42 #include "CUMathBase.h"
99 #pragma mark Constructors
112 Vec2(
float x,
float y) { this->x =
x; this->y =
y; }
119 Vec2(
const float* array) { x = array[0]; y = array[1]; }
128 x = p2.
x-p1.
x; y = p2.
y-p1.
y;
177 this->x =
x; this->y =
y;
189 x = array[0]; y = array[1];
214 x = p2.
x-p1.
x; y = p2.
y-p1.
y;
230 #pragma mark Static Arithmetic
239 return Vec2(cosf(a), sinf(a));
364 #pragma mark Arithmetic
374 x = clampf(x, min.
x, max.
x);
375 y = clampf(y, min.
y, max.
y);
390 return Vec2(clampf(x,min.
x,max.
x), clampf(y, min.
y, max.
y));
414 this->x +=
x; this->y +=
y;
439 this->x -=
x; this->y -=
y;
530 x = 1.0f/
x; y = 1.0f/
y;
573 x = func(x); y = func(y);
588 return Vec2(func(x), func(y));
593 #pragma mark Operators
673 return result.
add(v);
713 return result.
scale(s);
728 return result.
scale(v);
762 #pragma mark Comparisons
775 return (x == v.
x ? y < v.
y : x < v.
x);
790 return (x == v.
x ? y <= v.
y : x <= v.
x);
805 return (x == v.
x ? y > v.
y : x > v.
x);
820 return (x == v.
x ? y >= v.
y : x >= v.
x);
834 return x == v.
x && y == v.
y;
848 return x != v.
x || y != v.
y;
862 return x <= v.
x && y <= v.
y;
876 return x >= v.
x && y >= v.
y;
890 bool equals(
const Vec2& v,
float variance=CU_MATH_EPSILON)
const {
896 #pragma mark Linear Attributes
926 return x == 0.0f && y == 0.0f;
946 return x == 1.0f && y == 1.0f;
955 return x != 0.0f && y != 0.0f;
965 bool isUnit(
float variance=CU_MATH_EPSILON)
const {
967 return dot < variance && dot > -variance;
998 return (x-v.
x)*(x-v.
x)+(y-v.
y)*(y-v.
y);
1030 #pragma mark Linear Algebra
1038 float dot(
const Vec2& v)
const {
return (x * v.
x + y * v.
y); }
1051 return x*other.
y - y*other.
x;
1113 float tx =
x;
float ty =
y;
1114 float ox = other.
x;
float oy = other.
y;
1115 x = tx*ox - ty*oy; y = tx*oy + ty*ox;
1130 float tx =
x;
float ty =
y;
1131 float ox = other.
x;
float oy = other.
y;
1132 x = tx*ox + ty*oy; y = -tx*oy + ty*ox;
1174 return Vec2(x*other.
x - y*other.
y, x*other.
y + y*other.
x);
1190 return Vec2(x*other.
x + y*other.
y, y*other.
x - x*other.
y);
1201 float a =
x; x = -
y; y = a;
1213 float a =
x; x =
y; y = -a;
1253 return Vec2((x + other.
x) / 2.0f, (y + other.
y) / 2.0f);
1278 return other * (
dot(other)/other.
dot(other));
1295 *
this *= (1.f - alpha);
1296 return *
this += other * alpha;
1312 return *
this * (1.f - alpha) + other * alpha;
1317 #pragma mark Static Linear Algebra
1419 float *
S =
nullptr,
float *
T =
nullptr);
1504 #pragma mark Conversion Methods
1516 std::string
toString(
bool verbose =
false)
const;
1522 operator Size()
const;
1573 return result += right;
1587 return result -= right;
1595 operator Vec3()
const;
1623 operator Vec4()
const;
1650 #pragma mark Friend Operations
1662 return result.
scale(x);
Vec2 & operator+=(const Vec2 &v)
Definition: CUVec2.h:601
static Vec2 * scale(const Vec2 &v, float s, Vec2 *dst)
Vec2 & scale(float s)
Definition: CUVec2.h:450
Vec2 & operator/=(const Vec2 &v)
Definition: CUVec2.h:658
Vec2 & clamp(const Vec2 &min, const Vec2 &max)
Definition: CUVec2.h:373
float distance(const Vec2 &v) const
Definition: CUVec2.h:979
Vec2 getNegation() const
Definition: CUVec2.h:541
bool isUnit(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:965
Vec2(const float *array)
Definition: CUVec2.h:119
Vec2 & add(float x, float y)
Definition: CUVec2.h:413
float distanceSquared(const Vec2 &v) const
Definition: CUVec2.h:997
float x
Definition: CUVec2.h:66
Vec2 getMap(std::function< float(float)> func) const
Definition: CUVec2.h:587
Vec2 getPerp() const
Definition: CUVec2.h:1226
static Vec2 * negate(const Vec2 &v, Vec2 *dst)
static Vec2 * clamp(const Vec2 &v, const Vec2 &min, const Vec2 &max, Vec2 *dst)
float y
Definition: CUVec2.h:68
static Vec2 * add(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
static const Vec2 ONE
Definition: CUVec2.h:73
Vec2 & map(std::function< float(float)> func)
Definition: CUVec2.h:572
static const Vec2 ANCHOR_MIDDLE_LEFT
Definition: CUVec2.h:92
Vec2 & operator-=(const Vec2 &v)
Definition: CUVec2.h:612
Vec2 & negate()
Definition: CUVec2.h:515
Vec2 & scale(float sx, float sy)
Definition: CUVec2.h:463
static Vec2 * subtract(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
static bool doesSegmentIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
Vec2 & operator=(const Vec2 &v)
Definition: CUVec2.h:153
std::string toString(bool verbose=false) const
Vec2 & perp()
Definition: CUVec2.h:1200
bool isOne() const
Definition: CUVec2.h:945
Vec2 & operator*=(float s)
Definition: CUVec2.h:623
Vec2 getRotation(const Vec2 &other)
Definition: CUVec2.h:1173
const Vec2 operator/(const Vec2 &v) const
Definition: CUVec2.h:755
Vec2 & scale(const Vec2 &v)
Definition: CUVec2.h:475
Vec2 getReciprocal() const
Definition: CUVec2.h:557
Vec2 & reciprocate()
Definition: CUVec2.h:529
const Vec2 operator-(const Vec2 &v) const
Definition: CUVec2.h:685
Vec2 getMidpoint(const Vec2 &other) const
Definition: CUVec2.h:1252
const Vec2 operator-(const Size &right) const
Definition: CUVec2.h:1585
Vec2 & subtract(float x, float y)
Definition: CUVec2.h:438
Vec2 & set(const Vec2 &v)
Definition: CUVec2.h:200
static const Vec2 ANCHOR_MIDDLE_BOTTOM
Definition: CUVec2.h:96
bool operator==(const Vec2 &v) const
Definition: CUVec2.h:833
Vec2(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:127
bool under(const Vec2 &v) const
Definition: CUVec2.h:861
bool isZero() const
Definition: CUVec2.h:925
bool operator!=(const Vec2 &v) const
Definition: CUVec2.h:847
float length() const
Definition: CUVec2.h:1008
const Vec2 operator-() const
Definition: CUVec2.h:697
static float angle(const Vec2 &v1, const Vec2 &v2)
Vec2 getClamp(const Vec2 &min, const Vec2 &max) const
Definition: CUVec2.h:389
Vec2 & operator=(const float *array)
Definition: CUVec2.h:164
Vec2 getLerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1311
static bool doesLineOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
static const Vec2 ANCHOR_TOP_RIGHT
Definition: CUVec2.h:88
static Vec2 * midpoint(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
static const Vec2 ANCHOR_MIDDLE_RIGHT
Definition: CUVec2.h:90
Vec2 getNormalization() const
Definition: CUVec2.h:1077
bool operator<=(const Vec2 &v) const
Definition: CUVec2.h:789
float lengthSquared() const
Definition: CUVec2.h:1024
Vec2 getRotation(float angle)
static Vec2 * divide(const Vec2 &v, float s, Vec2 *dst)
Vec2 Point2
Definition: CUVec2.h:1666
Vec2 & operator*=(const Vec2 &v)
Definition: CUVec2.h:634
float cross(const Vec2 &other) const
Definition: CUVec2.h:1050
bool operator<(const Vec2 &v) const
Definition: CUVec2.h:774
float getAngle() const
Definition: CUVec2.h:904
static const Vec2 ANCHOR_BOTTOM_LEFT
Definition: CUVec2.h:82
Vec2 & subtract(const Vec2 &v)
Definition: CUVec2.h:425
Vec2(const Vec2 ©)
Definition: CUVec2.h:136
Vec2 & operator/=(float s)
Definition: CUVec2.h:645
const Vec2 operator*(const Vec2 &v) const
Definition: CUVec2.h:726
Vec2 getProjection(const Vec2 &other) const
Definition: CUVec2.h:1277
Vec2 getUnrotation(const Vec2 &other)
Definition: CUVec2.h:1189
static bool doesSegmentOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, Vec2 *S=nullptr, Vec2 *E=nullptr)
const Vec2 operator*(float s) const
Definition: CUVec2.h:711
static const Vec2 ANCHOR_MIDDLE_TOP
Definition: CUVec2.h:94
Vec2 & add(const Vec2 &v)
Definition: CUVec2.h:400
static bool isLineParallel(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
static Vec2 * reciprocate(const Vec2 &v, Vec2 *dst)
const Vec2 operator+(const Vec2 &v) const
Definition: CUVec2.h:671
bool isNearZero(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:936
Vec2(float x, float y)
Definition: CUVec2.h:112
Vec2 & lerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1294
bool isInvertible() const
Definition: CUVec2.h:954
~Vec2()
Definition: CUVec2.h:141
bool operator>=(const Vec2 &v) const
Definition: CUVec2.h:819
Vec2 & set(const float *array)
Definition: CUVec2.h:188
float dot(const Vec2 &v) const
Definition: CUVec2.h:1038
Vec2 getRPerp() const
Definition: CUVec2.h:1239
static Vec2 forAngle(const float a)
Definition: CUVec2.h:238
static const Vec2 UNIT_X
Definition: CUVec2.h:75
Vec2 & project(const Vec2 &other)
Definition: CUVec2.h:1263
bool equals(const Vec2 &v, float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:890
static Vec2 getIntersection(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
int operator*(Font::Style value)
Definition: CUFont.h:1503
const Vec2 operator+(const Size &right) const
Definition: CUVec2.h:1571
static bool doesLineIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, float *S=nullptr, float *T=nullptr)
static const Vec2 UNIT_Y
Definition: CUVec2.h:77
bool over(const Vec2 &v) const
Definition: CUVec2.h:875
Vec2 & rperp()
Definition: CUVec2.h:1212
Vec2 & set(float x, float y)
Definition: CUVec2.h:176
Definition: CUAnimationNode.h:52
Vec2 & rotate(const Vec2 &other)
Definition: CUVec2.h:1111
static const Vec2 ZERO
Definition: CUVec2.h:71
Vec2 & set(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:213
const Vec2 operator/(float s) const
Definition: CUVec2.h:740
Vec2 & unrotate(const Vec2 &other)
Definition: CUVec2.h:1129
static const Vec2 ANCHOR_BOTTOM_RIGHT
Definition: CUVec2.h:86
bool operator>(const Vec2 &v) const
Definition: CUVec2.h:804
Vec2 & rotate(float angle)
Vec2()
Definition: CUVec2.h:104
static const Vec2 ANCHOR_MIDDLE
Definition: CUVec2.h:80
static const Vec2 ANCHOR_TOP_LEFT
Definition: CUVec2.h:84
Vec2 & setZero()
Definition: CUVec2.h:223