43 template<
typename Type>
46 template<
typename Type>
49 template<
typename Type>
52 template<
typename Type>
55 template<
typename Type>
58 template<
typename Type>
61 template<
typename Type>
64 template<
typename Type>
74 template<
typename Type>
80 union { Type
x; Type
s; Type
r; };
81 union { Type
y; Type
t; Type
g; };
84 explicit Vec2(
const Type &scalar) :
x(scalar),
y(scalar) { }
87 explicit Vec2(
const Type &p1,
const Type &p2) :
x(p1),
y(p2) { }
88 explicit Vec2(
const Type *array_xy) :
x(array_xy[0]),
y(array_xy[1]) { }
92 template<typename OtherType, typename std::enable_if_t<std::is_integral<Type>::value && !std::is_integral<OtherType>::value,
int> = 0>
93 Vec2(
const Vec2<OtherType>& copy) :
x(static_cast<Type>(std::floor(copy.
x + 0.5f))),
y(static_cast<Type>(std::floor(copy.
y + 0.5f))) {}
95 template<typename OtherType, typename std::enable_if_t<!std::is_integral<Type>::value || std::is_integral<OtherType>::value,
int> = 0>
113 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; }
144 Type diff_x = second.x - first.x; Type diff_y = second.y - first.y;
145 return (diff_x >= -epsilon && diff_x <= epsilon && diff_y >= -epsilon && diff_y <= epsilon);
269 template<
typename Type>
273 template<
typename Type>
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>
316 template<
typename Type>
320 matrix[0 * 2 + 0] *
v.x + matrix[0 * 2 + 1] *
v.y,
321 matrix[1 * 2 + 0] *
v.x + matrix[1 * 2 + 1] *
v.y);
324 template<
typename Type>
328 matrix[0 * 2 + 0] *
v.x + matrix[1 * 2 + 0] *
v.y,
329 matrix[0 * 2 + 1] *
v.x + matrix[1 * 2 + 1] *
v.y);
334 template<
typename Type>
343 template<
typename Type>
346 template<
typename Type>
Angle class.
Definition angle.h:60
2D matrix
Definition vec4.h:52
3D matrix
Definition vec4.h:55
4D matrix
Definition vec4.h:58
2D (x,y) point structure.
Definition vec4.h:64
2D (width,height) size structure.
Definition vec4.h:61
2D vector
Definition vec4.h:43
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.
unsigned char g
Definition vec2.h:81
unsigned char y
Definition vec2.h:81
Angle angle_normed(const Vec2< Type > &vector) const
Calculate the angle between this vector and an other vector, where the vectors are unit vectors.
bool operator!=(const Vec2< Type > &vector) const
!= operator.
Definition vec2.h:261
static Vec2< Type > round(const Vec2< Type > &vector)
Rounds all components on a vector.
Vec2< Type > operator-() const
operator.
Definition vec2.h:240
void operator/=(const Vec2< Type > &vector)
/= operator.
Definition vec2.h:249
Vec2(const Vec2< Type > ©)=default
static Type dot(const Vec2< Type > &vector_1, const Vec2< Type > &vector_2)
Dot products a vector with an other vector.
Definition vec2.h:113
Type round_value(float value) const
Rounds a value for the datatype.
Vec2(const Type &scalar)
Definition vec2.h:84
Vec2(const Type &p1, const Type &p2)
Definition vec2.h:87
Vec2(const Vec3< Type > ©)
Definition vec2.h:85
Vec2()
Definition vec2.h:83
unsigned char t
Definition vec2.h:81
bool operator==(const Vec2< Type > &vector) const
== operator.
Definition vec2.h:258
bool is_equal(const Vec2< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition vec2.h:225
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:264
void operator+=(const Vec2< Type > &vector)
+= operator.
Definition vec2.h:228
void operator*=(const Vec2< Type > &vector)
*= operator.
Definition vec2.h:243
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:142
unsigned char s
Definition vec2.h:80
Type dot(const Vec2< Type > &vector) const
Dot products this vector with an other vector.
Definition vec2.h:169
static Vec2< Type > rotate(const Vec2< Type > &vector, const Vec2< Type > &hotspot, const Angle &angle)
Rotate a vector around another point.
Angle angle(const Vec2< unsigned char > &vector) const
Vec2(const Type *array_xy)
Definition vec2.h:88
Type datatype
Definition vec2.h:78
Vec2< Type > & rotate(const Vec2< Type > &hotspot, const Angle &angle)
Rotate this vector around another point.
unsigned char x
Definition vec2.h:80
Vec2(const Vec2< OtherType > ©)
Definition vec2.h:93
unsigned char r
Definition vec2.h:80
Angle angle_line(const Vec2< Type > &point) const
Calculate the angle of the line joining this point and other point.
Vec2(const Vec4< Type > ©)
Definition vec2.h:86
Vec2< Type > & operator=(const Vec2< Type > &vector)=default
= operator.
Vec2< Type > & round()
Rounds all components of this vector.
void operator-=(const Vec2< Type > &vector)
-= operator.
Definition vec2.h:234
3D vector
Definition vec4.h:46
4D vector
Definition vec4.h:75
Vec2< Type > operator/(const Vec2< Type > &v1, const Vec2< Type > &v2)
/ operator.
Definition vec2.h:306
Vec2< Type > & normalize()
Normalizes this vector.
Definition vec2.h:344
Vec2< unsigned int > Vec2ui
Definition vec2.h:355
Vec2< unsigned short > Vec2us
Definition vec2.h:353
Vec2< double > Vec2d
Definition vec2.h:358
Type length() const
Returns the length (magnitude) of this vector.
Definition vec2.h:335
Vec2< char > Vec2b
Definition vec2.h:352
Vec2< Type > operator-(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:282
static Vec2< Type > normalize(const Vec2< Type > &vector)
Normalizes a vector.
Definition vec2.h:347
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:270
Vec2< int > Vec2i
Definition vec2.h:356
Origin
Alignment origins.
Definition origin.h:39
Vec2< float > Vec2f
Definition vec2.h:357
Vec2< unsigned char > Vec2ub
Definition vec2.h:351
Vec2< Type > operator*(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:294
Vec2< short > Vec2s
Definition vec2.h:354
@ point
Definition graphic_context.h:78
@ length
value is a keyword
Definition style_value_type.h:38