5#ifndef __IRR_POINT_2D_H_INCLUDED__
6#define __IRR_POINT_2D_H_INCLUDED__
9#include "dimension2d.h"
41 vector2d<T>& operator=(
const dimension2d<T>& other) {
X = other.Width;
Y = other.Height;
return *
this; }
47 vector2d<T>& operator+=(
const T v) {
X+=v;
Y+=v;
return *
this; }
48 vector2d<T>& operator+=(
const dimension2d<T>& other) {
X += other.Width;
Y += other.Height;
return *
this; }
54 vector2d<T>& operator-=(
const T v) {
X-=v;
Y-=v;
return *
this; }
55 vector2d<T>& operator-=(
const dimension2d<T>& other) {
X -= other.Width;
Y -= other.Height;
return *
this; }
60 vector2d<T>& operator*=(
const T v) {
X*=v;
Y*=v;
return *
this; }
65 vector2d<T>& operator/=(
const T v) {
X/=v;
Y/=v;
return *
this; }
126 return X*other.
X +
Y*other.
Y;
154 const f64 cs = cos(degrees);
155 const f64 sn = sin(degrees);
160 set((T)(
X*cs -
Y*sn), (T)(
X*sn +
Y*cs));
175 length = core::reciprocal_squareroot ( length );
188 return X < 0 ? 180 : 0;
191 return Y < 0 ? 270 : 90;
211 return X < 0 ? 180 : 0;
213 return Y < 0 ? 90 : 270;
218 const f64 angle = atan( core::squareroot(1 - tmp*tmp) / tmp) *
RADTODEG64;
245 tmp = tmp / core::squareroot((
f64)((
X*
X +
Y*
Y) * (b.
X*b.
X + b.
Y*b.
Y)));
251 return atan(sqrt(1 - tmp*tmp) / tmp) *
RADTODEG64;
261 if (begin.
X != end.
X)
263 return ((begin.
X <=
X &&
X <= end.
X) ||
264 (begin.
X >=
X &&
X >= end.
X));
268 return ((begin.
Y <=
Y &&
Y <= end.
Y) ||
269 (begin.
Y >=
Y &&
Y >= end.
Y));
293 const f64 inv = 1.0f - d;
294 const f64 mul0 = inv * inv;
295 const f64 mul1 = 2.0f * d * inv;
296 const f64 mul2 = d * d;
299 (T)(
Y * mul0 + v2.
Y * mul1 + v3.
Y * mul2));
310 X = (T)((
f64)b.
X + ( ( a.
X - b.
X ) * d ));
311 Y = (T)((
f64)b.
Y + ( ( a.
Y - b.
Y ) * d ));
328 template<
class S,
class T>
336 bool dimension2d<T>::operator==(
const vector2d<T>& other)
const {
return Width == other.X && Height == other.Y; }
Specifies a 2 dimensional size.
Definition dimension2d.h:21
dimension2d()
Default constructor for empty dimension.
Definition dimension2d.h:24
2d vector template class with lots of operators and methods.
Definition vector2d.h:22
bool operator<(const vector2d< T > &other) const
sort in order X, Y. Difference must be above rounding tolerance.
Definition vector2d.h:82
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.
Definition vector2d.h:308
T getDistanceFrom(const vector2d< T > &other) const
Gets distance from another point.
Definition vector2d.h:133
f64 getAngleTrig() const
Calculates the angle of this vector in degrees in the trigonometric sense.
Definition vector2d.h:185
vector2d()
Default constructor (null vector).
Definition vector2d.h:25
bool operator>(const vector2d< T > &other) const
sort in order X, Y. Difference must be above rounding tolerance.
Definition vector2d.h:89
f64 getAngleWith(const vector2d< T > &b) const
Calculates the angle between this vector and another one in degree.
Definition vector2d.h:238
T getLength() const
Gets the length of the vector.
Definition vector2d.h:114
vector2d(T n)
Constructor with the same value for both members.
Definition vector2d.h:29
vector2d(const vector2d< T > &other)
Copy constructor.
Definition vector2d.h:31
f32 X
Definition vector2d.h:316
vector2d< T > getInterpolated(const vector2d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector2d.h:278
bool equals(const vector2d< T > &other) const
Checks if this vector equals the other one.
Definition vector2d.h:104
f32 Y
Definition vector2d.h:319
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.
Definition vector2d.h:290
T getDistanceFromSQ(const vector2d< T > &other) const
Returns squared distance from another point.
Definition vector2d.h:142
vector2d< T > & rotateBy(f64 degrees, const vector2d< T > ¢er=vector2d< T >())
rotates the point anticlockwise around a center by an amount of degrees.
Definition vector2d.h:151
bool operator>=(const vector2d< T > &other) const
sort in order X, Y. Equality with rounding tolerance.
Definition vector2d.h:75
T getLengthSQ() const
Get the squared length of this vector.
Definition vector2d.h:119
bool operator<=(const vector2d< T > &other) const
sort in order X, Y. Equality with rounding tolerance.
Definition vector2d.h:68
T dotProduct(const vector2d< T > &other) const
Get the dot product of this vector with another.
Definition vector2d.h:124
f64 getAngle() const
Calculates the angle of this vector in degrees in the counter trigonometric sense.
Definition vector2d.h:208
vector2d(T nx, T ny)
Constructor with two different values.
Definition vector2d.h:27
vector2d< T > & normalize()
Normalize the vector.
Definition vector2d.h:170
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.
Definition vector2d.h:259
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.h:166
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition irrMath.h:80
vector2d< s32 > vector2di
Typedef for integer 2d vector.
Definition vector2d.h:326
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition irrMath.h:83
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
double f64
64 bit floating point variable.
Definition irrTypes.h:108