Vector

N-Dimensional Vector over a FloatPoint type, where N must be 2,3 or 4

public
struct Vector (
T
size_t dim_
) if (
__traits(isFloating, T)
) {}

Constructors

this
this(T x, T y, T z, T w)

Build a new Vector from a set of initial values If no there values for z and w, will be set to 0

this
this(T[] xs)

Build a new Vector from a array If no there values for y and z, will be set to 0. w sill beset to 1

Members

Functions

approxEqual
bool approxEqual(Vector rhs, T maxRelDiff, T maxAbsDiff)

Approximated equality with controlable precision

distance
T distance(Vector b)

Calculate the distance between two points pointed by this vector and other Params : b = Vector B Returns : Distance between the point pointed by this vector and other point

normalize
void normalize()

Normalize this vector

opBinary
Vector opBinary(Vector rhs)

Define binary operator + and -

opBinary
Vector opBinary(T rhs)

Define Scalar multiplication

opBinary
T opBinary(Vector rhs)

Define Dot Product

opBinary
Vector opBinary(Vector rhs)

Define Cross Product for R3 (operation c = a & b )

opBinaryRight
Vector opBinaryRight(T rhs)

Define Scalar multiplication

opCast
Tout opCast()

Casting method to convert to other vector types

opEquals
bool opEquals(Vector rhs)

Define Equality

opIndex
T opIndex(size_t i)

Returns i coord of this vector

opIndexAssign
void opIndexAssign(T c, size_t i)

Assigns a value to a i coord

opUnary
Vector opUnary()

Define unary operators + and -

projectOnTo
Vector projectOnTo(Vector b)

Obtains the projection of this vector over other vector

rotate
Vector rotate(real angle)

Rotation in R2

sq_distance
T sq_distance(Vector b)

Calculate the squared distance between two points pointed by this vector and other Params : b = Vector B Returns : Squared distance between the point pointed by this vector and other point

toString
string toString()

Returns a string representation of this vector

Properties

isFinite
bool isFinite [@property getter]

Checks that the vector have finite values Returns : True if this vector have finite values (not infinite value or NaNs)

isOk
bool isOk [@property getter]

Checks that the vector not have a weird NaN value Returns : True if this vector not have a NaN value

isUnit
bool isUnit [@property getter]

It's a unitary vector (length == 1) Returns : True if length approxEqual to 1.0

length
T length [@property getter]

Returns the actual length of this Vector

ptr
T* ptr [@property getter]

Return a pointer of the internal array

sq_length
T sq_length [@property getter]

Returns the actual squared length of this Vector

unit
Vector unit [@property getter]

Returns the unit vector of this vector

Static functions

projectOnTo
Vector projectOnTo(Vector a, Vector b)

Obtains the projection of two vectors

Static variables

W_AXIS
enum Vector!(T, 4) W_AXIS;

W Axis in R4 (used like a scale factor with 3d Maths with 4d Matrixes)

X_AXIS
enum Vector!(T, 2) X_AXIS;

X Axis in R2

X_AXIS
enum Vector!(T, 3) X_AXIS;

X Axis in R3

X_AXIS
enum Vector!(T, 4) X_AXIS;

X Axis in R4

Y_AXIS
enum Vector!(T, 2) Y_AXIS;

Y Axis in R2

Y_AXIS
enum Vector!(T, 3) Y_AXIS;

Y Axis in R3

Y_AXIS
enum Vector!(T, 4) Y_AXIS;

Y Axis in R4

ZERO
enum Vector!(T, 2) ZERO;

Origin

ZERO
enum Vector!(T, 3) ZERO;

Origin

ZERO
enum Vector!(T, 4) ZERO;

Origin

Z_AXIS
enum Vector!(T, 3) Z_AXIS;

Z Axis in R3

Z_AXIS
enum Vector!(T, 4) Z_AXIS;

Z Axis in R4

dim
enum size_t dim;

Vector Dimension

Unions

__anonymous
union __anonymous
Undocumented in source.

Meta