CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUVec2.h
1 //
2 // CUVec2.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a 2d vector. It has support for basic
6 // arithmetic, as well as some common line intersection properties.
7 //
8 // Because math objects are intended to be on the stack, we do not provide
9 // any shared pointer support in this class.
10 //
11 // This module is based on an original file from GamePlay3D: http://gameplay3d.org.
12 // It has been modified to support the CUGL framework.
13 //
14 // CUGL MIT License:
15 // This software is provided 'as-is', without any express or implied
16 // warranty. In no event will the authors be held liable for any damages
17 // arising from the use of this software.
18 //
19 // Permission is granted to anyone to use this software for any purpose,
20 // including commercial applications, and to alter it and redistribute it
21 // freely, subject to the following restrictions:
22 //
23 // 1. The origin of this software must not be misrepresented; you must not
24 // claim that you wrote the original software. If you use this software
25 // in a product, an acknowledgment in the product documentation would be
26 // appreciated but is not required.
27 //
28 // 2. Altered source versions must be plainly marked as such, and must not
29 // be misrepresented as being the original software.
30 //
31 // 3. This notice may not be removed or altered from any source distribution.
32 //
33 // Author: Walker White
34 // Version: 5/30/16
35 
36 #ifndef __CU_VEC2_H__
37 #define __CU_VEC2_H__
38 
39 #include <math.h>
40 #include <string>
41 #include <functional>
42 #include "CUMathBase.h"
43 
44 namespace cugl {
45 
46 // Forward references for conversions
47 class Size;
48 class Vec3;
49 class Vec4;
50 
61 class Vec2 {
62 
63 #pragma mark Values
64 public:
66  float x;
68  float y;
69 
71  static const Vec2 ZERO;
73  static const Vec2 ONE;
75  static const Vec2 UNIT_X;
77  static const Vec2 UNIT_Y;
78 
80  static const Vec2 ANCHOR_CENTER;
82  static const Vec2 ANCHOR_BOTTOM_LEFT;
84  static const Vec2 ANCHOR_TOP_LEFT;
86  static const Vec2 ANCHOR_BOTTOM_RIGHT;
88  static const Vec2 ANCHOR_TOP_RIGHT;
90  static const Vec2 ANCHOR_MIDDLE_RIGHT;
92  static const Vec2 ANCHOR_MIDDLE_LEFT;
94  static const Vec2 ANCHOR_TOP_CENTER;
96  static const Vec2 ANCHOR_BOTTOM_CENTER;
97 
98 #pragma mark -
99 #pragma mark Constructors
100 public:
104  Vec2() : x(0), y(0) { }
105 
112  Vec2(float x, float y) { this->x = x; this->y = y; }
113 
119  Vec2(const float* array) { x = array[0]; y = array[1]; }
120 
127  Vec2(const Vec2& p1, const Vec2& p2) {
128  x = p2.x-p1.x; y = p2.y-p1.y;
129  }
130 
131 
132 #pragma mark -
133 #pragma mark Setters
134 
141  Vec2& operator=(const float* array) {
142  return set(array);
143  }
144 
153  Vec2& set(float x, float y) {
154  this->x = x; this->y = y;
155  return *this;
156  }
157 
165  Vec2& set(const float* array) {
166  x = array[0]; y = array[1];
167  return *this;
168  }
169 
177  Vec2& set(const Vec2& v) {
178  x = v.x; y = v.y;
179  return *this;
180  }
181 
190  Vec2& set(const Vec2& p1, const Vec2& p2) {
191  x = p2.x-p1.x; y = p2.y-p1.y;
192  return *this;
193  }
194 
201  x = y = 0;
202  return *this;
203  }
204 
205 
206 #pragma mark -
207 #pragma mark Static Arithmetic
208 
215  static Vec2 forAngle(const float a) {
216  return Vec2(cosf(a), sinf(a));
217  }
218 
229  static Vec2* clamp(const Vec2& v, const Vec2& min, const Vec2& max, Vec2* dst);
230 
239  static float angle(const Vec2& v1, const Vec2& v2);
240 
250  static Vec2* add(const Vec2& v1, const Vec2& v2, Vec2* dst);
251 
262  static Vec2* subtract(const Vec2& v1, const Vec2& v2, Vec2* dst);
263 
275  static Vec2* scale(const Vec2& v, float s, Vec2* dst);
276 
288  static Vec2* scale(const Vec2& v1, const Vec2& v2, Vec2* dst);
289 
301  static Vec2* divide(const Vec2& v, float s, Vec2* dst);
302 
314  static Vec2* divide(const Vec2& v1, const Vec2& v2, Vec2* dst);
315 
328  static Vec2* reciprocate(const Vec2& v, Vec2* dst);
329 
338  static Vec2* negate(const Vec2& v, Vec2* dst);
339 
340 #pragma mark -
341 #pragma mark Arithmetic
342 
350  Vec2& clamp(const Vec2& min, const Vec2& max) {
351  x = clampf(x, min.x, max.x);
352  y = clampf(y, min.y, max.y);
353  return *this;
354  }
355 
366  Vec2 getClamp(const Vec2& min, const Vec2& max) const {
367  return Vec2(clampf(x,min.x,max.x), clampf(y, min.y, max.y));
368  }
369 
377  Vec2& add(const Vec2& v) {
378  x += v.x; y += v.y;
379  return *this;
380  }
381 
390  Vec2& add(float x, float y) {
391  this->x += x; this->y += y;
392  return *this;
393  }
394 
402  Vec2& subtract(const Vec2& v) {
403  x -= v.x; y -= v.y;
404  return *this;
405  }
406 
415  Vec2& subtract(float x, float y) {
416  this->x -= x; this->y -= y;
417  return *this;
418  }
419 
427  Vec2& scale(float s) {
428  x *= s; y *= s;
429  return *this;
430  }
431 
440  Vec2& scale(float sx, float sy) {
441  x *= sx; y *= sy;
442  return *this;
443  }
444 
452  Vec2& scale(const Vec2& v) {
453  x *= v.x; y *= v.y;
454  return *this;
455  }
456 
464  Vec2& divide(float s);
465 
474  Vec2& divide(float sx, float sy);
475 
485  Vec2& divide(const Vec2& v);
486 
493  x = -x; y = -y;
494  return *this;
495  }
496 
507  x = 1.0f/x; y = 1.0f/y;
508  return *this;
509  }
510 
518  Vec2 getNegation() const {
519  Vec2 result(*this);
520  return result.negate();
521  }
522 
534  Vec2 getReciprocal() const {
535  Vec2 result(*this);
536  return result.reciprocate();
537  }
538 
549  Vec2& map(std::function<float(float)> func) {
550  x = func(x); y = func(y);
551  return *this;
552  }
553 
564  Vec2 getMap(std::function<float(float)> func) const {
565  return Vec2(func(x), func(y));
566  }
567 
568 
569 #pragma mark -
570 #pragma mark Operators
571 
578  Vec2& operator+=(const Vec2& v) {
579  return add(v);
580  }
581 
589  Vec2& operator-=(const Vec2& v) {
590  return subtract(v);
591  }
592 
600  Vec2& operator*=(float s) {
601  return scale(s);
602  }
603 
611  Vec2& operator*=(const Vec2& v) {
612  return scale(v);
613  }
614 
622  Vec2& operator/=(float s) {
623  return divide(s);
624  }
625 
635  Vec2& operator/=(const Vec2& v) {
636  return divide(v);
637  }
638 
648  const Vec2 operator+(const Vec2& v) const {
649  Vec2 result(*this);
650  return result.add(v);
651  }
652 
662  const Vec2 operator-(const Vec2& v) const {
663  Vec2 result(*this);
664  return result.subtract(v);
665  }
666 
674  const Vec2 operator-() const {
675  Vec2 result(*this);
676  return result.negate();
677  }
678 
688  const Vec2 operator*(float s) const {
689  Vec2 result(*this);
690  return result.scale(s);
691  }
692 
703  const Vec2 operator*(const Vec2& v) const {
704  Vec2 result(*this);
705  return result.scale(v);
706  }
707 
717  const Vec2 operator/(float s) const {
718  Vec2 result(*this);
719  return result.divide(s);
720  }
721 
732  const Vec2 operator/(const Vec2& v) const {
733  Vec2 result(*this);
734  return result.divide(v);
735  }
736 
737 
738 #pragma mark -
739 #pragma mark Comparisons
740 
751  bool operator<(const Vec2& v) const {
752  return (x == v.x ? y < v.y : x < v.x);
753  }
754 
766  bool operator<=(const Vec2& v) const {
767  return (x == v.x ? y <= v.y : x <= v.x);
768  }
769 
781  bool operator>(const Vec2& v) const {
782  return (x == v.x ? y > v.y : x > v.x);
783  }
784 
796  bool operator>=(const Vec2& v) const {
797  return (x == v.x ? y >= v.y : x >= v.x);
798  }
799 
810  bool operator==(const Vec2& v) const {
811  return x == v.x && y == v.y;
812  }
813 
824  bool operator!=(const Vec2& v) const {
825  return x != v.x || y != v.y;
826  }
827 
838  bool under(const Vec2& v) const {
839  return x <= v.x && y <= v.y;
840  }
841 
852  bool over(const Vec2& v) const {
853  return x >= v.x && y >= v.y;
854  }
855 
867  bool equals(const Vec2& v, float variance=CU_MATH_EPSILON) const {
868  return distanceSquared(v) <= variance*variance;
869  }
870 
871 
872 #pragma mark -
873 #pragma mark Linear Attributes
874 
881  float getAngle() const {
882  return atan2f(y, x);
883  }
884 
895  float getAngle(const Vec2& other) const;
896 
902  bool isZero() const {
903  return x == 0.0f && y == 0.0f;
904  }
905 
913  bool isNearZero(float variance=CU_MATH_EPSILON) const {
914  return lengthSquared() < variance*variance;
915  }
916 
922  bool isOne() const {
923  return x == 1.0f && y == 1.0f;
924  }
925 
931  bool isInvertible() const {
932  return x != 0.0f && y != 0.0f;
933  }
934 
942  bool isUnit(float variance=CU_MATH_EPSILON) const {
943  float dot = lengthSquared()-1;
944  return dot < variance && dot > -variance;
945  }
946 
956  float distance(const Vec2& v) const {
957  return sqrt(distanceSquared(v));
958  }
959 
974  float distanceSquared(const Vec2& v) const {
975  return (x-v.x)*(x-v.x)+(y-v.y)*(y-v.y);
976  }
977 
985  float length() const {
986  return sqrt(lengthSquared());
987  }
988 
1001  float lengthSquared() const {
1002  return x*x+y*y;
1003  }
1004 
1005 
1006 #pragma mark -
1007 #pragma mark Linear Algebra
1008 
1015  float dot(const Vec2& v) const { return (x * v.x + y * v.y); }
1016 
1027  float cross(const Vec2& other) const {
1028  return x*other.y - y*other.x;
1029  }
1030 
1041  Vec2& normalize();
1042 
1055  Vec2 result(*this);
1056  return result.normalize();
1057  }
1058 
1066  Vec2& rotate(float angle);
1067 
1076  Vec2& rotate(float angle, const Vec2& point);
1077 
1088  Vec2& rotate(const Vec2& other) {
1089  // The const is more of a guideline than a rule. Must bullet-proof.
1090  float tx = x; float ty = y;
1091  float ox = other.x; float oy = other.y;
1092  x = tx*ox - ty*oy; y = tx*oy + ty*ox;
1093  return *this;
1094  }
1095 
1106  Vec2& unrotate(const Vec2& other) {
1107  float tx = x; float ty = y;
1108  float ox = other.x; float oy = other.y;
1109  x = tx*ox + ty*oy; y = -tx*oy + ty*ox;
1110  return *this;
1111  }
1112 
1123  Vec2 getRotation(float angle);
1124 
1136  Vec2 getRotation(float angle, const Vec2& point);
1137 
1150  Vec2 getRotation(const Vec2& other) {
1151  return Vec2(x*other.x - y*other.y, x*other.y + y*other.x);
1152  }
1153 
1166  Vec2 getUnrotation(const Vec2& other) {
1167  return Vec2(x*other.x + y*other.y, y*other.x - x*other.y);
1168  }
1169 
1177  Vec2& perp() {
1178  float a = x; x = -y; y = a;
1179  return *this;
1180  }
1181 
1190  float a = x; x = y; y = -a;
1191  return *this;
1192  }
1193 
1203  Vec2 getPerp() const {
1204  return Vec2(-y, x);
1205  }
1206 
1216  Vec2 getRPerp() const {
1217  return Vec2(y, -x);
1218  }
1219 
1229  Vec2 getMidpoint(const Vec2& other) const {
1230  return Vec2((x + other.x) / 2.0f, (y + other.y) / 2.0f);
1231  }
1232 
1240  Vec2& project(const Vec2& other) {
1241  *this = getProjection(other);
1242  return *this;
1243  }
1244 
1254  Vec2 getProjection(const Vec2& other) const {
1255  return other * (dot(other)/other.dot(other));
1256  }
1257 
1258 
1271  Vec2& lerp(const Vec2& other, float alpha) {
1272  *this *= (1.f - alpha);
1273  return *this += other * alpha;
1274  }
1275 
1288  Vec2 getLerp(const Vec2& other, float alpha) {
1289  return *this * (1.f - alpha) + other * alpha;
1290  }
1291 
1292 
1293 #pragma mark -
1294 #pragma mark Static Linear Algebra
1295 
1304  static float dot(const Vec2& v1, const Vec2& v2);
1305 
1317  static float cross(const Vec2& v1, const Vec2& v2);
1318 
1330  static Vec2* normalize(const Vec2& v, Vec2* dst);
1331 
1341  static Vec2* midpoint(const Vec2& v1, const Vec2& v2, Vec2* dst);
1342 
1352  static Vec2* project(const Vec2& v1, const Vec2& v2, Vec2* dst);
1353 
1368  static Vec2* lerp(const Vec2& v1, const Vec2& v2, float alpha, Vec2* dst);
1369 
1394  static bool doesLineIntersect(const Vec2& A, const Vec2& B,
1395  const Vec2& C, const Vec2& D,
1396  float *S = nullptr, float *T = nullptr);
1397 
1411  static bool doesLineOverlap(const Vec2& A, const Vec2& B,
1412  const Vec2& C, const Vec2& D);
1413 
1427  static bool isLineParallel(const Vec2& A, const Vec2& B,
1428  const Vec2& C, const Vec2& D);
1429 
1442  static bool doesSegmentIntersect(const Vec2& A, const Vec2& B, const Vec2& C, const Vec2& D);
1443 
1460  static bool doesSegmentOverlap(const Vec2& A, const Vec2& B,
1461  const Vec2& C, const Vec2& D,
1462  Vec2* S = nullptr, Vec2* E = nullptr);
1463 
1477  static Vec2 getIntersection(const Vec2& A, const Vec2& B, const Vec2& C, const Vec2& D);
1478 
1479 
1480 #pragma mark -
1481 #pragma mark Conversion Methods
1482 public:
1493  std::string toString(bool verbose = false) const;
1494 
1496  operator std::string() const { return toString(); }
1497 
1499  operator Size() const;
1500 
1508  explicit Vec2(const Size& size);
1509 
1519  Vec2& operator= (const Size& size);
1520 
1528  Vec2& operator+=(const Size& right);
1529 
1537  Vec2& operator-=(const Size& right);
1538 
1548  const Vec2 operator+(const Size& right) const {
1549  Vec2 result(*this);
1550  return result += right;
1551  }
1552 
1562  const Vec2 operator-(const Size& right) const {
1563  Vec2 result(*this);
1564  return result -= right;
1565  }
1566 
1572  operator Vec3() const;
1573 
1581  explicit Vec2(const Vec3& v);
1582 
1592  Vec2& operator= (const Vec3& size);
1593 
1600  operator Vec4() const;
1601 
1610  explicit Vec2(const Vec4& v);
1611 
1622  Vec2& operator= (const Vec4& size);
1623 };
1624 
1625 
1626 #pragma mark -
1627 #pragma mark Friend Operations
1628 
1637 inline const Vec2 operator*(float x, const Vec2& v) {
1638  Vec2 result(v);
1639  return result.scale(x);
1640 }
1641 
1643 typedef Vec2 Point2;
1644 
1645 }
1646 
1647 #endif /* __CU_VEC2_H__ */
cugl::Vec2::subtract
Vec2 & subtract(float x, float y)
Definition: CUVec2.h:415
cugl::Vec2::lengthSquared
float lengthSquared() const
Definition: CUVec2.h:1001
cugl::Vec2::getProjection
Vec2 getProjection(const Vec2 &other) const
Definition: CUVec2.h:1254
cugl::Vec2::ANCHOR_TOP_CENTER
static const Vec2 ANCHOR_TOP_CENTER
Definition: CUVec2.h:94
cugl::Vec2::isUnit
bool isUnit(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:942
cugl::Vec2::getRotation
Vec2 getRotation(float angle)
cugl::Vec4
Definition: CUVec4.h:64
cugl::Vec2::ANCHOR_MIDDLE_RIGHT
static const Vec2 ANCHOR_MIDDLE_RIGHT
Definition: CUVec2.h:90
cugl::Vec2::reciprocate
Vec2 & reciprocate()
Definition: CUVec2.h:506
cugl::Vec2::project
Vec2 & project(const Vec2 &other)
Definition: CUVec2.h:1240
cugl::Vec2::scale
Vec2 & scale(float s)
Definition: CUVec2.h:427
cugl::Vec2::Vec2
Vec2(const float *array)
Definition: CUVec2.h:119
cugl::Vec2::scale
Vec2 & scale(const Vec2 &v)
Definition: CUVec2.h:452
cugl::Vec2::operator==
bool operator==(const Vec2 &v) const
Definition: CUVec2.h:810
cugl::Vec2::operator*
const Vec2 operator*(float s) const
Definition: CUVec2.h:688
cugl::Vec2::Vec2
Vec2(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:127
cugl::Vec2::toString
std::string toString(bool verbose=false) const
cugl::Vec2::getRotation
Vec2 getRotation(const Vec2 &other)
Definition: CUVec2.h:1150
cugl::Vec2::UNIT_X
static const Vec2 UNIT_X
Definition: CUVec2.h:75
cugl::Vec2::ZERO
static const Vec2 ZERO
Definition: CUVec2.h:71
cugl::Vec2::add
Vec2 & add(float x, float y)
Definition: CUVec2.h:390
cugl::Vec2::under
bool under(const Vec2 &v) const
Definition: CUVec2.h:838
cugl::Vec2::operator>=
bool operator>=(const Vec2 &v) const
Definition: CUVec2.h:796
cugl::Vec2::scale
Vec2 & scale(float sx, float sy)
Definition: CUVec2.h:440
cugl::Vec2::operator<=
bool operator<=(const Vec2 &v) const
Definition: CUVec2.h:766
cugl::Vec2::getIntersection
static Vec2 getIntersection(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
cugl::Vec2::ONE
static const Vec2 ONE
Definition: CUVec2.h:73
cugl::Vec2::setZero
Vec2 & setZero()
Definition: CUVec2.h:200
cugl::Vec2::midpoint
static Vec2 * midpoint(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
cugl::Vec2::ANCHOR_CENTER
static const Vec2 ANCHOR_CENTER
Definition: CUVec2.h:80
cugl::Size
Definition: CUSize.h:57
cugl::Vec2::doesLineIntersect
static bool doesLineIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, float *S=nullptr, float *T=nullptr)
cugl::Vec2::operator*
const Vec2 operator*(const Vec2 &v) const
Definition: CUVec2.h:703
cugl::Vec2::Vec2
Vec2()
Definition: CUVec2.h:104
cugl::Vec2::operator/=
Vec2 & operator/=(const Vec2 &v)
Definition: CUVec2.h:635
cugl::Vec2::operator+=
Vec2 & operator+=(const Vec2 &v)
Definition: CUVec2.h:578
cugl::Vec2::reciprocate
static Vec2 * reciprocate(const Vec2 &v, Vec2 *dst)
cugl::Vec2::x
float x
Definition: CUVec2.h:66
cugl::Vec2::operator-
const Vec2 operator-(const Vec2 &v) const
Definition: CUVec2.h:662
cugl::Vec2::lerp
Vec2 & lerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1271
cugl::Vec2::operator/
const Vec2 operator/(const Vec2 &v) const
Definition: CUVec2.h:732
cugl::Vec2::getClamp
Vec2 getClamp(const Vec2 &min, const Vec2 &max) const
Definition: CUVec2.h:366
cugl::Vec2::ANCHOR_BOTTOM_LEFT
static const Vec2 ANCHOR_BOTTOM_LEFT
Definition: CUVec2.h:82
cugl::Vec2::distanceSquared
float distanceSquared(const Vec2 &v) const
Definition: CUVec2.h:974
cugl::Vec2::negate
static Vec2 * negate(const Vec2 &v, Vec2 *dst)
cugl::Vec2::Vec2
Vec2(float x, float y)
Definition: CUVec2.h:112
cugl::Vec2::ANCHOR_BOTTOM_RIGHT
static const Vec2 ANCHOR_BOTTOM_RIGHT
Definition: CUVec2.h:86
cugl::Vec2::map
Vec2 & map(std::function< float(float)> func)
Definition: CUVec2.h:549
cugl::Vec2::operator-=
Vec2 & operator-=(const Vec2 &v)
Definition: CUVec2.h:589
cugl::Vec2::equals
bool equals(const Vec2 &v, float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:867
cugl::Vec2::ANCHOR_MIDDLE_LEFT
static const Vec2 ANCHOR_MIDDLE_LEFT
Definition: CUVec2.h:92
cugl::Vec2::cross
float cross(const Vec2 &other) const
Definition: CUVec2.h:1027
cugl::Vec2::doesSegmentOverlap
static bool doesSegmentOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, Vec2 *S=nullptr, Vec2 *E=nullptr)
cugl::Vec2::getMap
Vec2 getMap(std::function< float(float)> func) const
Definition: CUVec2.h:564
cugl::Vec2::getAngle
float getAngle() const
Definition: CUVec2.h:881
cugl::Vec2::isNearZero
bool isNearZero(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:913
cugl::Vec2::operator<
bool operator<(const Vec2 &v) const
Definition: CUVec2.h:751
cugl::Vec2::normalize
Vec2 & normalize()
cugl::Vec2::getUnrotation
Vec2 getUnrotation(const Vec2 &other)
Definition: CUVec2.h:1166
cugl::Vec2::ANCHOR_TOP_LEFT
static const Vec2 ANCHOR_TOP_LEFT
Definition: CUVec2.h:84
cugl::Vec2::distance
float distance(const Vec2 &v) const
Definition: CUVec2.h:956
cugl::Vec2::getLerp
Vec2 getLerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1288
cugl::Vec2::set
Vec2 & set(float x, float y)
Definition: CUVec2.h:153
cugl::Vec2::isInvertible
bool isInvertible() const
Definition: CUVec2.h:931
cugl::Vec2::y
float y
Definition: CUVec2.h:68
cugl::Vec2::add
Vec2 & add(const Vec2 &v)
Definition: CUVec2.h:377
cugl::Vec2::operator>
bool operator>(const Vec2 &v) const
Definition: CUVec2.h:781
cugl::Vec2::operator-
const Vec2 operator-() const
Definition: CUVec2.h:674
cugl::Vec2::over
bool over(const Vec2 &v) const
Definition: CUVec2.h:852
cugl::Vec2::set
Vec2 & set(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:190
cugl::Vec2::operator+
const Vec2 operator+(const Vec2 &v) const
Definition: CUVec2.h:648
cugl::Vec2::dot
float dot(const Vec2 &v) const
Definition: CUVec2.h:1015
cugl::Vec2::operator/
const Vec2 operator/(float s) const
Definition: CUVec2.h:717
cugl::Vec2::set
Vec2 & set(const float *array)
Definition: CUVec2.h:165
cugl::Vec2
Definition: CUVec2.h:61
cugl::Vec2::operator=
Vec2 & operator=(const float *array)
Definition: CUVec2.h:141
cugl::Vec2::getMidpoint
Vec2 getMidpoint(const Vec2 &other) const
Definition: CUVec2.h:1229
cugl::Vec2::unrotate
Vec2 & unrotate(const Vec2 &other)
Definition: CUVec2.h:1106
cugl::Vec2::operator!=
bool operator!=(const Vec2 &v) const
Definition: CUVec2.h:824
cugl::Vec2::subtract
Vec2 & subtract(const Vec2 &v)
Definition: CUVec2.h:402
cugl::Vec2::angle
static float angle(const Vec2 &v1, const Vec2 &v2)
cugl::Vec2::doesLineOverlap
static bool doesLineOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
cugl::Vec2::ANCHOR_BOTTOM_CENTER
static const Vec2 ANCHOR_BOTTOM_CENTER
Definition: CUVec2.h:96
cugl::Vec2::UNIT_Y
static const Vec2 UNIT_Y
Definition: CUVec2.h:77
cugl::Vec2::rperp
Vec2 & rperp()
Definition: CUVec2.h:1189
cugl::Vec2::add
static Vec2 * add(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
cugl::Vec2::operator/=
Vec2 & operator/=(float s)
Definition: CUVec2.h:622
cugl::Vec2::getNegation
Vec2 getNegation() const
Definition: CUVec2.h:518
cugl::Vec2::set
Vec2 & set(const Vec2 &v)
Definition: CUVec2.h:177
cugl::Vec2::forAngle
static Vec2 forAngle(const float a)
Definition: CUVec2.h:215
cugl::Vec2::doesSegmentIntersect
static bool doesSegmentIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
cugl::Vec2::isOne
bool isOne() const
Definition: CUVec2.h:922
cugl::Vec2::operator+
const Vec2 operator+(const Size &right) const
Definition: CUVec2.h:1548
cugl::Vec2::divide
static Vec2 * divide(const Vec2 &v, float s, Vec2 *dst)
cugl::Vec2::getRPerp
Vec2 getRPerp() const
Definition: CUVec2.h:1216
cugl::Vec2::getNormalization
Vec2 getNormalization() const
Definition: CUVec2.h:1054
cugl::Vec2::operator*=
Vec2 & operator*=(float s)
Definition: CUVec2.h:600
cugl::Vec2::operator-
const Vec2 operator-(const Size &right) const
Definition: CUVec2.h:1562
cugl::Vec3
Definition: CUVec3.h:61
cugl::Vec2::ANCHOR_TOP_RIGHT
static const Vec2 ANCHOR_TOP_RIGHT
Definition: CUVec2.h:88
cugl::Vec2::isLineParallel
static bool isLineParallel(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
cugl::Vec2::clamp
static Vec2 * clamp(const Vec2 &v, const Vec2 &min, const Vec2 &max, Vec2 *dst)
cugl::Vec2::getPerp
Vec2 getPerp() const
Definition: CUVec2.h:1203
cugl::Vec2::scale
static Vec2 * scale(const Vec2 &v, float s, Vec2 *dst)
cugl::Vec2::rotate
Vec2 & rotate(float angle)
cugl::Vec2::getReciprocal
Vec2 getReciprocal() const
Definition: CUVec2.h:534
cugl::Vec2::clamp
Vec2 & clamp(const Vec2 &min, const Vec2 &max)
Definition: CUVec2.h:350
cugl::Vec2::rotate
Vec2 & rotate(const Vec2 &other)
Definition: CUVec2.h:1088
cugl::Vec2::operator*=
Vec2 & operator*=(const Vec2 &v)
Definition: CUVec2.h:611
cugl::Vec2::length
float length() const
Definition: CUVec2.h:985
cugl::Vec2::negate
Vec2 & negate()
Definition: CUVec2.h:492
cugl::Vec2::isZero
bool isZero() const
Definition: CUVec2.h:902
cugl::Vec2::perp
Vec2 & perp()
Definition: CUVec2.h:1177
cugl::Vec2::subtract
static Vec2 * subtract(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)