1 // Copyright Ferdinand Majerech 2014. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 7 /// Functionality extending gl3n.linalg 8 module gl3n_extra.linalg; 9 10 public import gl3n.linalg; 11 12 13 /// Readability shortcuts. 14 alias Vector!(uint, 2) vec2u; 15 alias Vector!(uint, 3) vec3u; 16 alias Vector!(uint, 4) vec4u; 17 alias Vector!(ubyte, 2) vec2ub; 18 alias Vector!(ubyte, 3) vec3ub; 19 alias Vector!(ubyte, 4) vec4ub; 20 alias Matrix!(float, 3, 2) mat32; 21 alias Matrix!(float, 4, 2) mat42; 22 alias Matrix!(float, 2, 3) mat23; 23 alias Matrix!(float, 4, 3) mat43; 24 alias Matrix!(float, 2, 4) mat24; 25 alias Matrix!(double, 2, 2) mat2d; 26 alias Matrix!(double, 3, 3) mat3d; 27 alias Matrix!(double, 4, 4) mat4d; 28 alias Matrix!(double, 3, 2) mat32d; 29 alias Matrix!(double, 4, 2) mat42d; 30 alias Matrix!(double, 2, 3) mat23d; 31 alias Matrix!(double, 4, 3) mat43d; 32 alias Matrix!(double, 2, 4) mat24d; 33 alias Matrix!(double, 3, 4) mat34d; 34 35 // Called setLength() because length() doesn't seem to work correctly with UFCS. 36 /// Set length of the vector, resizing it but preserving its direction. 37 void setLength(T, size_t dim)(ref Vector!(T, dim) vector, T length) @safe pure nothrow @nogc 38 { 39 const oldLength = vector.length; 40 assert(oldLength != 0.0f, "Cannot set length of a zero vector!"); 41 const ratio = length / oldLength; 42 vector *= ratio; 43 }