gwnavruntime/math/vec2ll.h Source File

vec2ll.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
12 #include <math.h>
13 
14 namespace Kaim
15 {
16 
18 class Vec2LL
19 {
20  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
21 
22 public:
23  // ------------------------------ Functions -----------------------------
24 
25  Vec2LL() : x(0), y(0) {}
26  Vec2LL(KyInt64 _x, KyInt64 _y) : x(_x), y(_y) {}
27  explicit Vec2LL(KyInt64* coords) { Set(coords); }
28 
29  void Set(KyInt64 _x, KyInt64 _y) { x = _x; y = _y; }
30  void Set(KyInt64* coords) { x = coords[0]; y = coords[1]; }
31 
32  void Clear() { x = 0; y = 0; }
33 
34  // ------------------------------ Operators -----------------------------
35 
36  KyInt64 operator[](KyInt64 idx) const { return (&x)[idx]; }
37  KyInt64& operator[](KyInt64 idx) { return (&x)[idx]; }
38 
39  bool operator==(const Vec2LL& v) const { return x == v.x && y == v.y; }
40  bool operator!=(const Vec2LL& v) const { return !operator==(v); }
41 
42  bool operator<(const Vec2LL& v) const { return (x != v.x) ? x < v.x : y < v.y; }
43  bool operator<=(const Vec2LL& v) const { return (x != v.x) ? x < v.x : y <= v.y; }
44  bool operator>(const Vec2LL& v) const { return (x != v.x) ? x > v.x : y > v.y; }
45  bool operator>=(const Vec2LL& v) const { return (x != v.x) ? x < v.x : y >= v.y; }
46 
47  Vec2LL& operator*=(KyInt64 s) { x *= s; y *= s; return *this; }
48  Vec2LL& operator/=(KyInt64 d) { x /= d; y /= d; return *this; }
49  Vec2LL& operator+=(const Vec2LL& v) { x += v.x; y += v.y; return *this; }
50  Vec2LL& operator-=(const Vec2LL& v) { x -= v.x; y -= v.y; return *this; }
51 
52  Vec2LL operator*(KyInt64 s) const { return Vec2LL(x * s , y * s ); }
53  Vec2LL operator/(KyInt64 d) const { return Vec2LL(x / d , y / d ); }
54  Vec2LL operator+(const Vec2LL& v) const { return Vec2LL(x + v.x, y + v.y); }
55  Vec2LL operator-(const Vec2LL& v) const { return Vec2LL(x - v.x, y - v.y); }
56  Vec2LL operator-() const { return Vec2LL(-x , -y ); }
57 
58  // ------------------------------ SquareLength -----------------------------
59 
60  KyInt64 GetSquareLength() const { return x * x + y * y; }
61  KyInt64 SqLength() const { return x * x + y * y; }
62 
63  // ------------------------------ Rotation -----------------------------
64 
65  Vec2LL PerpCCW() const { return Vec2LL(y, -x); }
66  Vec2LL PerpCW() const { return Vec2LL(-y, x); }
67 
68  // ------------------------------ Zero, Unit -----------------------------
69 
70  static Vec2LL Zero() { return Vec2LL(0, 0); }
71  static Vec2LL UnitX() { return Vec2LL(1, 0); }
72  static Vec2LL UnitY() { return Vec2LL(0, 1); }
73 
74  // ------------------------------ Data -----------------------------
75 
76  KyInt64 x;
77  KyInt64 y;
78 };
79 
80 inline KyInt64 DotProduct(const Vec2LL& v1, const Vec2LL& v2) { return v1.x * v2.x + v1.y * v2.y; }
81 inline KyInt64 CrossProduct(const Vec2LL& v1, const Vec2LL& v2) { return v1.x * v2.y - v1.y * v2.x; }
82 
83 template <class OSTREAM>
84 inline OSTREAM& operator<<(OSTREAM& os, const Vec2LL& v)
85 {
86  os << "{" << v.x << "," << v.y << "}";
87  return os;
88 }
89 
90 }
91 
92 
93 
94 
Vec2LL(KyInt64 *coords)
Constructs x=coords[0], y=coords[1].
Definition: vec2ll.h:27
Vec2LL(KyInt64 _x, KyInt64 _y)
Constructs x=_x, y=_y.
Definition: vec2ll.h:26
Vec2LL()
Constructs x=0.0f, y=0.0f.
Definition: vec2ll.h:25
2d vector using KyInt64
Definition: vec2ll.h:18
void Clear()
Sets x=0 and y=0.
Definition: vec2ll.h:32
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
std::int64_t KyInt64
int64_t
Definition: types.h:25
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
bool operator<(const Vec2LL &v) const
x is compared first. ex: {1, 5} < {2,="" 0}.="" />
Definition: vec2ll.h:42