Vector

Vector structure with data accesible with [N] or swizzling.

All operations on Vector (*, +, /, -, etc...) are scalar.

Allows casting to sily.color or sily.matrix.

struct Vector (
T
size_t N
) if (
isNumeric!T &&
N > 0
) {}

Constructors

this
this(T val)
this(T[N] vals)

Constructs Vector from components. If no components present vector will be filled with 0

this
this(T[4] vals)

Construct euler vector from quaternion

Alias This

data

Alias to allow easy data access

Members

Aliases

VecType
alias VecType = Vector!(T, N)

Alias to vector type. Can be used to contruct vectors of same type

dataType
alias dataType = T

Alias to data type (e.g. float, int)

isNormalised
alias isNormalised = isNormalized

Returns true if vector is normalised

normalise
alias normalise = normalize

Normalises vector in place

normalised
alias normalised = normalized

Normalises vector

Functions

abs
VecType abs()

Abs vector values

angle
double angle(VecType v2)

Calculates angle between this vector and v2 from [0, 0]

angle
double angle(VecType v2)

Calculates angle between this vector and v2 from [0, 0]

angleTo
double angleTo(VecType to)

Calculates angle between line this->to and X ordinate

ceil
VecType ceil()

Ceils vector values

clamp
VecType clamp(VecType p_min, VecType p_max)

Clamps vector values

clamp
VecType clamp(T p_min, T p_max)

Clamps vector values

clamped
VecType clamped(VecType p_min, VecType p_max)

Clamps vector values in place

clamped
VecType clamped(T p_min, T p_max)

Clamps vector values in place

copyof
VecType copyof()

Returns copy of vector

cross
double cross(VecType b)

Calculates cross product of this and b, assumes that Z = 0

cross
VecType cross(VecType b)

Calculates cross product of this and b

cross
VecType cross(VecType b)

Calculates cross product of this and b, W is multiplication of a.w and b.w

distanceSquaredTo
T distanceSquaredTo(VecType b)

Returns squared distance from vector to b

distanceTo
double distanceTo(VecType b)

Calculates distance to vector b

dot
double dot(VecType b)

Performs dot product

floor
VecType floor()

Floors vector values

isClose
bool isClose(VecType v)

Is vector approximately close to v

isNormalized
bool isNormalized()

Returns true if vector is normalised

length
double length()

Returns vector length

lengthSquared
T lengthSquared()

Returns squared vector length

lerp
VecType lerp(VecType to, double weight)

Linear interpolates vector

limitLength
VecType limitLength(double p_min, double p_max)

Limits length of vector and returns resulting vector

max
VecType max(VecType b)

Clamps vector values to max

min
VecType min(VecType b)

Clamps vector values to min

moveTowards
VecType moveTowards(VecType to, double maxDist)

Moves vector toward target

normalize
VecType normalize()

Normalises vector in place

normalized
VecType normalized()

Normalises vector

opBinary
VecType opBinary(Vector!(R, N) b)
VecType opBinary(R b)
opBinaryRight
VecType opBinaryRight(Vector!(R, N) b)
VecType opBinaryRight(R b)

opBinary x [+, -, *, /, %] y

opCast
R opCast()

opCast cast(x) y

opCast
R opCast()

Cast to matrix (column/row matrix)

opCast
Color opCast()

Cast to color

opCast
bool opCast()

Cast to bool

opCmp
int opCmp(Vector!(R, N) b)

opCmp x [< > <= >=] y

opEquals
bool opEquals(Vector!(R, size) b)

opEquals x == y

opOpAssign
VecType opOpAssign(Vector!(R, N) b)
VecType opOpAssign(R b)

opOpAssign x [+, -, *, /, %]= y

opUnary
VecType opUnary()

opUnary [-, +, --, ++] x

opUnary
VecType opUnary()
dvec!N opUnary()

Invert vector

perpendicular
VecType perpendicular()

Returns vector perpendicular to this

ptr
T* ptr()

Returns pointer to data

reflect
VecType reflect(VecType normal)

Calculates reflected vector to normal

refract
VecType refract(VecType n, double r)

Calculates direction of refracted ray where this is incoming ray, n is normal vector and r is refractive ratio

rotate
VecType rotate(double angle)

Rotates vector by angle

round
VecType round()

Rounds vector values

sign
VecType sign()

Signs current vector

snap
VecType snap(VecType p_step)

Snaps vector values

snap
VecType snap(T p_step)

Snaps vector values

snapped
VecType snapped(VecType p_step)

Snaps vector values in place

snapped
VecType snapped(T p_step)

Snaps vector values in place

toHash
size_t toHash()

Returns hash

toString
string toString()

Returns string representation of vector: [1.00, 1.00,... , 1.00]

unproject
VecType unproject(mat4 proj, mat4 view)

Projects vector3 from screen space into object space

Mixins

__anonymous
mixin accessByString!(T, N, "data", AS)

Mixes in swizzle

Variables

data
T[N] data;

Vector data

size
enum size_t size;

Alias to vector size

Mixed In Members

From mixin accessByString!(T, N, "data", AS)

opDispatch
T opDispatch [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
T opDispatch [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
auto opDispatch [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
U opDispatch [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.

Meta