Blender  V3.3
BLI_float3x3_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 
3 #include "testing/testing.h"
4 
5 #include "BLI_float3x3.hh"
6 #include "BLI_math_base.h"
7 #include "BLI_math_vec_types.hh"
8 
9 namespace blender::tests {
10 
11 TEST(float3x3, Identity)
12 {
13  float2 point(1.0f, 2.0f);
14  float3x3 transformation = float3x3::identity();
15  float2 result = transformation * point;
17 }
18 
19 TEST(float3x3, Translation)
20 {
21  float2 point(1.0f, 2.0f);
22  float3x3 transformation = float3x3::from_translation(float2(5.0f, 3.0f));
23  float2 result = transformation * point;
24  EXPECT_FLOAT_EQ(result[0], 6.0f);
25  EXPECT_FLOAT_EQ(result[1], 5.0f);
26 }
27 
28 TEST(float3x3, Rotation)
29 {
30  float2 point(1.0f, 2.0f);
31  float3x3 transformation = float3x3::from_rotation(M_PI_2);
32  float2 result = transformation * point;
33  EXPECT_FLOAT_EQ(result[0], -2.0f);
34  EXPECT_FLOAT_EQ(result[1], 1.0f);
35 }
36 
37 TEST(float3x3, TranslationRotationScale)
38 {
39  float2 point(1.0f, 2.0f);
41  float2(1.0f, 3.0f), M_PI_2, float2(2.0f, 3.0f));
42  float2 result = transformation * point;
43  EXPECT_FLOAT_EQ(result[0], -5.0f);
44  EXPECT_FLOAT_EQ(result[1], 5.0f);
45 }
46 
47 TEST(float3x3, NormalizedAxes)
48 {
49  float2 point(1.0f, 2.0f);
50 
51  /* The horizontal is aligned with (1, 1) and vertical is aligned with (-1, 1), in other words, a
52  * Pi / 4 rotation. */
53  float value = std::sqrt(2.0f) / 2.0f;
55  float2(1.0f, 3.0f), float2(value), float2(-value, value));
56  float2 result = transformation * point;
57 
58  float3x3 expected_transformation = float3x3::from_translation_rotation_scale(
59  float2(1.0f, 3.0f), M_PI_4, float2(1.0f));
60  float2 expected = expected_transformation * point;
61 
62  EXPECT_FLOAT_EQ(result[0], expected[0]);
63  EXPECT_FLOAT_EQ(result[1], expected[1]);
64 }
65 
66 TEST(float3x3, PostTransformationMultiplication)
67 {
68  float2 point(1.0f, 2.0f);
69  float3x3 translation = float3x3::from_translation(float2(5.0f, 3.0f));
71  float3x3 transformation = translation * rotation;
72  float2 result = transformation * point;
73  EXPECT_FLOAT_EQ(result[0], 3.0f);
74  EXPECT_FLOAT_EQ(result[1], 4.0f);
75 }
76 
77 TEST(float3x3, PreTransformationMultiplication)
78 {
79  float2 point(1.0f, 2.0f);
80  float3x3 translation = float3x3::from_translation(float2(5.0f, 3.0f));
82  float3x3 transformation = rotation * translation;
83  float2 result = transformation * point;
84  EXPECT_FLOAT_EQ(result[0], -5.0f);
85  EXPECT_FLOAT_EQ(result[1], 6.0f);
86 }
87 
88 TEST(float3x3, TransformationMultiplicationAssignment)
89 {
90  float2 point(1.0f, 2.0f);
91  float3x3 transformation = float3x3::from_translation(float2(5.0f, 3.0f));
92  transformation *= float3x3::from_rotation(M_PI_2);
93  float2 result = transformation * point;
94  EXPECT_FLOAT_EQ(result[0], 3.0f);
95  EXPECT_FLOAT_EQ(result[1], 4.0f);
96 }
97 
98 TEST(float3x3, Inverted)
99 {
100  float2 point(1.0f, 2.0f);
102  float2(1.0f, 3.0f), M_PI_4, float2(1.0f));
103  transformation *= transformation.inverted();
104  float2 result = transformation * point;
105  EXPECT_FLOAT_EQ(result[0], 1.0f);
106  EXPECT_FLOAT_EQ(result[1], 2.0f);
107 }
108 
109 TEST(float3x3, Origin)
110 {
111  float2 point(1.0f, 2.0f);
113  float3x3 transformation = float3x3::from_origin_transformation(rotation, float2(0.0f, 2.0f));
114  float2 result = transformation * point;
115  EXPECT_FLOAT_EQ(result[0], 0.0f);
116  EXPECT_FLOAT_EQ(result[1], 3.0f);
117 }
118 
119 } // namespace blender::tests
sqrt(x)+1/max(0
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define M_PI_2
Definition: BLI_math_base.h:23
#define M_PI_4
Definition: BLI_math_base.h:26
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
TEST(any, DefaultConstructor)
Definition: BLI_any_test.cc:10
vec_base< float, 2 > float2
static float3x3 from_translation(const float2 translation)
Definition: BLI_float3x3.hh:45
static float3x3 from_rotation(float rotation)
Definition: BLI_float3x3.hh:53
static float3x3 identity()
Definition: BLI_float3x3.hh:38
static float3x3 from_normalized_axes(const float2 translation, const float2 horizontal, const float2 vertical)
Definition: BLI_float3x3.hh:85
static float3x3 from_origin_transformation(const float3x3 &transformation, const float2 origin)
float3x3 inverted() const
static float3x3 from_translation_rotation_scale(const float2 translation, float rotation, const float2 scale)
Definition: BLI_float3x3.hh:66