linalg::vec<T,M> defines a fixed-length vector containing exactly M elements of type T.
This data structure can be used to store a wide variety of types of data, including geometric vectors, points, homogeneous coordinates, plane equations, colors, texture coordinates, or any other situation where you need to manipulate a small sequence of numbers. As such, vec<T,M> is supported by a set of algebraic and component-wise functions, as well as a set of standard reductions.
vec<T,M>:
- is DefaultConstructible:
- is constructible from M elements of type T:
- is CopyConstructible and CopyAssignable:
float3 v {1,2,3};
float3 u {v};
float3 w;
w = u;
- is EqualityComparable and LessThanComparable:
if(v == y) cout << "v and u contain equal elements in the same positions" <<
endl; if(v < u) cout << "v precedes u lexicographically" << endl;
- is explicitly constructible from a single element of type T:
- is explicitly constructible from a vec<U,M> of some other type U:
float3 v {1.1f,2.3f,3.5f};
int3 u = int3{v};
- has fields x,y,z,w:
float y = point.y;
pixel.w = 0.5;
float s = tc.x;
- supports indexing:
float x = v[0];
v[2] = 5;
- supports unary operators +, -, ! and ~ in component-wise fashion:
- supports binary operators +, -, *, /, %, |, &, ^, << and >> in component-wise fashion:
auto v = float2{1,1} + float2{2,3};
- supports binary operators with a scalar on the left or the right:
auto v = 2 * float3{1,2,3};
auto u = float3{1,2,3} + 1;
- supports operators +=, -=, *=, /=, %=, |=, &=, ^=, <<= and >>= with vectors or scalars on the right:
- supports operations on mixed element types:
auto v = float3{1,2,3} + int3{4,5,6};
- supports range-based for:
for(auto elem : float3{1,2,3}) cout << elem << ' ';
- has a flat memory layout:
float3 v {1,2,3};
float * p = v.data();
p[1] = 4;