34 #include "../api_core.h"
45 template<
typename Type>
48 template<
typename Type>
51 template<
typename Type>
54 template<
typename Type>
57 template<
typename Type>
60 template<
typename Type>
63 template<
typename Type>
66 template<
typename Type>
76 template<
typename Type>
82 union { Type
x; Type
s; Type
r; };
83 union { Type
y; Type
t; Type
g; };
86 explicit Vec2(
const Type &scalar) :
x(scalar),
y(scalar) { }
89 explicit Vec2(
const Type &p1,
const Type &p2) :
x(p1),
y(p2) { }
90 explicit Vec2(
const Type *array_xy) :
x(array_xy[0]),
y(array_xy[1]) { }
111 static Type
dot(
const Vec2<Type>& vector_1,
const Vec2<Type>& vector_2) {
return vector_1.x*vector_2.x + vector_1.y*vector_2.y; }
142 Type diff_x = second.x - first.x; Type diff_y = second.y - first.y;
143 return (diff_x >= -epsilon && diff_x <= epsilon && diff_y >= -epsilon && diff_y <= epsilon );
272 bool operator < (const Vec2<Type>& vector)
const {
return y < vector.y || (
y == vector.y &&
x < vector.x); }
277 template<
typename Type>
281 template<
typename Type>
285 template<
typename Type>
289 template<
typename Type>
293 template<
typename Type>
297 template<
typename Type>
301 template<
typename Type>
305 template<
typename Type>
309 template<
typename Type>
313 template<
typename Type>
317 template<
typename Type>
321 template<
typename Type>
324 template<
typename Type>
328 matrix[0*2+0]*v.x + matrix[0*2+1]*v.y,
329 matrix[1*2+0]*v.x + matrix[1*2+1]*v.y);
332 template<
typename Type>
336 matrix[0*2+0]*v.x + matrix[1*2+0]*v.y,
337 matrix[0*2+1]*v.x + matrix[1*2+1]*v.y);
414 template<
typename Type>
423 template<
typename Type>
426 template<
typename Type>
void operator+=(const Vec2< Type > &vector)
+= operator.
Definition: vec2.h:236
Type r
Definition: vec2.h:82
Vec2< float > Vec2f
Definition: vec2.h:437
Type x
Definition: vec3.h:81
Vec2< Type > & operator=(const Vec2< Type > &vector)
= operator.
Definition: vec2.h:263
Type round_value(float value) const
Rounds a value for the datatype.
Type t
Definition: vec2.h:83
Angle class.
Definition: angle.h:63
void operator/=(const Vec2< Type > &vector)
/= operator.
Definition: vec2.h:257
Type distance(const Vec2< Type > &vector) const
Calculate the distance between this vector and an other vector.
bool operator!=(const Vec2< Type > &vector) const
!= operator.
Definition: vec2.h:269
Type y
Definition: vec3.h:82
Vec2< unsigned char > Vec2ub
Definition: vec2.h:431
static bool is_equal(const Vec2< Type > &first, const Vec2< Type > &second, Type epsilon)
Returns true if equal within the bounds of an epsilon.
Definition: vec2.h:140
static Vec2< Type > rotate(const Vec2< Type > &vector, const Vec2< Type > &hotspot, const Angle &angle)
Rotate a vector around another point.
Origin
Alignment origins.
Definition: origin.h:41
Vec2(const Vec3< Type > ©)
Definition: vec2.h:87
Vec2< short > Vec2s
Definition: vec2.h:434
bool is_equal(const Vec2< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition: vec2.h:228
Vec2< unsigned short > Vec2us
Definition: vec2.h:433
Vec2< Type > operator/(const Vec2< Type > &v1, const Vec2< Type > &v2)
/ operator.
Definition: vec2.h:314
Vec2< int > Vec2i
Definition: vec2.h:436
Vec2()
Definition: vec2.h:85
Type s
Definition: vec2.h:82
Angle angle_line(const Vec2< Type > &point) const
Calculate the angle of the line joining this point and other point.
Vec2< char > Vec2b
Definition: vec2.h:432
Vec2< Type > operator-() const
operator.
Definition: vec2.h:248
static Pointx< Type > calc_origin(Origin origin, const Sizex< Type > &size)
Returns the anchor point for the origin within the dimensions of the size structure.
void operator*=(const Vec2< Type > &vector)
*= operator.
Definition: vec2.h:251
Type x
Definition: vec2.h:82
static Type dot(const Vec2< Type > &vector_1, const Vec2< Type > &vector_2)
Dot products a vector with an other vector.
Definition: vec2.h:111
Vec2< double > Vec2d
Definition: vec2.h:438
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:278
Angle angle(const Vec2< Type > &vector) const
Calculate the angle between this vector and an other vector.
2D matrix
Definition: mat2.h:46
Angle angle_normed(const Vec2< Type > &vector) const
Calculate the angle between this vector and an other vector, where the vectors are unit vectors...
Vec2(const Type &p1, const Type &p2)
Definition: vec2.h:89
Type datatype
Definition: vec2.h:80
Vec2< Type > operator*(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:302
3D vector
Definition: line_ray.h:49
Type y
Definition: vec4.h:82
Vec2(const Type &scalar)
Definition: vec2.h:86
Type dot(const Vec2< Type > &vector) const
Dot products this vector with an other vector.
Definition: vec2.h:172
2D (x,y) point structure.
Definition: point.h:53
Type g
Definition: vec2.h:83
Type x
Definition: vec4.h:81
4D vector
Definition: size.h:48
Vec2< Type > operator-(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition: vec2.h:290
void operator-=(const Vec2< Type > &vector)
-= operator.
Definition: vec2.h:242
Vec2< Type > & round()
Rounds all components of this vector.
Vec2< unsigned int > Vec2ui
Definition: vec2.h:435
Type length() const
Returns the length (magnitude) of this vector.
Definition: vec2.h:415
bool operator==(const Vec2< Type > &vector) const
== operator.
Definition: vec2.h:266
Vec2< Type > & normalize()
Normalizes this vector.
Definition: vec2.h:424
2D (width,height) size structure.
Definition: size.h:55
Vec2(const Vec4< Type > ©)
Definition: vec2.h:88
Type y
Definition: vec2.h:83
Vec2(const Type *array_xy)
Definition: vec2.h:90