1 /** 2 gl3n.util 3 4 Authors: David Herberth 5 License: MIT 6 */ 7 8 module gl3n.util; 9 10 private { 11 import gl3n.linalg : Vector, Matrix, Quaternion; 12 import gl3n.plane : PlaneT; 13 14 static import std.compiler; 15 16 static if (std.compiler.version_major > 2 || 17 std.compiler.version_minor > 68) 18 { 19 import std.meta : AliasSeq; 20 alias TypeTuple = AliasSeq; 21 } 22 else { 23 import std.typetuple : TypeTuple; 24 } 25 } 26 27 private void is_vector_impl(T, int d)(Vector!(T, d) vec) {} 28 29 /// If T is a vector, this evaluates to true, otherwise false. 30 template is_vector(T) { 31 enum is_vector = is(typeof(is_vector_impl(T.init))); 32 } 33 34 private void is_matrix_impl(T, int r, int c)(Matrix!(T, r, c) mat) {} 35 36 /// If T is a matrix, this evaluates to true, otherwise false. 37 template is_matrix(T) { 38 enum is_matrix = is(typeof(is_matrix_impl(T.init))); 39 } 40 41 private void is_quaternion_impl(T)(Quaternion!(T) qu) {} 42 43 /// If T is a quaternion, this evaluates to true, otherwise false. 44 template is_quaternion(T) { 45 enum is_quaternion = is(typeof(is_quaternion_impl(T.init))); 46 } 47 48 private void is_plane_impl(T)(PlaneT!(T) p) {} 49 50 /// If T is a plane, this evaluates to true, otherwise false. 51 template is_plane(T) { 52 enum is_plane = is(typeof(is_plane_impl(T.init))); 53 } 54 55 56 unittest { 57 // I need to import it here like this, otherwise you'll get a compiler 58 // or a linker error depending where gl3n.util gets imported 59 import gl3n.linalg; 60 import gl3n.plane; 61 62 assert(is_vector!vec2); 63 assert(is_vector!vec3); 64 assert(is_vector!vec3d); 65 assert(is_vector!vec4i); 66 assert(!is_vector!int); 67 assert(!is_vector!mat34); 68 assert(!is_vector!quat); 69 70 assert(is_matrix!mat2); 71 assert(is_matrix!mat34); 72 assert(is_matrix!mat4); 73 assert(!is_matrix!float); 74 assert(!is_matrix!vec3); 75 assert(!is_matrix!quat); 76 77 assert(is_quaternion!quat); 78 assert(!is_quaternion!vec2); 79 assert(!is_quaternion!vec4i); 80 assert(!is_quaternion!mat2); 81 assert(!is_quaternion!mat34); 82 assert(!is_quaternion!float); 83 84 assert(is_plane!Plane); 85 assert(!is_plane!vec2); 86 assert(!is_plane!quat); 87 assert(!is_plane!mat4); 88 assert(!is_plane!float); 89 } 90 91 template TupleRange(int from, int to) if (from <= to) { 92 static if (from >= to) { 93 alias TupleRange = TypeTuple!(); 94 } else { 95 alias TupleRange = TypeTuple!(from, TupleRange!(from + 1, to)); 96 } 97 }