Generic 1D small vector.
N | number of elements |
T | type of elements |
Assign a Vector from a compatible type.
Assign a Vector with a static array type.
Assign with a dynamic array.
Size is checked in debug-mode.
Assign from a samey Vector.
Assign from other vectors types (same size, compatible type).
Converts to a pretty string.
Implements swizzling.
vec4i vi = [4, 1, 83, 10];
assert(vi.zxxyw == [83, 4, 4, 1, 10]);
Support swizzling assignment like in shader languages.
vec3f v = [0, 1, 2];
v.yz = v.zx;
assert(v == [0, 2, 0]);
Casting to small vectors of the same size.
vec4f vf;
vec4d vd = cast!(vec4d)vf;
Implement slices operator overloading.
Allows to go back to slice world.
Faster but less accurate inverse of Euclidean length.
In-place normalization.
Faster but less accurate in-place normalization.
Faster but less accurate vector normalization.
Gets an orthogonal vector from a 3-dimensional vector.
Doesn’t normalize the output.
True if
Tis some kind of
Vector
Get the numeric type used to measure a vectors's coordinates.
static assert(is(DimensionType!vec2f == float)); static assert(is(DimensionType!vec3d == double));
Element-wise minimum.
Element-wise maximum.
3D reflect, like the GLSL function.
// reflect a 2D vector across the x axis (the normal points along the y axis) assert(vec2f(1,1).reflect(vec2f(0,1)) == vec2f(1,-1)); assert(vec2f(1,1).reflect(vec2f(0,-1)) == vec2f(1,-1)); // note that the normal must be, well, normalized: assert(vec2f(1,1).reflect(vec2f(0,20)) != vec2f(1,-1)); // think of this like a ball hitting a flat floor at an angle. // the x and y components remain unchanged, and the z inverts assert(vec3f(2,3,-0.5).reflect(vec3f(0,0,1)) == vec3f(2,3,0.5));