5#include "testing/testing.h"
12using namespace blender::math;
14TEST(math_matrix_types, DefaultConstructor)
23TEST(math_matrix_types, StaticConstructor)
50TEST(math_matrix_types, VectorConstructor)
52 float3x2 m({1.0f, 2.0f}, {3.0f, 4.0f}, {5.0f, 6.0f});
61TEST(math_matrix_types, SmallerMatrixConstructor)
63 float2x2 m2({1.0f, 2.0f}, {3.0f, 4.0f});
76TEST(math_matrix_types, ComponentMasking)
78 float3x3 m3({1.1f, 1.2f, 1.3f}, {2.1f, 2.2f, 2.3f}, {3.1f, 3.2f, 3.3f});
86TEST(math_matrix_types, PointerConversion)
88 float array[4] = {1.0f, 2.0f, 3.0f, 4.0f};
96TEST(math_matrix_types, TypeConversion)
115TEST(math_matrix_types, PointerArrayConversion)
117 float array[2][2] = {{1.0f, 2.0f}, {3.0f, 4.0f}};
126TEST(math_matrix_types, ComponentAccess)
128 float3x3 m3({1.1f, 1.2f, 1.3f}, {2.1f, 2.2f, 2.3f}, {3.1f, 3.2f, 3.3f});
135TEST(math_matrix_types, AddOperator)
137 float3x3 m3({1.1f, 1.2f, 1.3f}, {2.1f, 2.2f, 2.3f}, {3.1f, 3.2f, 3.3f});
170TEST(math_matrix_types, SubtractOperator)
172 float3x3 m3({10.0f, 10.2f, 10.3f}, {20.1f, 20.2f, 20.3f}, {30.1f, 30.2f, 30.3f});
205TEST(math_matrix_types, MultiplyOperator)
222TEST(math_matrix_types, MatrixMultiplyOperator)
275TEST(math_matrix_types, VectorMultiplyOperator)
289TEST(math_matrix_types, ViewConstructor)
292 float4(1, 2, 3, 4),
float4(5, 6, 7, 8),
float4(9, 10, 11, 12),
float4(13, 14, 15, 16));
307TEST(math_matrix_types, ViewFromCstyleMatrix)
309 float c_style_mat[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
314 float4x4 expect =
float4x4({2, 4, 6, 8}, {10, 12, 14, 16}, {18, 20, 22, 24}, {26, 28, 30, 32});
317 EXPECT_M4_NEAR(expect, mat, 1e-8f);
320 EXPECT_M4_NEAR(expect, c_mat_mutable_view, 1e-8f);
323TEST(math_matrix_types, ViewAssignment)
326 float4(1, 2, 3, 4),
float4(5, 6, 7, 8),
float4(9, 10, 11, 12),
float4(13, 14, 15, 16));
330 float4x4 expect =
float4x4({1, 2, 3, 4}, {5, -1, -2, 8}, {9, -3, -4, 12}, {13, 14, 15, 16});
331 EXPECT_M4_NEAR(expect, mat, 1e-8f);
334 mat.
view<2, 2, 2, 2>() = mat.
view<2, 2, 0, 0>();
335 float4x4 expect2 =
float4x4({1, 2, 3, 4}, {5, -1, -2, 8}, {9, -3, 1, 2}, {13, 14, 5, -1});
336 EXPECT_M4_NEAR(expect2, mat, 1e-8f);
338 mat.
view<2, 2, 0, 0>() = mat.
view<2, 2, 1, 1>();
339 float4x4 expect3 =
float4x4({-1, -2, 3, 4}, {-3, 1, -2, 8}, {9, -3, 1, 2}, {13, 14, 5, -1});
340 EXPECT_M4_NEAR(expect3, mat, 1e-8f);
350TEST(math_matrix_types, ViewScalarOperators)
352 float4x4 mat =
float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});
379 float4x4 expect =
float4x4({1, 2, 3, 4}, {5, 20, 24, 8}, {9, 36, 40, 12}, {13, 14, 15, 16});
380 EXPECT_M4_NEAR(expect, mat, 1e-8f);
389TEST(math_matrix_types, ViewMatrixMultiplyOperator)
391 float4x4 mat =
float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});
408TEST(math_matrix_types, ViewVectorMultiplyOperator)
410 float4x4 mat =
float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});
423TEST(math_matrix_types, ViewMatrixNormalize)
425 float4x4 mat =
float4x4({1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16});
429 {0.476731300, 0.572077572, 0.66742378, 8},
430 {0.517891824, 0.575435340, 0.63297885, 12},
432 EXPECT_M4_NEAR(expect, mat, 1e-8f);
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
VecBase< float, D > normalize(VecOp< float, D >) RET
MatBase< float, 2, 2 > float2x2
MatBase< float, 2, 3 > float2x3
MatBase< float, 4, 4 > float4x4
MatBase< float, 2, 4 > float2x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 4 > float4
MatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_view
VecBase< float, 2 > float2
MatBase< float, 3, 2 > float3x2
MatBase< float, 3, 3 > float3x3
MutableMatView< float, 4, 4, 4, 4, 0, 0, alignof(float)> float4x4_mutableview
MatBase< double, 3, 2 > double3x2
VecBase< float, 3 > float3
static MatBase diagonal(float value)
const MatView< T, ViewNumCol, ViewNumRow, NumCol, NumRow, SrcStartCol, SrcStartRow, Alignment > view() const
static MatBase all(float value)
static MatBase identity()