1 /** 2 inmath.util 3 4 Authors: David Herberth, Inochi2D Project 5 License: MIT 6 */ 7 module inmath.util; 8 9 private { 10 import inmath.linalg : Vector, Matrix, Quaternion, Rect; 11 import inmath.plane : PlaneT; 12 13 static import std.compiler; 14 15 } 16 17 static if (std.compiler.version_major > 2 || 18 std.compiler.version_minor > 68) 19 { 20 private import std.meta : AliasSeq; 21 public alias TypeTuple = AliasSeq; 22 } else { 23 public import std.typetuple : TypeTuple; 24 } 25 26 /// If T is a vector, this evaluates to true, otherwise false. 27 enum isVector(T) = is(T : Vector!U, U...); 28 29 /// If T is a matrix, this evaluates to true, otherwise false. 30 enum isMatrix(T) = is(T : Matrix!U, U...); 31 32 /// If T is a quaternion, this evaluates to true, otherwise false. 33 enum isQuaternion(T) = is(T : Quaternion!U, U...); 34 35 /// If T is a rect, this evaluates to true, otherwise false. 36 enum isRect(T) = is(T : Rect!U, U...); 37 38 /// If T is a plane, this evaluates to true, otherwise false. 39 enum isPlane(T) = is(T : PlaneT!U, U...); 40 41 42 unittest { 43 // I need to import it here like this, otherwise you'll get a compiler 44 // or a linker error depending where inmath.util gets imported 45 import inmath.linalg; 46 import inmath.plane; 47 48 assert(isVector!vec2); 49 assert(isVector!vec3); 50 assert(isVector!vec3d); 51 assert(isVector!vec4i); 52 assert(!isVector!int); 53 assert(!isVector!mat34); 54 assert(!isVector!quat); 55 56 assert(isMatrix!mat2); 57 assert(isMatrix!mat34); 58 assert(isMatrix!mat4); 59 assert(!isMatrix!float); 60 assert(!isMatrix!vec3); 61 assert(!isMatrix!quat); 62 63 assert(isQuaternion!quat); 64 assert(!isQuaternion!vec2); 65 assert(!isQuaternion!vec4i); 66 assert(!isQuaternion!mat2); 67 assert(!isQuaternion!mat34); 68 assert(!isQuaternion!float); 69 70 assert(isPlane!Plane); 71 assert(!isPlane!vec2); 72 assert(!isPlane!quat); 73 assert(!isPlane!mat4); 74 assert(!isPlane!float); 75 } 76 77 template TupleRange(int from, int to) if (from <= to) { 78 static if (from >= to) { 79 alias TupleRange = TypeTuple!(); 80 } else { 81 alias TupleRange = TypeTuple!(from, TupleRange!(from + 1, to)); 82 } 83 }