arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::core::vector2d< T > Class Template Reference

2d vector template class with lots of operators and methods. More...

#include <dimension2d.h>

Public Member Functions

 vector2d ()
 Default constructor (null vector) More...
 
 vector2d (T nx, T ny)
 Constructor with two different values. More...
 
 vector2d (T n)
 Constructor with the same value for both members. More...
 
 vector2d (const vector2d< T > &other)
 Copy constructor. More...
 
 vector2d (const dimension2d< T > &other)
 
vector2d< T > operator- () const
 
vector2d< T > & operator= (const vector2d< T > &other)
 
vector2d< T > & operator= (const dimension2d< T > &other)
 
vector2d< T > operator+ (const vector2d< T > &other) const
 
vector2d< T > operator+ (const dimension2d< T > &other) const
 
vector2d< T > & operator+= (const vector2d< T > &other)
 
vector2d< T > operator+ (const T v) const
 
vector2d< T > & operator+= (const T v)
 
vector2d< T > & operator+= (const dimension2d< T > &other)
 
vector2d< T > operator- (const vector2d< T > &other) const
 
vector2d< T > operator- (const dimension2d< T > &other) const
 
vector2d< T > & operator-= (const vector2d< T > &other)
 
vector2d< T > operator- (const T v) const
 
vector2d< T > & operator-= (const T v)
 
vector2d< T > & operator-= (const dimension2d< T > &other)
 
vector2d< T > operator * (const vector2d< T > &other) const
 
vector2d< T > & operator *= (const vector2d< T > &other)
 
vector2d< T > operator * (const T v) const
 
vector2d< T > & operator *= (const T v)
 
vector2d< T > operator/ (const vector2d< T > &other) const
 
vector2d< T > & operator/= (const vector2d< T > &other)
 
vector2d< T > operator/ (const T v) const
 
vector2d< T > & operator/= (const T v)
 
T & operator [] (u32 index)
 
const T & operator [] (u32 index) const
 
bool operator<= (const vector2d< T > &other) const
 sort in order X, Y. Equality with rounding tolerance. More...
 
bool operator>= (const vector2d< T > &other) const
 sort in order X, Y. Equality with rounding tolerance. More...
 
bool operator< (const vector2d< T > &other) const
 sort in order X, Y. Difference must be above rounding tolerance. More...
 
bool operator> (const vector2d< T > &other) const
 sort in order X, Y. Difference must be above rounding tolerance. More...
 
bool operator== (const vector2d< T > &other) const
 
bool operator!= (const vector2d< T > &other) const
 
bool equals (const vector2d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
 Checks if this vector equals the other one. More...
 
vector2d< T > & set (T nx, T ny)
 
vector2d< T > & set (const vector2d< T > &p)
 
getLength () const
 Gets the length of the vector. More...
 
getLengthSQ () const
 Get the squared length of this vector. More...
 
dotProduct (const vector2d< T > &other) const
 Get the dot product of this vector with another. More...
 
bool nearlyParallel (const vector2d< T > &other, const T factor=relativeErrorFactor< T >()) const
 check if this vector is parallel to another vector More...
 
getDistanceFrom (const vector2d< T > &other) const
 Gets distance from another point. More...
 
getDistanceFromSQ (const vector2d< T > &other) const
 Returns squared distance from another point. More...
 
vector2d< T > & rotateBy (f64 degrees, const vector2d< T > &center=vector2d< T >())
 rotates the point anticlockwise around a center by an amount of degrees. More...
 
vector2d< T > & normalize ()
 Normalize the vector. More...
 
f64 getAngleTrig () const
 Calculates the angle of this vector in degrees in the trigonometric sense. More...
 
f64 getAngle () const
 Calculates the angle of this vector in degrees in the counter trigonometric sense. More...
 
f64 getAngleWith (const vector2d< T > &b) const
 Calculates the angle between this vector and another one in degree. More...
 
bool isBetweenPoints (const vector2d< T > &begin, const vector2d< T > &end) const
 Returns if this vector interpreted as a point is on a line between two other points. More...
 
vector2d< T > getInterpolated (const vector2d< T > &other, f64 d) const
 Creates an interpolated vector between this vector and another vector. More...
 
vector2d< T > getInterpolated_quadratic (const vector2d< T > &v2, const vector2d< T > &v3, f64 d) const
 Creates a quadratically interpolated vector between this and two other vectors. More...
 
s32 checkOrientation (const vector2d< T > &b, const vector2d< T > &c) const
 
bool areClockwise (const vector2d< T > &b, const vector2d< T > &c) const
 
bool areCounterClockwise (const vector2d< T > &b, const vector2d< T > &c) const
 
vector2d< T > & interpolate (const vector2d< T > &a, const vector2d< T > &b, f64 d)
 Sets this vector to the linearly interpolated vector between a and b. More...
 

Public Attributes

X
 X coordinate of vector. More...
 
Y
 Y coordinate of vector. More...
 

Detailed Description

template<class T>
class irr::core::vector2d< T >

2d vector template class with lots of operators and methods.

As of Irrlicht 1.6, this class supersedes position2d, which should be considered deprecated.

Definition at line 16 of file dimension2d.h.

Constructor & Destructor Documentation

◆ vector2d() [1/5]

template<class T>
irr::core::vector2d< T >::vector2d ( )
inline

Default constructor (null vector)

Definition at line 25 of file vector2d.h.

25 : X(0), Y(0) {}
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ vector2d() [2/5]

template<class T>
irr::core::vector2d< T >::vector2d ( nx,
ny 
)
inline

Constructor with two different values.

Definition at line 27 of file vector2d.h.

27 : X(nx), Y(ny) {}
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLfixed ny
GLbyte nx
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ vector2d() [3/5]

template<class T>
irr::core::vector2d< T >::vector2d ( n)
inlineexplicit

Constructor with the same value for both members.

Definition at line 29 of file vector2d.h.

29 : X(n), Y(n) {}
GLdouble n
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ vector2d() [4/5]

template<class T>
irr::core::vector2d< T >::vector2d ( const vector2d< T > &  other)
inline

Copy constructor.

Definition at line 31 of file vector2d.h.

31 : X(other.X), Y(other.Y) {}
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ vector2d() [5/5]

template<class T>
irr::core::vector2d< T >::vector2d ( const dimension2d< T > &  other)
inline

Definition at line 33 of file vector2d.h.

33 : X(other.Width), Y(other.Height) {}
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

Member Function Documentation

◆ areClockwise()

template<class T>
bool irr::core::vector2d< T >::areClockwise ( const vector2d< T > &  b,
const vector2d< T > &  c 
) const
inline

Returns true if points (a,b,c) are clockwise on the X,Y plane

Definition at line 365 of file vector2d.h.

366  {
367  T val = (b.Y - Y) * (c.X - b.X) -
368  (b.X - X) * (c.Y - b.Y);
369 
370  return val > 0;
371  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLuint GLfloat * val
GLboolean GLboolean GLboolean b
const GLubyte * c
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ areCounterClockwise()

template<class T>
bool irr::core::vector2d< T >::areCounterClockwise ( const vector2d< T > &  b,
const vector2d< T > &  c 
) const
inline

Returns true if points (a,b,c) are counterclockwise on the X,Y plane

Definition at line 374 of file vector2d.h.

375  {
376  T val = (b.Y - Y) * (c.X - b.X) -
377  (b.X - X) * (c.Y - b.Y);
378 
379  return val < 0;
380  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLuint GLfloat * val
GLboolean GLboolean GLboolean b
const GLubyte * c
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ checkOrientation()

template<class T>
s32 irr::core::vector2d< T >::checkOrientation ( const vector2d< T > &  b,
const vector2d< T > &  c 
) const
inline

Test if this point and another 2 points taken as triplet are colinear, clockwise, anticlockwise. This can be used also to check winding order in triangles for 2D meshes.

Returns
0 if points are colinear, 1 if clockwise, 2 if anticlockwise

Definition at line 345 of file vector2d.h.

346  {
347  // Example of clockwise points
348  //
349  // ^ Y
350  // | A
351  // | . .
352  // | . .
353  // | C.....B
354  // +---------------> X
355 
356  T val = (b.Y - Y) * (c.X - b.X) -
357  (b.X - X) * (c.Y - b.Y);
358 
359  if (val == 0) return 0; // colinear
360 
361  return (val > 0) ? 1 : 2; // clock or counterclock wise
362  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLuint GLfloat * val
GLboolean GLboolean GLboolean b
const GLubyte * c
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ dotProduct()

template<class T>
T irr::core::vector2d< T >::dotProduct ( const vector2d< T > &  other) const
inline

Get the dot product of this vector with another.

Parameters
otherOther vector to take dot product with.
Returns
The dot product of the two vectors.

Definition at line 139 of file vector2d.h.

140  {
141  return X*other.X + Y*other.Y;
142  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ equals()

template<class T>
bool irr::core::vector2d< T >::equals ( const vector2d< T > &  other,
const tolerance = (T)ROUNDING_ERROR_f32 
) const
inline

Checks if this vector equals the other one.

Takes floating point rounding errors into account.

Parameters
otherVector to compare with.
toleranceEpsilon value for both - comparing X and Y.
Returns
True if the two vector are (almost) equal, else false.

Definition at line 119 of file vector2d.h.

120  {
121  return core::equals(X, other.X, tolerance) && core::equals(Y, other.Y, tolerance);
122  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getAngle()

template<class T>
f64 irr::core::vector2d< T >::getAngle ( ) const
inline

Calculates the angle of this vector in degrees in the counter trigonometric sense.

0 is to the right (3 o'clock), values increase clockwise.

Returns
Returns a value between 0 and 360.

Definition at line 237 of file vector2d.h.

238  {
239  if (Y == 0) // corrected thanks to a suggestion by Jox
240  return X < 0 ? 180 : 0;
241  else if (X == 0)
242  return Y < 0 ? 90 : 270;
243 
244  // don't use getLength here to avoid precision loss with s32 vectors
245  // avoid floating-point trouble as sqrt(y*y) is occasionally larger than y, so clamp
246  const f64 tmp = core::clamp(Y / sqrt((f64)(X*X + Y*Y)), -1.0, 1.0);
247  const f64 angle = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64;
248 
249  if (X>0 && Y>0)
250  return angle + 270;
251  else
252  if (X>0 && Y<0)
253  return angle + 90;
254  else
255  if (X<0 && Y<0)
256  return 90 - angle;
257  else
258  if (X<0 && Y>0)
259  return 270 - angle;
260 
261  return angle;
262  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLfloat angle
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getAngleTrig()

template<class T>
f64 irr::core::vector2d< T >::getAngleTrig ( ) const
inline

Calculates the angle of this vector in degrees in the trigonometric sense.

0 is to the right (3 o'clock), values increase counter-clockwise. This method has been suggested by Pr3t3nd3r.

Returns
Returns a value between 0 and 360.

Definition at line 214 of file vector2d.h.

215  {
216  if (Y == 0)
217  return X < 0 ? 180 : 0;
218  else
219  if (X == 0)
220  return Y < 0 ? 270 : 90;
221 
222  if ( Y > 0)
223  if (X > 0)
224  return atan((irr::f64)Y/(irr::f64)X) * RADTODEG64;
225  else
226  return 180.0-atan((irr::f64)Y/-(irr::f64)X) * RADTODEG64;
227  else
228  if (X > 0)
229  return 360.0-atan(-(irr::f64)Y/(irr::f64)X) * RADTODEG64;
230  else
231  return 180.0+atan(-(irr::f64)Y/-(irr::f64)X) * RADTODEG64;
232  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getAngleWith()

template<class T>
f64 irr::core::vector2d< T >::getAngleWith ( const vector2d< T > &  b) const
inline

Calculates the angle between this vector and another one in degree.

Parameters
bOther vector to test with.
Returns
Returns a value between 0 and 90.

Definition at line 267 of file vector2d.h.

268  {
269  f64 tmp = (f64)(X*b.X + Y*b.Y);
270 
271  if (tmp == 0.0)
272  return 90.0;
273 
274  tmp = tmp / core::squareroot((f64)((X*X + Y*Y) * (b.X*b.X + b.Y*b.Y)));
275  if (tmp < 0.0)
276  tmp = -tmp;
277  if ( tmp > 1.0 ) // avoid floating-point trouble
278  tmp = 1.0;
279 
280  return atan(sqrt(1 - tmp*tmp) / tmp) * RADTODEG64;
281  }
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition: irrMath.h:84
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLboolean GLboolean GLboolean b
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getDistanceFrom()

template<class T>
T irr::core::vector2d< T >::getDistanceFrom ( const vector2d< T > &  other) const
inline

Gets distance from another point.

Here, the vector is interpreted as a point in 2-dimensional space.

Parameters
otherOther vector to measure from.
Returns
Distance from other point.

Definition at line 162 of file vector2d.h.

163  {
164  return vector2d<T>(X - other.X, Y - other.Y).getLength();
165  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getDistanceFromSQ()

template<class T>
T irr::core::vector2d< T >::getDistanceFromSQ ( const vector2d< T > &  other) const
inline

Returns squared distance from another point.

Here, the vector is interpreted as a point in 2-dimensional space.

Parameters
otherOther vector to measure from.
Returns
Squared distance from other point.

Definition at line 171 of file vector2d.h.

172  {
173  return vector2d<T>(X - other.X, Y - other.Y).getLengthSQ();
174  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getInterpolated()

template<class T>
vector2d<T> irr::core::vector2d< T >::getInterpolated ( const vector2d< T > &  other,
f64  d 
) const
inline

Creates an interpolated vector between this vector and another vector.

Parameters
otherThe other vector to interpolate with.
dInterpolation value between 0.0f (all the other vector) and 1.0f (all this vector). Note that this is the opposite direction of interpolation to getInterpolated_quadratic()
Returns
An interpolated vector. This vector is not modified.

Definition at line 316 of file vector2d.h.

317  {
318  const f64 inv = 1.0f - d;
319  return vector2d<T>((T)(other.X*inv + X*d), (T)(other.Y*inv + Y*d));
320  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getInterpolated_quadratic()

template<class T>
vector2d<T> irr::core::vector2d< T >::getInterpolated_quadratic ( const vector2d< T > &  v2,
const vector2d< T > &  v3,
f64  d 
) const
inline

Creates a quadratically interpolated vector between this and two other vectors.

Parameters
v2Second vector to interpolate with.
v3Third vector to interpolate with (maximum at 1.0f)
dInterpolation value between 0.0f (all this vector) and 1.0f (all the 3rd vector). Note that this is the opposite direction of interpolation to getInterpolated() and interpolate()
Returns
An interpolated vector. This vector is not modified.

Definition at line 328 of file vector2d.h.

329  {
330  // this*(1-d)*(1-d) + 2 * v2 * (1-d) + v3 * d * d;
331  const f64 inv = 1.0f - d;
332  const f64 mul0 = inv * inv;
333  const f64 mul1 = 2.0f * d * inv;
334  const f64 mul2 = d * d;
335 
336  return vector2d<T> ( (T)(X * mul0 + v2.X * mul1 + v3.X * mul2),
337  (T)(Y * mul0 + v2.Y * mul1 + v3.Y * mul2));
338  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLfloat GLfloat GLfloat v2
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLfloat GLfloat GLfloat GLfloat v3
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getLength()

template<class T>
T irr::core::vector2d< T >::getLength ( ) const
inline

Gets the length of the vector.

Returns
The length of the vector.

Definition at line 129 of file vector2d.h.

129 { return core::squareroot( X*X + Y*Y ); }
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ getLengthSQ()

template<class T>
T irr::core::vector2d< T >::getLengthSQ ( ) const
inline

Get the squared length of this vector.

This is useful because it is much faster than getLength().

Returns
The squared length of the vector.

Definition at line 134 of file vector2d.h.

134 { return X*X + Y*Y; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ interpolate()

template<class T>
vector2d<T>& irr::core::vector2d< T >::interpolate ( const vector2d< T > &  a,
const vector2d< T > &  b,
f64  d 
)
inline

Sets this vector to the linearly interpolated vector between a and b.

Parameters
afirst vector to interpolate with, maximum at 1.0f
bsecond vector to interpolate with, maximum at 0.0f
dInterpolation value between 0.0f (all vector b) and 1.0f (all vector a) Note that this is the opposite direction of interpolation to getInterpolated_quadratic()

Definition at line 388 of file vector2d.h.

389  {
390  X = (T)((f64)b.X + ( ( a.X - b.X ) * d ));
391  Y = (T)((f64)b.Y + ( ( a.Y - b.Y ) * d ));
392  return *this;
393  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ isBetweenPoints()

template<class T>
bool irr::core::vector2d< T >::isBetweenPoints ( const vector2d< T > &  begin,
const vector2d< T > &  end 
) const
inline

Returns if this vector interpreted as a point is on a line between two other points.

It is assumed that the point is on the line.

Parameters
beginBeginning vector to compare between.
endEnding vector to compare between.
Returns
True if this vector is between begin and end, false if not.

Definition at line 288 of file vector2d.h.

289  {
290  // . end
291  // /
292  // /
293  // /
294  // . begin
295  // -
296  // -
297  // . this point (am I inside or outside)?
298  //
299  if (begin.X != end.X)
300  {
301  return ((begin.X <= X && X <= end.X) ||
302  (begin.X >= X && X >= end.X));
303  }
304  else
305  {
306  return ((begin.Y <= Y && Y <= end.Y) ||
307  (begin.Y >= Y && Y >= end.Y));
308  }
309  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ nearlyParallel()

template<class T>
bool irr::core::vector2d< T >::nearlyParallel ( const vector2d< T > &  other,
const factor = relativeErrorFactor<T>() 
) const
inline

check if this vector is parallel to another vector

Definition at line 145 of file vector2d.h.

146  {
147  // https://eagergames.wordpress.com/2017/04/01/fast-parallel-lines-and-vectors-test/
148  // if a || b then a.x/a.y = b.x/b.y (similiar triangles)
149  // if a || b then either both x are 0 or both y are 0.
150 
151  return equalsRelative( X*other.Y, other.X* Y, factor)
152  && // a bit counterintuitive, but makes sure that
153  // only y or only x are 0, and at same time deals
154  // with the case where one vector is zero vector.
155  (X*other.X + Y*other.Y) != 0;
156  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equalsRelative(const T a, const T b, const T factor=relativeErrorFactor< T >())
Definition: irrMath.h:255
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ normalize()

template<class T>
vector2d<T>& irr::core::vector2d< T >::normalize ( )
inline

Normalize the vector.

The null vector is left untouched.

Returns
Reference to this vector, after normalization.

Definition at line 199 of file vector2d.h.

200  {
201  f32 length = (f32)(X*X + Y*Y);
202  if ( length == 0 )
203  return *this;
205  X = (T)(X * length);
206  Y = (T)(Y * length);
207  return *this;
208  }
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLuint GLsizei GLsizei * length
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator *() [1/2]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator * ( const vector2d< T > &  other) const
inline

Definition at line 57 of file vector2d.h.

57 { return vector2d<T>(X * other.X, Y * other.Y); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator *() [2/2]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator * ( const v) const
inline

Definition at line 59 of file vector2d.h.

59 { return vector2d<T>(X * v, Y * v); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator *=() [1/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator *= ( const vector2d< T > &  other)
inline

Definition at line 58 of file vector2d.h.

58 { X*=other.X; Y*=other.Y; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator *=() [2/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator *= ( const v)
inline

Definition at line 60 of file vector2d.h.

60 { X*=v; Y*=v; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator []() [1/2]

template<class T>
T& irr::core::vector2d< T >::operator [] ( u32  index)
inline

Definition at line 67 of file vector2d.h.

68  {
69  _IRR_DEBUG_BREAK_IF(index>1) // access violation
70 
71  return *(&X+index);
72  }
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator []() [2/2]

template<class T>
const T& irr::core::vector2d< T >::operator [] ( u32  index) const
inline

Definition at line 74 of file vector2d.h.

75  {
76  _IRR_DEBUG_BREAK_IF(index>1) // access violation
77 
78  return *(&X+index);
79  }
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator!=()

template<class T>
bool irr::core::vector2d< T >::operator!= ( const vector2d< T > &  other) const
inline

Definition at line 110 of file vector2d.h.

110 { return !equals(other); }
bool equals(const vector2d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
Checks if this vector equals the other one.
Definition: vector2d.h:119

◆ operator+() [1/3]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator+ ( const vector2d< T > &  other) const
inline

Definition at line 43 of file vector2d.h.

43 { return vector2d<T>(X + other.X, Y + other.Y); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator+() [2/3]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator+ ( const dimension2d< T > &  other) const
inline

Definition at line 44 of file vector2d.h.

44 { return vector2d<T>(X + other.Width, Y + other.Height); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator+() [3/3]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator+ ( const v) const
inline

Definition at line 46 of file vector2d.h.

46 { return vector2d<T>(X + v, Y + v); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator+=() [1/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator+= ( const vector2d< T > &  other)
inline

Definition at line 45 of file vector2d.h.

45 { X+=other.X; Y+=other.Y; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator+=() [2/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator+= ( const v)
inline

Definition at line 47 of file vector2d.h.

47 { X+=v; Y+=v; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator+=() [3/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator+= ( const dimension2d< T > &  other)
inline

Definition at line 48 of file vector2d.h.

48 { X += other.Width; Y += other.Height; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-() [1/4]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator- ( ) const
inline

Definition at line 37 of file vector2d.h.

37 { return vector2d<T>(-X, -Y); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-() [2/4]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator- ( const vector2d< T > &  other) const
inline

Definition at line 50 of file vector2d.h.

50 { return vector2d<T>(X - other.X, Y - other.Y); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-() [3/4]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator- ( const dimension2d< T > &  other) const
inline

Definition at line 51 of file vector2d.h.

51 { return vector2d<T>(X - other.Width, Y - other.Height); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-() [4/4]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator- ( const v) const
inline

Definition at line 53 of file vector2d.h.

53 { return vector2d<T>(X - v, Y - v); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-=() [1/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator-= ( const vector2d< T > &  other)
inline

Definition at line 52 of file vector2d.h.

52 { X-=other.X; Y-=other.Y; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-=() [2/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator-= ( const v)
inline

Definition at line 54 of file vector2d.h.

54 { X-=v; Y-=v; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator-=() [3/3]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator-= ( const dimension2d< T > &  other)
inline

Definition at line 55 of file vector2d.h.

55 { X -= other.Width; Y -= other.Height; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator/() [1/2]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator/ ( const vector2d< T > &  other) const
inline

Definition at line 62 of file vector2d.h.

62 { return vector2d<T>(X / other.X, Y / other.Y); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator/() [2/2]

template<class T>
vector2d<T> irr::core::vector2d< T >::operator/ ( const v) const
inline

Definition at line 64 of file vector2d.h.

64 { return vector2d<T>(X / v, Y / v); }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator/=() [1/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator/= ( const vector2d< T > &  other)
inline

Definition at line 63 of file vector2d.h.

63 { X/=other.X; Y/=other.Y; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator/=() [2/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator/= ( const v)
inline

Definition at line 65 of file vector2d.h.

65 { X/=v; Y/=v; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
const GLdouble * v
Definition: SDL_opengl.h:2064
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator<()

template<class T>
bool irr::core::vector2d< T >::operator< ( const vector2d< T > &  other) const
inline

sort in order X, Y. Difference must be above rounding tolerance.

Definition at line 96 of file vector2d.h.

97  {
98  return (X<other.X && !core::equals(X, other.X)) ||
99  (core::equals(X, other.X) && Y<other.Y && !core::equals(Y, other.Y));
100  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator<=()

template<class T>
bool irr::core::vector2d< T >::operator<= ( const vector2d< T > &  other) const
inline

sort in order X, Y. Equality with rounding tolerance.

Definition at line 82 of file vector2d.h.

83  {
84  return (X<other.X || core::equals(X, other.X)) ||
85  (core::equals(X, other.X) && (Y<other.Y || core::equals(Y, other.Y)));
86  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator=() [1/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator= ( const vector2d< T > &  other)
inline

Definition at line 39 of file vector2d.h.

39 { X = other.X; Y = other.Y; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator=() [2/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::operator= ( const dimension2d< T > &  other)
inline

Definition at line 41 of file vector2d.h.

41 { X = other.Width; Y = other.Height; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator==()

template<class T>
bool irr::core::vector2d< T >::operator== ( const vector2d< T > &  other) const
inline

Definition at line 109 of file vector2d.h.

109 { return equals(other); }
bool equals(const vector2d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
Checks if this vector equals the other one.
Definition: vector2d.h:119

◆ operator>()

template<class T>
bool irr::core::vector2d< T >::operator> ( const vector2d< T > &  other) const
inline

sort in order X, Y. Difference must be above rounding tolerance.

Definition at line 103 of file vector2d.h.

104  {
105  return (X>other.X && !core::equals(X, other.X)) ||
106  (core::equals(X, other.X) && Y>other.Y && !core::equals(Y, other.Y));
107  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ operator>=()

template<class T>
bool irr::core::vector2d< T >::operator>= ( const vector2d< T > &  other) const
inline

sort in order X, Y. Equality with rounding tolerance.

Definition at line 89 of file vector2d.h.

90  {
91  return (X>other.X || core::equals(X, other.X)) ||
92  (core::equals(X, other.X) && (Y>other.Y || core::equals(Y, other.Y)));
93  }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ rotateBy()

template<class T>
vector2d<T>& irr::core::vector2d< T >::rotateBy ( f64  degrees,
const vector2d< T > &  center = vector2d<T>() 
)
inline

rotates the point anticlockwise around a center by an amount of degrees.

Parameters
degreesAmount of degrees to rotate by, anticlockwise.
centerRotation center.
Returns
This vector after transformation.

Definition at line 180 of file vector2d.h.

181  {
182  degrees *= DEGTORAD64;
183  const f64 cs = cos(degrees);
184  const f64 sn = sin(degrees);
185 
186  X -= center.X;
187  Y -= center.Y;
188 
189  set((T)(X*cs - Y*sn), (T)(X*sn + Y*cs));
190 
191  X += center.X;
192  Y += center.Y;
193  return *this;
194  }
vector2d< T > & set(T nx, T ny)
Definition: vector2d.h:124
T Y
Y coordinate of vector.
Definition: vector2d.h:399
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition: irrMath.h:81
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ set() [1/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::set ( nx,
ny 
)
inline

Definition at line 124 of file vector2d.h.

124 {X=nx; Y=ny; return *this; }
T Y
Y coordinate of vector.
Definition: vector2d.h:399
GLfixed ny
GLbyte nx
T X
X coordinate of vector.
Definition: vector2d.h:396

◆ set() [2/2]

template<class T>
vector2d<T>& irr::core::vector2d< T >::set ( const vector2d< T > &  p)
inline

Definition at line 125 of file vector2d.h.

125 { X=p.X; Y=p.Y; return *this; }
GLfloat GLfloat p
T Y
Y coordinate of vector.
Definition: vector2d.h:399
T X
X coordinate of vector.
Definition: vector2d.h:396

Member Data Documentation

◆ X

template<class T>
T irr::core::vector2d< T >::X

X coordinate of vector.

Definition at line 396 of file vector2d.h.

◆ Y

template<class T>
T irr::core::vector2d< T >::Y

Y coordinate of vector.

Definition at line 399 of file vector2d.h.


The documentation for this class was generated from the following files: