30 void Set(
const KyFloat32* coords) { x = coords[0]; y = coords[1]; }
32 void Clear() { x = 0.0f; y = 0.0f; }
39 bool operator==(
const Vec2f& v)
const {
return x == v.x && y == v.y; }
40 bool operator!=(
const Vec2f& v)
const {
return x != v.x || y != v.y; }
43 bool operator<(
const Vec2f& v)
const {
return (x != v.x) ? x < v.x : y < v.y; };
44 bool operator>(
const Vec2f& v)
const {
return (x != v.x) ? x < v.x : y <= v.y; };
45 bool operator<=(
const Vec2f& v)
const {
return (x != v.x) ? x > v.x : y > v.y; };
46 bool operator>=(
const Vec2f& v)
const {
return (x != v.x) ? x < v.x : y >= v.y; };
50 Vec2f& operator+=(
const Vec2f& v) { x += v.x; y += v.y;
return *
this; }
51 Vec2f& operator-=(
const Vec2f& v) { x -= v.x; y -= v.y;
return *
this; }
55 Vec2f operator+(
const Vec2f& v)
const {
return Vec2f(x + v.x, y + v.y); }
56 Vec2f operator-(
const Vec2f& v)
const {
return Vec2f(x - v.x, y - v.y); }
57 Vec2f operator-()
const {
return Vec2f(-x, -y); }
64 KyFloat32 GetSquareLength()
const {
return x * x + y * y; }
65 KyFloat32 GetLength()
const {
return Sqrtf(x * x + y * y); }
68 Vec2f GetNormalized()
const;
72 KyFloat32 SqLength()
const {
return x * x + y * y; }
73 KyFloat32 Length()
const {
return Sqrtf(x * x + y * y); }
74 Vec2f Dir()
const {
return GetNormalized(); }
81 void RotateCCW(
KyFloat32 cosAngle,
KyFloat32 sinAngle) { Set(cosAngle * x - sinAngle * y, sinAngle * x + cosAngle * y); }
82 Vec2f GetRotatedCCW(
KyFloat32 cosAngle,
KyFloat32 sinAngle)
const {
return Vec2f(cosAngle * x - sinAngle * y, sinAngle * x + cosAngle * y); }
92 bool IsZero()
const {
return x == 0.0f && y == 0.0f; }
108 SwapEndianness(e,
self.x);
109 SwapEndianness(e,
self.y);
112 template <
class OSTREAM>
113 inline OSTREAM& operator<<(OSTREAM& os,
const Vec2f& v)
115 return os <<
"{" << v.x <<
"," << v.y <<
"}";
121 inline KyFloat32 DotProduct(
const Vec2f& v1,
const Vec2f& v2) {
return v1.x * v2.x + v1.y * v2.y; }
122 inline KyFloat32 CrossProduct(
const Vec2f& v1,
const Vec2f& v2) {
return v1.x * v2.y - v1.y * v2.x; }
125 inline Vec2f Seg(
const Vec2f& A,
const Vec2f& B) {
return B - A; }
134 return dx * dx + dy * dy;
152 inline bool IsEpsilonZero(
const Vec2f& v) {
return IsEpsilonZero(v.x) && IsEpsilonZero(v.y); }
153 inline bool IsEpsilonEqual(
const Vec2f& v1,
const Vec2f& v2) {
return IsEpsilonEqual(v1.x, v2.x) && IsEpsilonEqual(v1.y, v2.y); }
154 inline bool IsEpsilonDifferent(
const Vec2f& A,
const Vec2f& B) {
return !IsEpsilonEqual(A, B); }
170 const KyFloat32 sqlenProd = sqlenV1 * sqlenV2;
172 if (sqlenProd != 0.0f)
174 const KyFloat32 lenProd = (sqlenProd == 1.0f) ? 1.0f : Sqrtf(sqlenProd);
177 const KyFloat32 angle = Acosf(dp / lenProd);
179 const KyFloat32 cp = CrossProduct(v1, v2);
180 return cp >= 0.0f ? angle :
KY_2_PI - angle;
234 if (fabsf(cp) > 0.01f)
235 return (dir2 - dir1).PerpCW().GetNormalized();
254 const KyFloat32 ra = CrossProduct(dir_ref, dir_a);
255 const KyFloat32 rb = CrossProduct(dir_ref, dir_b);
256 const KyFloat32 ab = CrossProduct(dir_a, dir_b);
264 if (DotProduct(dir_ref, dir_b) > 0.0f)
267 return DotProduct(dir_ref, dir_a) > 0.0f;
300 inline KyFloat32 Dot(
const Vec2f& v1,
const Vec2f& v2) {
return DotProduct(v1, v2); }
302 inline KyFloat32 Cross(
const Vec2f& v1,
const Vec2f& v2) {
return CrossProduct(v1, v2); }
319 inline KyFloat32 Vec2f::GetNormalized(Vec2f& normalized)
const
325 const KyFloat32 inv_length = 1.0f / length;
326 normalized.Set(x * inv_length, y * inv_length);
331 normalized.Set(0.0f, 0.0f);
336 inline Vec2f Vec2f::GetNormalized()
const
340 return *
this / length;
KyFloat32 GetPositiveAngle(const Vec2f &v1, const Vec2f &v2, Winding::Enum winding)
Returns the positive angle in [0,2PI[ of the CounterClockwise or Clockwise rotation from v1 to v2...
Definition: vec2f.h:200
Vec2f()
Sets {0.0f, 0.0f}.
Definition: vec2f.h:25
bool operator<(const Vec2f &v) const
x is compared first, ex: {1, 5} < {2,="" 0}="" />
Definition: vec2f.h:43
KyFloat32 operator^(const Vec2f &v) const
CrossProduct(*this, v)
Definition: vec2f.h:60
Vec2f OffsetY(KyFloat32 dy) const
Returns {x, y + dy}.
Definition: vec2f.h:87
Vec2f(KyFloat32 *coords)
Sets {coords[0], coords[1]}.
Definition: vec2f.h:27
KyFloat32 Distance(const Vec2f &A, const Vec2f &B)
Returns the distance between A and B.
Definition: vec2f.h:138
Vec2f GetNormalized(const Vec2f &v)
Returns normalized v, returns {0.0f, 0.0f} if v is zero.
Definition: vec2f.h:141
static Vec2f UnitX()
Returns {1.0f, 0.0f}.
Definition: vec2f.h:97
bool Dir2dLessCW(const Vec2f &dir_ref, const Vec2f &dir_a, const Vec2f &dir_b)
Returns true when the CW angle (dir_ref, dir_a) is strictly less than CCW angle (dir_ref, dir_b).
Definition: vec2f.h:293
Vec2f OffsetX(KyFloat32 dx) const
Returns {x + dx, y}.
Definition: vec2f.h:86
KyFloat32 SquareDistance(const Vec2f &A, const Vec2f &B)
Returns the square of the distance between A and B.
Definition: vec2f.h:130
KyFloat32 GetPositiveAngleCCW(const Vec2f &v1, const Vec2f &v2)
Returns the positive angle in [0,2PI[ of the CounterClockwise rotation from v1 to v2...
Definition: vec2f.h:166
KyFloat32 GetSignedAngle(const Vec2f &v1, const Vec2f &v2, Winding::Enum winding)
Returns the signed (>0 for CCW <0 for="" cw)="" angle="" in="" ]-2pi,2pi[="" of="" the="" counterclockwise="" or="" clockwise="">0>
Definition: vec2f.h:211
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Vec2f Dir(const Vec2f &A, const Vec2f &B)
Returns the normalized direction AB, returns zero if A == B.
Definition: vec2f.h:150
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
Vec2f PerpCCW() const
Rotates by 90 degrees counter-clockwise.
Definition: vec2f.h:79
Vec2f Offset(KyFloat32 dx, KyFloat32 dy) const
Returns {x + dx, y + dy}.
Definition: vec2f.h:88
2d vector using KyFloat32.
Definition: vec2f.h:18
bool Dir2dLessCCW(const Vec2f &dir_ref, const Vec2f &dir_a, const Vec2f &dir_b)
Returns true when the CCW angle (dir_ref, dir_a) is strictly less than CCW angle (dir_ref, dir_b).
Definition: vec2f.h:252
KyFloat32 GetPositiveAngleCW(const Vec2f &v1, const Vec2f &v2)
Returns the positive angle in [0,2PI[ of the Clockwise rotation from v1 to v2.
Definition: vec2f.h:194
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Vec2f operator*(KyFloat32 s, const Vec2f &v)
scalar * vec operator
Definition: vec2f.h:120
KyFloat32 operator*(const Vec2f &v) const
DotProduct(*this, v)
Definition: vec2f.h:59
static Vec2f Zero()
Returns {0.0f, 0.0f}.
Definition: vec2f.h:93
std::int32_t KyInt32
int32_t
Definition: types.h:24
Vec2f BisectorCCW(const Vec2f &dir1, const Vec2f &dir2)
Definition: vec2f.h:231
Vec2f PerpCW() const
Rotates by 90 degrees clockwise.
Definition: vec2f.h:78
static const KyFloat32 KY_2_PI
Stores the value of 2*pi.
Definition: fastmath.h:143
KyFloat32 CrossProduct_z(const Vec2f &v1, const Vec2f &v2)
alias for CrossProduct, useful in some template functions
Definition: vec2f.h:123
static Vec2f UnitY()
Returns {0.0f, 1.0f}.
Definition: vec2f.h:98
void Rotate(Vec2f &v, KyFloat32 cosAngle, KyFloat32 sinAngle)
Rotate v by the provided cosAngle, sinAngle. Positive angles rotate CCW.
Definition: vec2f.h:222
void Clear()
Sets {0.0f, 0.0f}.
Definition: vec2f.h:32
float KyFloat32
float
Definition: types.h:32
void Set(const KyFloat32 *coords)
Sets {coords[0], coords[1]}.
Definition: vec2f.h:30