mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added Matrix identity macros and few matrix unit tests (#742)
* Add matrix identity macros * Add matrix some matrix unit tests --------- Co-authored-by: Tonis <tanton@paysure.solutions>
This commit is contained in:
@@ -105,6 +105,9 @@ define matrix4_ortho = matrix::ortho<double>;
|
||||
define matrix4_perspective = matrix::perspective<double>;
|
||||
define matrix4f_ortho = matrix::ortho<float>;
|
||||
define matrix4f_perspective = matrix::perspective<float>;
|
||||
macro Matrix4 matrix4_indentity() => { .m = { [0] = 1, [5] = 1, [10] = 1, [15] = 1 } };
|
||||
macro Matrix3 matrix3_indentity() => { .m = { [0] = 1, [4] = 1, [8] = 1 } };
|
||||
macro Matrix2 matrix2_indentity() => { .m = { [0] = 1, [3] = 1 } };
|
||||
|
||||
/**
|
||||
* @require types::is_numerical($typeof(x)) `The input must be a numerical value or numerical vector`
|
||||
|
||||
50
test/unit/stdlib/math/matrix.c3
Normal file
50
test/unit/stdlib/math/matrix.c3
Normal file
@@ -0,0 +1,50 @@
|
||||
module math_matrix @test;
|
||||
import std::math;
|
||||
|
||||
fn void test_mat4()
|
||||
{
|
||||
{|
|
||||
Matrix4 mat = math::matrix4_indentity();
|
||||
Matrix4 mat2 = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
||||
Matrix4 calc = mat.mul(mat2);
|
||||
assert(calc.m == mat.m);
|
||||
|
||||
Matrix4 translated = mat.translate(Vec3{0.0, 0.0, 0.0});
|
||||
assert(translated.m == mat.m);
|
||||
|};
|
||||
|
||||
{|
|
||||
Matrix4 mat = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
Matrix4 mat2 = { 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
Matrix4 calc = mat.mul(mat2);
|
||||
Matrix4 value = { 56, 46, 36, 26, 152, 126, 100, 74, 56, 46, 36, 26, 152, 126, 100, 74 };
|
||||
assert(calc.m == value.m);
|
||||
|};
|
||||
}
|
||||
|
||||
|
||||
fn void test_mat3()
|
||||
{
|
||||
Matrix3 mat = { 3, 5, 3, 5, 2, 6, 6, 2, 1 };
|
||||
Matrix3 mat2 = { 4, 2, 6, 7, 8, 9, 2, 3, 4 };
|
||||
Matrix3 calc = mat.mul(mat2);
|
||||
Matrix3 value = { 53, 55, 75, 46, 44, 72, 40, 31, 58 };
|
||||
|
||||
assert(calc.m == value.m);
|
||||
}
|
||||
|
||||
fn void test_mat2()
|
||||
{
|
||||
Matrix2 mat = { 3, 5, 5, 2};
|
||||
Matrix2 mat2 = { 4, 2, 7, 8 };
|
||||
Matrix2 calc = mat.mul(mat2);
|
||||
Matrix2 value = { 47, 46, 34, 26 };
|
||||
|
||||
assert(calc.m == value.m);
|
||||
}
|
||||
|
||||
fn void test_vec3()
|
||||
{
|
||||
Vec3 cross = Vec3{2,3,4}.cross(Vec3{5,6,7});
|
||||
assert(cross == Vec3{-3,6,-3});
|
||||
}
|
||||
Reference in New Issue
Block a user