9 #ifndef Navigation_Vec2i_H
10 #define Navigation_Vec2i_H
53 KY_INLINE
void Set(
KyInt32* coords) {
x = coords[0];
y = coords[1]; }
67 KY_INLINE
bool operator==(
const Vec2i& v)
const {
return ((
x ^ v.x) | (
y ^ v.y)) == 0; }
189 return returnCellPos;
195 static const Vec2i s_cardinalDirToNeighbor[4] =
203 neighbor.
x =
x + s_cardinalDirToNeighbor[dir].
x;
204 neighbor.
y =
y + s_cardinalDirToNeighbor[dir].
y;
263 SwapEndianness(e,
self.x);
264 SwapEndianness(e,
self.y);
269 const KyInt32 dx = v2.x - v1.x;
270 const KyInt32 dy = v2.y - v1.y;
271 return dx * dx + dy * dy;
281 if (
y < A.
y &&
y < B.
y &&
y < C.
y)
289 if (
x < A.
x &&
x < B.
x &&
x < C.
x)
313 KY_INLINE
KyInt32 DotProduct(
const Vec2i& v1,
const Vec2i& v2) {
return v1 * v2; }
316 KY_INLINE
KyInt32 CrossProduct(
const Vec2i& v1,
const Vec2i& v2) {
return v1.CrossProd(v2); }
319 template <
typename T> KY_INLINE T CrossProductT(
const Vec2i& v1,
const Vec2i& v2) {
return (T)(v1.x) * (T)(v2.y) - (T)(v1.y) * (T)(v2.x); }
320 template <
typename T> KY_INLINE T DotProductT(
const Vec2i& v1,
const Vec2i& v2) {
return (T)(v1.x) * (T)(v2.x) + (T)(v1.y) * (T)(v2.y); }
322 template <
class OSTREAM>
323 inline OSTREAM& operator<<(OSTREAM& os,
const Kaim::Vec2i& v)
325 os <<
"{" << v.
x <<
";" << v.
y <<
"}";
bool operator<(const Vec2i &v) const
order by x first: (1,9)<(2,8).>(2,8).>
Definition: vec2i.h:83
Vec2i operator*(KyInt32 s) const
Multiplies both the X and Y coordinates of the vector by the specified value.
Definition: vec2i.h:115
Vec2i & operator/=(KyInt32 d)
Divides both the X and Y coordinates of this vector by the specified value.
Definition: vec2i.h:98
Vec2i PerpCW() const
Rotates this vector 90 degrees clockwise (negating the X coordinate).
Definition: vec2i.h:158
Vec2i PerpCCW() const
Rotates this vector 90 degrees counter-clockwise (negating the Y coordinate).
Definition: vec2i.h:155
KyFloat32 CrossProduct(const Vec2f &v1, const Vec2f &v2)
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2f.h:190
KyInt32 operator^(const Vec2i &v) const
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2i.h:135
Vec2i NeighborEast() const
Returns a vector that identifies the next grid cell to the East: i.e. in the positive direction of th...
Definition: vec2i.h:179
bool IsInsideNotColinearTriangle(const Vec2i &A, const Vec2i &B, const Vec2i &C) const
Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters...
Definition: vec2i.h:331
Vec2i & operator-=(KyInt32 t)
Subtractst from both the X and Y coordinates of this vector.
Definition: vec2i.h:104
Vec2i NeighborNorthWest() const
Returns a vector that identifies the next grid cell to the North-West: i.e.
Definition: vec2i.h:232
Vec2i NeighborSouthWest() const
Returns a vector that identifies the next grid cell to the South-West: i.e.
Definition: vec2i.h:240
bool IsStrictlyInsideTriangle(const Vec2i &A, const Vec2i &B, const Vec2i &C) const
Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters...
Definition: vec2i.h:337
bool operator!=(const Vec2i &v) const
Returns true if this object contains at least one different coordinate from v.
Definition: vec2i.h:80
Vec2i NeighborSouth() const
Returns a vector that identifies the next grid cell to the South: i.e. in the negative direction of t...
Definition: vec2i.h:197
Vec2i NeighborWest() const
Returns a vector that identifies the next grid cell to the West: i.e. in the negative direction of th...
Definition: vec2i.h:185
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
void Set(KyInt32 _x, KyInt32 _y)
Sets the coordinates of the vector to match the specified values.
Definition: vec2i.h:54
bool operator==(const Vec2i &v) const
Returns true if this object contains the same coordinates as v.
Definition: vec2i.h:77
Vec2i Neighbor(CardinalDir dir) const
Returns a vector that identifies the next grid cell in the direction of the specified CardinalDir...
Definition: vec2i.h:203
KyInt32 x
The size of the vector along the X axis.
Definition: vec2i.h:283
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:23
static Vec2i UnitY()
Returns the normalized orientation of the Y axis.
Definition: vec2i.h:274
bool operator>=(const Vec2i &v) const
order by x first: (2,8)>=(1,9).
Definition: vec2i.h:92
KyInt32 CrossProd(const Vec2i &v) const
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2i.h:144
bool IsStrictlyOnLeftSide(const Vec2i &A, const Vec2i &B) const
Returns true if this vector is on the left side when moving from A to B, but not if this vector is on...
Definition: vec2i.h:166
Vec2i operator/(KyInt32 d) const
Divides both the X and Y coordinates of the vector by the specified value.
Definition: vec2i.h:118
KyInt32 y
The size of the vector along the Y axis.
Definition: vec2i.h:284
KyInt32 operator[](KyInt32 idx) const
Retrieves the size of the vector around one of its axes.
Definition: vec2i.h:70
KyFloat32 SquareDistance(const Vec2f &v1, const Vec2f &v2)
Returns the square of the distance between v1 and v2.
Definition: vec2f.h:194
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
bool IsOnLeftSide(const Vec2i &A, const Vec2i &B) const
Returns true if this vector is on the left side when moving from A to B, or if this vector is on the ...
Definition: vec2i.h:162
static Vec2i UnitX()
Returns the normalized orientation of the X axis.
Definition: vec2i.h:271
bool IsInsideTriangle(const Vec2i &A, const Vec2i &B, const Vec2i &C) const
Returns true if this vector is inside the clockwise triangle formed by theA,B and C parameters...
Definition: vec2i.h:304
This class defines a two-dimensional vector whose coordinates are stored using 32-bit integers...
Definition: vec2i.h:26
Definition: gamekitcrowddispersion.h:20
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
Vec2i & operator+=(KyInt32 t)
Addst to both the X and Y coordinates of this vector.
Definition: vec2i.h:101
Vec2f operator*(KyFloat32 s, const Vec2f &v)
Multiplies the X and Y coordinates of v by s.
Definition: vec2f.h:184
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
KyInt32 GetSquareLength() const
Returns the square of the magnitude of the vector.
Definition: vec2i.h:169
Vec2i operator+(const Vec2i &v) const
Adds the X coordinate of v to the X coordinate of this vector, and adds the Y coordinate of v to the ...
Definition: vec2i.h:122
Vec2i operator-() const
Negates the X and Y coordinates of this vector, effectively flipping it around the origin...
Definition: vec2i.h:129
bool operator>(const Vec2i &v) const
order by x first: (2,8)>(1,9).
Definition: vec2i.h:89
Vec2i & operator*=(KyInt32 s)
Multiplies both the X and Y coordinates of this vector by the specified value.
Definition: vec2i.h:95
Vec2i()
Creates a vector with coordinates (0,0).
Definition: vec2i.h:39
KyInt32 Orient2d(const Vec2i &A, const Vec2i &B) const
Indicates whether or not the polyline formed by (A to B to this vector ) outlines a triangle in count...
Definition: vec2i.h:152
Vec2i NeighborSouthEast() const
Returns a vector that identifies the next grid cell to the South-East: i.e.
Definition: vec2i.h:236
Vec2i NeighborNorthEast() const
Returns a vector that identifies the next grid cell to the North-East: i.e.
Definition: vec2i.h:228
bool operator<=(const Vec2i &v) const
order by x first: (1,9)<=(2,8).>=(2,8).>
Definition: vec2i.h:86
Vec2i NeighborNorth() const
Returns a vector that identifies the next grid cell to the North: i.e. in the positive direction of t...
Definition: vec2i.h:191