 |
CUGL 1.3
Cornell University Game Library
|
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;
154 this->x =
x; this->y =
y;
166 x = array[0];
y = array[1];
191 x = p2.
x-p1.
x;
y = p2.
y-p1.
y;
207 #pragma mark Static Arithmetic
216 return Vec2(cosf(a), sinf(a));
341 #pragma mark Arithmetic
351 x = clampf(
x, min.
x, max.
x);
352 y = clampf(
y, min.
y, max.
y);
367 return Vec2(clampf(
x,min.
x,max.
x), clampf(
y, min.
y, max.
y));
391 this->x +=
x; this->y +=
y;
416 this->x -=
x; this->y -=
y;
507 x = 1.0f/
x;
y = 1.0f/
y;
550 x = func(
x);
y = func(
y);
565 return Vec2(func(
x), func(
y));
570 #pragma mark Operators
650 return result.
add(v);
690 return result.
scale(s);
705 return result.
scale(v);
739 #pragma mark Comparisons
752 return (
x == v.
x ?
y < v.
y :
x < v.
x);
767 return (
x == v.
x ?
y <= v.
y :
x <= v.
x);
782 return (
x == v.
x ?
y > v.
y :
x > v.
x);
797 return (
x == v.
x ?
y >= v.
y :
x >= v.
x);
811 return x == v.
x &&
y == v.
y;
825 return x != v.
x ||
y != v.
y;
839 return x <= v.
x &&
y <= v.
y;
853 return x >= v.
x &&
y >= v.
y;
867 bool equals(
const Vec2& v,
float variance=CU_MATH_EPSILON)
const {
873 #pragma mark Linear Attributes
903 return x == 0.0f &&
y == 0.0f;
923 return x == 1.0f &&
y == 1.0f;
932 return x != 0.0f &&
y != 0.0f;
942 bool isUnit(
float variance=CU_MATH_EPSILON)
const {
944 return dot < variance && dot > -variance;
975 return (
x-v.
x)*(
x-v.
x)+(
y-v.
y)*(
y-v.
y);
1007 #pragma mark Linear Algebra
1028 return x*other.
y -
y*other.
x;
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;
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;
1151 return Vec2(
x*other.
x -
y*other.
y,
x*other.
y +
y*other.
x);
1167 return Vec2(
x*other.
x +
y*other.
y,
y*other.
x -
x*other.
y);
1178 float a =
x;
x = -
y;
y = a;
1190 float a =
x;
x =
y;
y = -a;
1230 return Vec2((
x + other.
x) / 2.0f, (
y + other.
y) / 2.0f);
1255 return other * (
dot(other)/other.
dot(other));
1272 *
this *= (1.f - alpha);
1273 return *
this += other * alpha;
1289 return *
this * (1.f - alpha) + other * alpha;
1294 #pragma mark Static Linear Algebra
1396 float *S =
nullptr,
float *T =
nullptr);
1462 Vec2* S =
nullptr,
Vec2* E =
nullptr);
1481 #pragma mark Conversion Methods
1493 std::string
toString(
bool verbose =
false)
const;
1499 operator Size()
const;
1550 return result += right;
1564 return result -= right;
1572 operator Vec3()
const;
1600 operator Vec4()
const;
1627 #pragma mark Friend Operations
1637 inline const Vec2 operator*(
float x,
const Vec2& v) {
1639 return result.scale(x);
1643 typedef Vec2 Point2;
Vec2 & subtract(float x, float y)
Definition: CUVec2.h:415
float lengthSquared() const
Definition: CUVec2.h:1001
Vec2 getProjection(const Vec2 &other) const
Definition: CUVec2.h:1254
static const Vec2 ANCHOR_TOP_CENTER
Definition: CUVec2.h:94
bool isUnit(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:942
Vec2 getRotation(float angle)
static const Vec2 ANCHOR_MIDDLE_RIGHT
Definition: CUVec2.h:90
Vec2 & reciprocate()
Definition: CUVec2.h:506
Vec2 & project(const Vec2 &other)
Definition: CUVec2.h:1240
Vec2 & scale(float s)
Definition: CUVec2.h:427
Vec2(const float *array)
Definition: CUVec2.h:119
Vec2 & scale(const Vec2 &v)
Definition: CUVec2.h:452
bool operator==(const Vec2 &v) const
Definition: CUVec2.h:810
const Vec2 operator*(float s) const
Definition: CUVec2.h:688
Vec2(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:127
std::string toString(bool verbose=false) const
Vec2 getRotation(const Vec2 &other)
Definition: CUVec2.h:1150
static const Vec2 UNIT_X
Definition: CUVec2.h:75
static const Vec2 ZERO
Definition: CUVec2.h:71
Vec2 & add(float x, float y)
Definition: CUVec2.h:390
bool under(const Vec2 &v) const
Definition: CUVec2.h:838
bool operator>=(const Vec2 &v) const
Definition: CUVec2.h:796
Vec2 & scale(float sx, float sy)
Definition: CUVec2.h:440
bool operator<=(const Vec2 &v) const
Definition: CUVec2.h:766
static Vec2 getIntersection(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
static const Vec2 ONE
Definition: CUVec2.h:73
Vec2 & setZero()
Definition: CUVec2.h:200
static Vec2 * midpoint(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
static const Vec2 ANCHOR_CENTER
Definition: CUVec2.h:80
static bool doesLineIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, float *S=nullptr, float *T=nullptr)
const Vec2 operator*(const Vec2 &v) const
Definition: CUVec2.h:703
Vec2()
Definition: CUVec2.h:104
Vec2 & operator/=(const Vec2 &v)
Definition: CUVec2.h:635
Vec2 & operator+=(const Vec2 &v)
Definition: CUVec2.h:578
static Vec2 * reciprocate(const Vec2 &v, Vec2 *dst)
float x
Definition: CUVec2.h:66
const Vec2 operator-(const Vec2 &v) const
Definition: CUVec2.h:662
Vec2 & lerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1271
const Vec2 operator/(const Vec2 &v) const
Definition: CUVec2.h:732
Vec2 getClamp(const Vec2 &min, const Vec2 &max) const
Definition: CUVec2.h:366
static const Vec2 ANCHOR_BOTTOM_LEFT
Definition: CUVec2.h:82
float distanceSquared(const Vec2 &v) const
Definition: CUVec2.h:974
static Vec2 * negate(const Vec2 &v, Vec2 *dst)
Vec2(float x, float y)
Definition: CUVec2.h:112
static const Vec2 ANCHOR_BOTTOM_RIGHT
Definition: CUVec2.h:86
Vec2 & map(std::function< float(float)> func)
Definition: CUVec2.h:549
Vec2 & operator-=(const Vec2 &v)
Definition: CUVec2.h:589
bool equals(const Vec2 &v, float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:867
static const Vec2 ANCHOR_MIDDLE_LEFT
Definition: CUVec2.h:92
float cross(const Vec2 &other) const
Definition: CUVec2.h:1027
static bool doesSegmentOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D, Vec2 *S=nullptr, Vec2 *E=nullptr)
Vec2 getMap(std::function< float(float)> func) const
Definition: CUVec2.h:564
float getAngle() const
Definition: CUVec2.h:881
bool isNearZero(float variance=CU_MATH_EPSILON) const
Definition: CUVec2.h:913
bool operator<(const Vec2 &v) const
Definition: CUVec2.h:751
Vec2 getUnrotation(const Vec2 &other)
Definition: CUVec2.h:1166
static const Vec2 ANCHOR_TOP_LEFT
Definition: CUVec2.h:84
float distance(const Vec2 &v) const
Definition: CUVec2.h:956
Vec2 getLerp(const Vec2 &other, float alpha)
Definition: CUVec2.h:1288
Vec2 & set(float x, float y)
Definition: CUVec2.h:153
bool isInvertible() const
Definition: CUVec2.h:931
float y
Definition: CUVec2.h:68
Vec2 & add(const Vec2 &v)
Definition: CUVec2.h:377
bool operator>(const Vec2 &v) const
Definition: CUVec2.h:781
const Vec2 operator-() const
Definition: CUVec2.h:674
bool over(const Vec2 &v) const
Definition: CUVec2.h:852
Vec2 & set(const Vec2 &p1, const Vec2 &p2)
Definition: CUVec2.h:190
const Vec2 operator+(const Vec2 &v) const
Definition: CUVec2.h:648
float dot(const Vec2 &v) const
Definition: CUVec2.h:1015
const Vec2 operator/(float s) const
Definition: CUVec2.h:717
Vec2 & set(const float *array)
Definition: CUVec2.h:165
Vec2 & operator=(const float *array)
Definition: CUVec2.h:141
Vec2 getMidpoint(const Vec2 &other) const
Definition: CUVec2.h:1229
Vec2 & unrotate(const Vec2 &other)
Definition: CUVec2.h:1106
bool operator!=(const Vec2 &v) const
Definition: CUVec2.h:824
Vec2 & subtract(const Vec2 &v)
Definition: CUVec2.h:402
static float angle(const Vec2 &v1, const Vec2 &v2)
static bool doesLineOverlap(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
static const Vec2 ANCHOR_BOTTOM_CENTER
Definition: CUVec2.h:96
static const Vec2 UNIT_Y
Definition: CUVec2.h:77
Vec2 & rperp()
Definition: CUVec2.h:1189
static Vec2 * add(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)
Vec2 & operator/=(float s)
Definition: CUVec2.h:622
Vec2 getNegation() const
Definition: CUVec2.h:518
Vec2 & set(const Vec2 &v)
Definition: CUVec2.h:177
static Vec2 forAngle(const float a)
Definition: CUVec2.h:215
static bool doesSegmentIntersect(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
bool isOne() const
Definition: CUVec2.h:922
const Vec2 operator+(const Size &right) const
Definition: CUVec2.h:1548
static Vec2 * divide(const Vec2 &v, float s, Vec2 *dst)
Vec2 getRPerp() const
Definition: CUVec2.h:1216
Vec2 getNormalization() const
Definition: CUVec2.h:1054
Vec2 & operator*=(float s)
Definition: CUVec2.h:600
const Vec2 operator-(const Size &right) const
Definition: CUVec2.h:1562
static const Vec2 ANCHOR_TOP_RIGHT
Definition: CUVec2.h:88
static bool isLineParallel(const Vec2 &A, const Vec2 &B, const Vec2 &C, const Vec2 &D)
static Vec2 * clamp(const Vec2 &v, const Vec2 &min, const Vec2 &max, Vec2 *dst)
Vec2 getPerp() const
Definition: CUVec2.h:1203
static Vec2 * scale(const Vec2 &v, float s, Vec2 *dst)
Vec2 & rotate(float angle)
Vec2 getReciprocal() const
Definition: CUVec2.h:534
Vec2 & clamp(const Vec2 &min, const Vec2 &max)
Definition: CUVec2.h:350
Vec2 & rotate(const Vec2 &other)
Definition: CUVec2.h:1088
Vec2 & operator*=(const Vec2 &v)
Definition: CUVec2.h:611
float length() const
Definition: CUVec2.h:985
Vec2 & negate()
Definition: CUVec2.h:492
bool isZero() const
Definition: CUVec2.h:902
Vec2 & perp()
Definition: CUVec2.h:1177
static Vec2 * subtract(const Vec2 &v1, const Vec2 &v2, Vec2 *dst)