Vec

Generic struct that represents a vector holding size elements of type T. A vector must contain at least 1 element, and has no upper-bound on the size beyond restrictions imposed by the system.

Constructors

this
this(T[size] elements)

Constructs a vector from an array of elements.

this
this(T[] elements)

Constructs a vector from a variadic list of elements.

this
this(T value)

Constructs a vector where all elements have the given value.

this
this(MY_TYPE other)

Constructs a vector as a copy of the other.

Members

Functions

add
MY_TYPE add(Vec!(V, size) other)

Adds the given vector to this one.

copy
MY_TYPE copy()

Gets a copy of this vector.

cross
MY_TYPE cross(MY_TYPE other)

Computes the cross product of this vector and another, and stores the result in this vector.

div
MY_TYPE div(V factor)

Divides this vector by a factor, element-wise.

div
MY_TYPE div(Vec!(V, size) other)

Divides this vector by another vector, element-wise.

dot
T dot(MY_TYPE other)

Determines the dot product of this vector and another vector.

mag
double mag()

Determines the magnitude of this vector.

mag2
double mag2()

Determines the squared magnitude of this vector.

mul
MY_TYPE mul(V factor)

Multiplies this vector by a factor, element-wise.

mul
MY_TYPE mul(Vec!(V, size) other)

Multiplies this vector by another vector, element-wise.

norm
MY_TYPE norm()

Normalizes this vector, such that it will have a magnitude of 1.

opBinary
MY_TYPE opBinary(Vec!(V, size) other)

Adds two vectors.

opBinary
MY_TYPE opBinary(V scalar)

Adds a scalar value to a vector, element-wise.

opBinary
MY_TYPE opBinary(Vec!(V, size) other)

Subtracts two vectors.

opBinary
MY_TYPE opBinary(V factor)

Multiplies a vector by a factor.

opBinary
MY_TYPE opBinary(V factor)

Divides a vector by a factor.

opCmp
int opCmp(MY_TYPE other)

Compares this vector to another, based on their magnitudes.

opIndex
T opIndex(size_t i)

Gets the element at a specified index.

opIndexAssign
void opIndexAssign(T value, size_t i)

Inserts an element at the specified index.

opOpAssign
MY_TYPE opOpAssign(Vec!(V, size) other)

Adds a vector to this one.

opOpAssign
MY_TYPE opOpAssign(V scalar)

Adds a scalar value to this vector.

opOpAssign
MY_TYPE opOpAssign(Vec!(V, size) other)

Subtracts a vector from this one.

opOpAssign
MY_TYPE opOpAssign(V factor)

Multiplies this vector by a factor.

opOpAssign
MY_TYPE opOpAssign(V factor)

Divides this vector by a factor.

sub
MY_TYPE sub(Vec!(V, size) other)

Subtracts the given vector from this one.

toCartesian
MY_TYPE toCartesian()

Converts this 2-dimensional vector from Polar to Cartesian coordinates. It is assumed that the first element is the **radius** and the second element is the angle **theta**. The first element becomes the **x** coordinate, and the second becomes the **y** coordinate.

toPolar
MY_TYPE toPolar()

Converts this 2-dimensional vector from Cartesian to Polar coordinates. It is assumed that the first element is the **x** coordinate, and the second element is the **y** coordinate. The first element becomes the **radius** and the second becomes the angle **theta**.

toString
string toString()

Gets a simple string representation of this vector.

Static functions

empty
MY_TYPE empty()

Constructs a vector containing all 0's.

sum
MY_TYPE sum(MY_TYPE[] vectors)

Computes the sum of a given array of vectors.

Static variables

SIZE
size_t SIZE;

A static contstant that can be used to get the size of the vector.

Variables

data
T[size] data;

The internal static array storing the elements of this vector.

Meta