Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::core::vector2d< T > Class Template Reference

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

#include <nirtcpp/core/engine/vector2d.hpp>

Public Member Functions

 vector2d ()
 Default constructor (null vector)
 
 vector2d (T nx, T ny)
 Constructor with two different values.
 
 vector2d (T n)
 Constructor with the same value for both members.
 
 vector2d (const dimension2d< T > &other)
 
vector2d< Toperator- () const
 
vector2d< T > & operator= (const dimension2d< T > &other)
 
vector2d< Toperator+ (const vector2d< T > &other) const
 
vector2d< Toperator+ (const dimension2d< T > &other) const
 
vector2d< T > & operator+= (const vector2d< T > &other)
 
vector2d< Toperator+ (const T v) const
 
vector2d< T > & operator+= (const T v)
 
vector2d< T > & operator+= (const dimension2d< T > &other)
 
vector2d< Toperator- (const vector2d< T > &other) const
 
vector2d< Toperator- (const dimension2d< T > &other) const
 
vector2d< T > & operator-= (const vector2d< T > &other)
 
vector2d< Toperator- (const T v) const
 
vector2d< T > & operator-= (const T v)
 
vector2d< T > & operator-= (const dimension2d< T > &other)
 
vector2d< Toperator* (const vector2d< T > &other) const
 
vector2d< T > & operator*= (const vector2d< T > &other)
 
vector2d< Toperator* (const T v) const
 
vector2d< T > & operator*= (const T v)
 
vector2d< Toperator/ (const vector2d< T > &other) const
 
vector2d< T > & operator/= (const vector2d< T > &other)
 
vector2d< Toperator/ (const T v) const
 
vector2d< T > & operator/= (const T v)
 
Toperator[] (u32 index)
 
const Toperator[] (u32 index) const
 
bool operator<= (const vector2d< T > &other) const
 sort in order X, Y. Equality with rounding tolerance.
 
bool operator>= (const vector2d< T > &other) const
 sort in order X, Y. Equality with rounding tolerance.
 
bool operator< (const vector2d< T > &other) const
 sort in order X, Y. Difference must be above rounding tolerance.
 
bool operator> (const vector2d< T > &other) const
 sort in order X, Y. Difference must be above rounding tolerance.
 
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.
 
vector2d< T > & set (T nx, T ny)
 
vector2d< T > & set (const vector2d< T > &p)
 
T getLength () const
 Gets the length of the vector.
 
T getLengthSQ () const
 Get the squared length of this vector.
 
T dotProduct (const vector2d< T > &other) const
 Get the dot product of this vector with another.
 
bool nearlyParallel (const vector2d< T > &other, const T factor=relativeErrorFactor< T >()) const
 check if this vector is parallel to another vector
 
T getDistanceFrom (const vector2d< T > &other) const
 Gets distance from another point.
 
T getDistanceFromSQ (const vector2d< T > &other) const
 Returns squared distance from another point.
 
vector2d< T > & rotateBy (f64 degrees, const vector2d< T > &center=vector2d< T >())
 rotates the point anticlockwise around a center by an amount of degrees.
 
vector2d< T > & normalize ()
 Normalize the vector.
 
f64 getAngleTrig () const
 Calculates the angle of this vector in degrees in the trigonometric sense.
 
f64 getAngle () const
 Calculates the angle of this vector in degrees in the counter trigonometric sense.
 
f64 getAngleWith (const vector2d< T > &b) const
 Calculates the angle between this vector and another one in degree.
 
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.
 
vector2d< TgetInterpolated (const vector2d< T > &other, f64 d) const
 Creates an interpolated vector between this vector and another vector.
 
vector2d< TgetInterpolated_quadratic (const vector2d< T > &v2, const vector2d< T > &v3, f64 d) const
 Creates a quadratically interpolated vector between this and two other vectors.
 
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.
 

Public Attributes

T X
 X coordinate of vector.
 
T Y
 Y coordinate of vector.
 

Detailed Description

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

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

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

Member Function Documentation

◆ areClockwise()

template<class T >
bool nirt::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

◆ areCounterClockwise()

template<class T >
bool nirt::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

◆ checkOrientation()

template<class T >
s32 nirt::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

◆ dotProduct()

template<class T >
T nirt::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.

◆ equals()

template<class T >
bool nirt::core::vector2d< T >::equals ( const vector2d< T > &  other,
const T  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.

◆ getAngle()

template<class T >
f64 nirt::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.

◆ getAngleTrig()

template<class T >
f64 nirt::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.

◆ getAngleWith()

template<class T >
f64 nirt::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.

◆ getDistanceFrom()

template<class T >
T nirt::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.

◆ getDistanceFromSQ()

template<class T >
T nirt::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.

◆ getInterpolated()

template<class T >
vector2d< T > nirt::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.

◆ getInterpolated_quadratic()

template<class T >
vector2d< T > nirt::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.

◆ getLength()

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

Gets the length of the vector.

Returns
The length of the vector.

◆ getLengthSQ()

template<class T >
T nirt::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.

◆ interpolate()

template<class T >
vector2d< T > & nirt::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()

◆ isBetweenPoints()

template<class T >
bool nirt::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.

◆ normalize()

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

Normalize the vector.

The null vector is left untouched.

Returns
Reference to this vector, after normalization.

◆ rotateBy()

template<class T >
vector2d< T > & nirt::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.

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

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print