Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BLI_float3x3_test.cc « tests « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d22993ee69e8bb9affde09f87598037fa2e1ccec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* SPDX-License-Identifier: Apache-2.0 */

#include "testing/testing.h"

#include "BLI_float3x3.hh"
#include "BLI_math_base.h"
#include "BLI_math_vec_types.hh"

namespace blender::tests {

TEST(float3x3, Identity)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::identity();
  float2 result = transformation * point;
  EXPECT_EQ(result, point);
}

TEST(float3x3, Translation)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::from_translation(float2(5.0f, 3.0f));
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], 6.0f);
  EXPECT_FLOAT_EQ(result[1], 5.0f);
}

TEST(float3x3, Rotation)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::from_rotation(M_PI_2);
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], -2.0f);
  EXPECT_FLOAT_EQ(result[1], 1.0f);
}

TEST(float3x3, TranslationRotationScale)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::from_translation_rotation_scale(
      float2(1.0f, 3.0f), M_PI_2, float2(2.0f, 3.0f));
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], -5.0f);
  EXPECT_FLOAT_EQ(result[1], 5.0f);
}

TEST(float3x3, NormalizedAxes)
{
  float2 point(1.0f, 2.0f);

  /* The horizontal is aligned with (1, 1) and vertical is aligned with (-1, 1), in other words, a
   * Pi / 4 rotation. */
  float value = std::sqrt(2.0f) / 2.0f;
  float3x3 transformation = float3x3::from_normalized_axes(
      float2(1.0f, 3.0f), float2(value), float2(-value, value));
  float2 result = transformation * point;

  float3x3 expected_transformation = float3x3::from_translation_rotation_scale(
      float2(1.0f, 3.0f), M_PI_4, float2(1.0f));
  float2 expected = expected_transformation * point;

  EXPECT_FLOAT_EQ(result[0], expected[0]);
  EXPECT_FLOAT_EQ(result[1], expected[1]);
}

TEST(float3x3, PostTransformationMultiplication)
{
  float2 point(1.0f, 2.0f);
  float3x3 translation = float3x3::from_translation(float2(5.0f, 3.0f));
  float3x3 rotation = float3x3::from_rotation(M_PI_2);
  float3x3 transformation = translation * rotation;
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], 3.0f);
  EXPECT_FLOAT_EQ(result[1], 4.0f);
}

TEST(float3x3, PreTransformationMultiplication)
{
  float2 point(1.0f, 2.0f);
  float3x3 translation = float3x3::from_translation(float2(5.0f, 3.0f));
  float3x3 rotation = float3x3::from_rotation(M_PI_2);
  float3x3 transformation = rotation * translation;
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], -5.0f);
  EXPECT_FLOAT_EQ(result[1], 6.0f);
}

TEST(float3x3, TransformationMultiplicationAssignment)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::from_translation(float2(5.0f, 3.0f));
  transformation *= float3x3::from_rotation(M_PI_2);
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], 3.0f);
  EXPECT_FLOAT_EQ(result[1], 4.0f);
}

TEST(float3x3, Inverted)
{
  float2 point(1.0f, 2.0f);
  float3x3 transformation = float3x3::from_translation_rotation_scale(
      float2(1.0f, 3.0f), M_PI_4, float2(1.0f));
  transformation *= transformation.inverted();
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], 1.0f);
  EXPECT_FLOAT_EQ(result[1], 2.0f);
}

TEST(float3x3, Origin)
{
  float2 point(1.0f, 2.0f);
  float3x3 rotation = float3x3::from_rotation(M_PI_2);
  float3x3 transformation = float3x3::from_origin_transformation(rotation, float2(0.0f, 2.0f));
  float2 result = transformation * point;
  EXPECT_FLOAT_EQ(result[0], 0.0f);
  EXPECT_FLOAT_EQ(result[1], 3.0f);
}

}  // namespace blender::tests