1 module polyplex.math.simplemath; 2 3 public import polyplex.math.simplemath.vectors; 4 public import polyplex.math.simplemath.matrix2x2; 5 public import polyplex.math.simplemath.matrix3x3; 6 public import polyplex.math.simplemath.matrix4x4; 7 public import polyplex.math.simplemath.quaternion; 8 public import polyplex.math.simplemath.transform; 9 10 // Unit tests 11 unittest { 12 // ================ Vectors =================== 13 14 // Test IsVector 15 assert(IsVector!(Vector2)); 16 assert(IsVector!(Vector2i)); 17 assert(IsVector!(Vector3)); 18 assert(IsVector!(Vector3i)); 19 assert(IsVector!(Vector4)); 20 assert(IsVector!(Vector4i)); 21 assert(!IsVector!(float)); 22 23 // ================ Vector2 =================== 24 25 // Test IsVector2T 26 assert(IsVector2T!(Vector2)); 27 assert(IsVector2T!(Vector2i)); 28 29 assert(!IsVector2T!(Vector4)); 30 assert(!IsVector2T!(float)); 31 assert(!IsVector2T!(string)); 32 33 // Test Construct 34 assert(Vector2(1) == Vector2(1, 1)); 35 assert(Vector2(1, 0) == Vector2(1, 0)); 36 37 // Test Add 38 assert((Vector2(1)+Vector2(2, 3)) == Vector2(3, 4)); 39 assert((Vector2(1)+Vector2(2, 32)) != Vector2(3, 4)); 40 41 // Test Subtract 42 assert((Vector2(32)-Vector2(1, 1)) == Vector2(31, 31)); 43 assert((Vector2(32)-Vector2(0, 0)) != Vector2(31, 31)); 44 45 // ================ Vector3 =================== 46 47 // Test IsVector2T 48 assert(IsVector3T!(Vector3)); 49 assert(IsVector3T!(Vector3i)); 50 51 // ================ Vector4 =================== 52 53 // Test IsVector4T 54 assert(IsVector4T!(Vector4)); 55 assert(IsVector4T!(Vector4i)); 56 57 // =============== Matricies ================== 58 59 // Test Matrix4x4 60 Matrix4x4 mt4 = Matrix4x4.Identity; 61 Matrix4x4 mt4_o = Matrix4x4([ 62 [1, 0, 0, 2], 63 [0, 1, 0, 5], 64 [0, 0, 1, 3], 65 [0, 0, 0, 1] 66 ]); 67 68 Matrix4x4 orth_mat = Matrix4x4.Orthographic(-1f, 1f, -1f, 1f, -1f, 1f); 69 Matrix4x4 comp_orth = Matrix4x4([ 70 [1f, 0f, 0f, -0f], 71 [0f, 1f, 0f, -0f], 72 [0f, 0f, -1f, -0f], 73 [0f, 0f, 0f, 1f] 74 ]); 75 assert(orth_mat == comp_orth, "orth_mat != comp_orth \n" ~ orth_mat.ToString ~ ",\n" ~ comp_orth.ToString); 76 }