5#ifndef NIRT_POINT_2D_HPP_INCLUDED
6#define NIRT_POINT_2D_HPP_INCLUDED
8#include <nirtcpp/core/engine/irrMath.hpp>
9#include <nirtcpp/core/engine/dimension2d.hpp>
35 vector2d<T> operator-()
const {
return vector2d<T>(-
X, -
Y); }
37 vector2d<T>& operator=(
const dimension2d<T>& other) {
X = other.Width;
Y = other.Height;
return *
this; }
39 vector2d<T> operator+(
const vector2d<T>& other)
const {
return vector2d<T>(
X + other.X,
Y + other.Y); }
40 vector2d<T> operator+(
const dimension2d<T>& other)
const {
return vector2d<T>(
X + other.Width,
Y + other.Height); }
41 vector2d<T>& operator+=(
const vector2d<T>& other) {
X+=other.X;
Y+=other.Y;
return *
this; }
42 vector2d<T> operator+(
const T v)
const {
return vector2d<T>(
X + v,
Y + v); }
43 vector2d<T>& operator+=(
const T v) {
X+=v;
Y+=v;
return *
this; }
44 vector2d<T>& operator+=(
const dimension2d<T>& other) {
X += other.Width;
Y += other.Height;
return *
this; }
46 vector2d<T> operator-(
const vector2d<T>& other)
const {
return vector2d<T>(
X - other.X,
Y - other.Y); }
47 vector2d<T> operator-(
const dimension2d<T>& other)
const {
return vector2d<T>(
X - other.Width,
Y - other.Height); }
48 vector2d<T>& operator-=(
const vector2d<T>& other) {
X-=other.X;
Y-=other.Y;
return *
this; }
49 vector2d<T> operator-(
const T v)
const {
return vector2d<T>(
X - v,
Y - v); }
50 vector2d<T>& operator-=(
const T v) {
X-=v;
Y-=v;
return *
this; }
51 vector2d<T>& operator-=(
const dimension2d<T>& other) {
X -= other.Width;
Y -= other.Height;
return *
this; }
53 vector2d<T> operator*(
const vector2d<T>& other)
const {
return vector2d<T>(
X * other.X,
Y * other.Y); }
54 vector2d<T>& operator*=(
const vector2d<T>& other) {
X*=other.X;
Y*=other.Y;
return *
this; }
55 vector2d<T> operator*(
const T v)
const {
return vector2d<T>(
X * v,
Y * v); }
56 vector2d<T>& operator*=(
const T v) {
X*=v;
Y*=v;
return *
this; }
58 vector2d<T> operator/(
const vector2d<T>& other)
const {
return vector2d<T>(
X / other.X,
Y / other.Y); }
59 vector2d<T>& operator/=(
const vector2d<T>& other) {
X/=other.X;
Y/=other.Y;
return *
this; }
60 vector2d<T> operator/(
const T v)
const {
return vector2d<T>(
X / v,
Y / v); }
61 vector2d<T>& operator/=(
const T v) {
X/=v;
Y/=v;
return *
this; }
63 T& operator [](
u32 index)
65 NIRT_DEBUG_BREAK_IF(index>1)
70 const T& operator [](
u32 index)
const
72 NIRT_DEBUG_BREAK_IF(index>1)
106 bool operator!=(
const vector2d<T>& other)
const {
return !
equals(other); }
121 vector2d<T>& set(
const vector2d<T>& p) {
X=p.X;
Y=p.Y;
return *
this; }
213 return X < 0 ? 180 : 0;
216 return Y < 0 ? 270 : 90;
236 return X < 0 ? 180 : 0;
238 return Y < 0 ? 90 : 270;
270 tmp =
tmp / core::squareroot((
f64)((
X*
X +
Y*
Y) * (b.X*b.X + b.Y*b.Y)));
295 if (begin.X != end.X)
297 return ((begin.X <=
X &&
X <= end.X) ||
298 (begin.X >=
X &&
X >= end.X));
302 return ((begin.Y <=
Y &&
Y <= end.Y) ||
303 (begin.Y >=
Y &&
Y >= end.Y));
352 T val = (b.Y -
Y) * (c.X - b.X) -
353 (b.X -
X) * (c.Y - b.Y);
355 if (
val == 0)
return 0;
357 return (
val > 0) ? 1 : 2;
363 T val = (b.Y -
Y) * (c.X - b.X) -
364 (b.X -
X) * (c.Y - b.Y);
372 T val = (b.Y -
Y) * (c.X - b.X) -
373 (b.X -
X) * (c.Y - b.Y);
386 X = (
T)((
f64)b.X + ( ( a.X - b.X ) *
d ));
387 Y = (
T)((
f64)b.Y + ( ( a.Y - b.Y ) *
d ));
404 template<
class S,
class T>
412 bool dimension2d<T>::operator==(
const vector2d<T>& other)
const {
return Width == other.X && Height == other.Y; }
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
dimension2d()
Default constructor for empty dimension.
Definition dimension2d.hpp:24
2d vector template class with lots of operators and methods.
Definition vector2d.hpp:22
vector2d(T nx, T ny)
Constructor with two different values.
Definition vector2d.hpp:27
T getLengthSQ() const
Get the squared length of this vector.
Definition vector2d.hpp:130
vector2d< T > getInterpolated(const vector2d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector2d.hpp:312
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.hpp:324
vector2d()
Default constructor (null vector)
Definition vector2d.hpp:25
T Y
Y coordinate of vector.
Definition vector2d.hpp:395
vector2d< T > & normalize()
Normalize the vector.
Definition vector2d.hpp:195
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.hpp:176
bool areClockwise(const vector2d< T > &b, const vector2d< T > &c) const
Definition vector2d.hpp:361
bool operator>(const vector2d< T > &other) const
sort in order X, Y. Difference must be above rounding tolerance.
Definition vector2d.hpp:99
f64 getAngleWith(const vector2d< T > &b) const
Calculates the angle between this vector and another one in degree.
Definition vector2d.hpp:263
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.hpp:284
bool areCounterClockwise(const vector2d< T > &b, const vector2d< T > &c) const
Definition vector2d.hpp:370
s32 checkOrientation(const vector2d< T > &b, const vector2d< T > &c) const
Definition vector2d.hpp:341
bool operator<(const vector2d< T > &other) const
sort in order X, Y. Difference must be above rounding tolerance.
Definition vector2d.hpp:92
bool operator>=(const vector2d< T > &other) const
sort in order X, Y. Equality with rounding tolerance.
Definition vector2d.hpp:85
T getDistanceFromSQ(const vector2d< T > &other) const
Returns squared distance from another point.
Definition vector2d.hpp:167
T getDistanceFrom(const vector2d< T > &other) const
Gets distance from another point.
Definition vector2d.hpp:158
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.hpp:384
T getLength() const
Gets the length of the vector.
Definition vector2d.hpp:125
T dotProduct(const vector2d< T > &other) const
Get the dot product of this vector with another.
Definition vector2d.hpp:135
vector2d(T n)
Constructor with the same value for both members.
Definition vector2d.hpp:29
f64 getAngleTrig() const
Calculates the angle of this vector in degrees in the trigonometric sense.
Definition vector2d.hpp:210
f64 getAngle() const
Calculates the angle of this vector in degrees in the counter trigonometric sense.
Definition vector2d.hpp:233
T X
X coordinate of vector.
Definition vector2d.hpp:392
bool equals(const vector2d< T > &other, const T tolerance=(T) ROUNDING_ERROR_f32) const
Checks if this vector equals the other one.
Definition vector2d.hpp:115
bool nearlyParallel(const vector2d< T > &other, const T factor=relativeErrorFactor< T >()) const
check if this vector is parallel to another vector
Definition vector2d.hpp:141
bool equalsRelative(const T a, const T b, const T factor=relativeErrorFactor< T >())
Definition irrMath.hpp:252
const f64 RADTODEG64
64bit constant for converting from radians to degrees
Definition irrMath.hpp:81
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
const f64 DEGTORAD64
64bit constant for converting from degrees to radians (formally known as GRAD_PI2)
Definition irrMath.hpp:78
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.hpp:243
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
double f64
64 bit floating point variable.
Definition irrTypes.hpp:114
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110