gwnavruntime/math/vec2ll.h Source File

vec2ll.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef Navigation_Vec2L_H
10 #define Navigation_Vec2L_H
11 
12 
16 #include <math.h>
17 
18 
19 namespace Kaim
20 {
21 
22 
26 class Vec2LL
27 {
28  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
29 
30 public:
31  // ---------------------------------- Creation & Initialization ----------------------------------
32 
34  Vec2LL() : x(0), y(0) {}
35 
39  Vec2LL(KyInt64 _x, KyInt64 _y) : x(_x), y(_y) {}
40 
44  explicit Vec2LL(KyInt64* coords) { Set(coords); }
45 
49  KY_INLINE void Set(KyInt64 _x, KyInt64 _y) { x = _x; y = _y; }
50 
54  KY_INLINE void Set(KyInt64* coords) { x = coords[0]; y = coords[1]; }
55 
56 
57  // -------------------------- Operators --------------------------------
58 
61  KY_INLINE KyInt64 operator[](KyInt64 idx) const { return (&x)[idx]; }
62 
65  KY_INLINE KyInt64& operator[](KyInt64 idx) { return (&x)[idx]; }
66 
68  KY_INLINE bool operator==(const Vec2LL& v) const { return x == v.x && y == v.y; }
69 
71  KY_INLINE bool operator!=(const Vec2LL& v) const { return !operator==(v);/*x != v.x || y != v.y;*/ }
72 
74  KY_INLINE bool operator<(const Vec2LL& v) const
75  {
76  if (x < v.x) return true;
77  if (x > v.x) return false;
78  return (y < v.y);
79  }
80 
82  KY_INLINE Vec2LL& operator*=(KyInt64 s) { x *= s; y *= s; return *this; }
83 
85  KY_INLINE Vec2LL& operator/=(KyInt64 d) { x /= d; y /= d; return *this; }
86 
88  KY_INLINE Vec2LL& operator+=(KyInt64 t) { x += t; y += t; return *this; }
89 
91  KY_INLINE Vec2LL& operator-=(KyInt64 t) { x -= t; y -= t; return *this; }
92 
95  KY_INLINE Vec2LL& operator+=(const Vec2LL& v) { x += v.x; y += v.y; return *this; }
96 
99  KY_INLINE Vec2LL& operator-=(const Vec2LL& v) { x -= v.x; y -= v.y; return *this; }
100 
102  KY_INLINE Vec2LL operator*(KyInt64 s) const { return Vec2LL(x * s , y * s ); }
103 
105  KY_INLINE Vec2LL operator/(KyInt64 d) const { return Vec2LL(x / d , y / d ); }
106 
109  KY_INLINE Vec2LL operator+(const Vec2LL& v) const { return Vec2LL(x + v.x, y + v.y); }
110 
113  KY_INLINE Vec2LL operator-(const Vec2LL& v) const { return Vec2LL(x - v.x, y - v.y); }
114 
116  KY_INLINE Vec2LL operator-() const { return Vec2LL(-x , -y ); }
117 
119  KY_INLINE KyInt64 operator*(const Vec2LL& v) const { return x * v.x + y * v.y; } // DOT PROD
120 
122  KY_INLINE KyInt64 operator^(const Vec2LL& v) const { return CrossProd(v); } // CROSS PROD 2D aka PERP PROD
124 
125  // -------------------------- Main interface --------------------------------
128  KY_INLINE KyInt64 CrossProd(const Vec2LL& v) const { return x * v.y - y * v.x; } // CROSS PROD 2D aka PERP PROD
131  KY_INLINE KyInt64 GetSquareLength() const { return x * x + y * y; }
134  KY_INLINE Vec2LL PerpCCW() const{return Vec2LL(y, -x);}
135 
137  KY_INLINE Vec2LL PerpCW() const{return Vec2LL(-y, x);}
138 
139  KY_INLINE void SetAdditionResult(const Vec2LL& v1, const Vec2LL& v2) { x = v1.x + v2.x; y = v1.y + v2.y; }
140 
141 
142  // -------------------------- Static methods --------------------------------
143 
145  static KY_INLINE Vec2LL UnitX() { return Vec2LL(1, 0); }
146 
148  static KY_INLINE Vec2LL UnitY() { return Vec2LL(0, 1); }
149 
150 
151  // ---------------------------------- Public Data Members ----------------------------------
152 
153  KyInt64 x;
154  KyInt64 y;
155 };
156 
157 inline Vec2LL operator * (KyInt64 lhs, const Vec2LL& rhs) { return rhs * lhs; }
158 
160 KY_INLINE KyInt64 DotProduct(const Vec2LL& v1, const Vec2LL& v2) { return v1 * v2; }
161 
163 KY_INLINE KyInt64 CrossProduct(const Vec2LL& v1, const Vec2LL& v2) { return v1.CrossProd(v2); }
164 
165 
166 template <class OSTREAM>
167 inline OSTREAM& operator<<(OSTREAM& os, const Kaim::Vec2LL& v)
168 {
169  os << "{" << v.x << ";" << v.y << "}";
170  return os;
171 }
172 
173 } // namespace Kaim
174 
177 #endif
178 
KyInt64 x
The size of the vector along the X axis.
Definition: vec2ll.h:175
Vec2LL operator+(const Vec2LL &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: vec2ll.h:119
static Vec2LL UnitY()
Returns the normalized orientation of the Y axis.
Definition: vec2ll.h:166
Vec2LL PerpCW() const
Rotates this vector 90 degrees clockwise (negating the X coordinate).
Definition: vec2ll.h:151
KyInt64 CrossProd(const Vec2LL &v) const
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2ll.h:142
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
Vec2LL & operator/=(KyInt64 d)
Divides both the X and Y coordinates of this vector by the specified value.
Definition: vec2ll.h:95
bool operator==(const Vec2LL &v) const
Returns true if this object contains the same coordinates as v.
Definition: vec2ll.h:78
Vec2LL()
Creates a vector with coordinates (0,0).
Definition: vec2ll.h:40
This class defines a two-dimensional vector whose coordinates are stored using 64-bit integers...
Definition: vec2ll.h:27
static Vec2LL UnitX()
Returns the normalized orientation of the X axis.
Definition: vec2ll.h:163
Vec2LL PerpCCW() const
Rotates this vector 90 degrees counter-clockwise (negating the Y coordinate).
Definition: vec2ll.h:148
KyInt64 y
The size of the vector along the Y axis.
Definition: vec2ll.h:176
Vec2LL operator/(KyInt64 d) const
Divides both the X and Y coordinates of the vector by the specified value.
Definition: vec2ll.h:115
KyInt64 operator^(const Vec2LL &v) const
Returns the magnitude on the Z axis of the cross product between this vector and v.
Definition: vec2ll.h:132
bool operator!=(const Vec2LL &v) const
Returns true if this object contains at least one different coordinate from v.
Definition: vec2ll.h:81
void Set(KyInt64 _x, KyInt64 _y)
Sets the coordinates of the vector to match the specified values.
Definition: vec2ll.h:55
Definition: gamekitcrowddispersion.h:20
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
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
KyInt64 operator[](KyInt64 idx) const
Retrieves the size of the vector around one of its axes.
Definition: vec2ll.h:71
Vec2LL & operator*=(KyInt64 s)
Multiplies both the X and Y coordinates of this vector by the specified value.
Definition: vec2ll.h:92
Vec2LL operator*(KyInt64 s) const
Multiplies both the X and Y coordinates of the vector by the specified value.
Definition: vec2ll.h:112
Vec2LL operator-() const
Negates the X and Y coordinates of this vector, effectively flipping it around the origin...
Definition: vec2ll.h:126
KyInt64 GetSquareLength() const
Returns the square of the magnitude of the vector.
Definition: vec2ll.h:145
bool operator<(const Vec2LL &v) const
Returns true if the size of this vector along both the X and Y axes is less than that of v...
Definition: vec2ll.h:84
Vec2LL & operator-=(KyInt64 t)
Subtractst from both the X and Y coordinates of this vector.
Definition: vec2ll.h:101
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
Vec2LL & operator+=(KyInt64 t)
Addst to both the X and Y coordinates of this vector.
Definition: vec2ll.h:98