5#include "testing/testing.h"
12TEST(math_vector, ClampVecWithFloats)
14 const float min = 0.0f;
15 const float max = 1.0f;
17 float a[2] = {-1.0f, -1.0f};
19 EXPECT_FLOAT_EQ(0.0f, a[0]);
20 EXPECT_FLOAT_EQ(0.0f, a[1]);
22 float b[2] = {0.5f, 0.5f};
24 EXPECT_FLOAT_EQ(0.5f,
b[0]);
25 EXPECT_FLOAT_EQ(0.5f,
b[1]);
27 float c[2] = {2.0f, 2.0f};
29 EXPECT_FLOAT_EQ(1.0f, c[0]);
30 EXPECT_FLOAT_EQ(1.0f, c[1]);
33TEST(math_vector, ClampVecWithVecs)
35 const float min[2] = {0.0f, 2.0f};
36 const float max[2] = {1.0f, 3.0f};
38 float a[2] = {-1.0f, -1.0f};
40 EXPECT_FLOAT_EQ(0.0f, a[0]);
41 EXPECT_FLOAT_EQ(2.0f, a[1]);
43 float b[2] = {0.5f, 2.5f};
45 EXPECT_FLOAT_EQ(0.5f,
b[0]);
46 EXPECT_FLOAT_EQ(2.5f,
b[1]);
48 float c[2] = {2.0f, 4.0f};
50 EXPECT_FLOAT_EQ(1.0f, c[0]);
51 EXPECT_FLOAT_EQ(3.0f, c[1]);
54TEST(math_vector, test_invert_v3_safe)
56 float v3_with_zeroes[3] = {0.0f, 2.0f, 3.0f};
58 EXPECT_FLOAT_EQ(0.0f, v3_with_zeroes[0]);
59 EXPECT_FLOAT_EQ(0.5f, v3_with_zeroes[1]);
60 EXPECT_FLOAT_EQ(0.33333333333f, v3_with_zeroes[2]);
62 float v3_without_zeroes[3] = {1.0f, 2.0f, 3.0f};
63 float inverted_unsafe[3] = {1.0f, 2.0f, 3.0f};
67 EXPECT_FLOAT_EQ(inverted_unsafe[0], v3_without_zeroes[0]);
68 EXPECT_FLOAT_EQ(inverted_unsafe[1], v3_without_zeroes[1]);
69 EXPECT_FLOAT_EQ(inverted_unsafe[2], v3_without_zeroes[2]);
74 const int3 value(0, 100, -100);
89TEST(math_vector, InterpolateInt)
91 const int3 a(0, -100, 50);
92 const int3 b(0, 100, 100);
99TEST(math_vector, InterpolateFloat)
101 const float3 a(40.0f, -100.0f, 50.0f);
102 const float3 b(20.0f, 100.0f, 100.0f);
104 EXPECT_FLOAT_EQ(result.x, 30.0f);
105 EXPECT_FLOAT_EQ(result.y, 0.0f);
106 EXPECT_FLOAT_EQ(result.z, 75.0f);
109TEST(math_vector, CeilToMultiple)
111 const int3 a(21, 16, 0);
112 const int3 b(8, 16, 15);
114 EXPECT_FLOAT_EQ(result.x, 24);
115 EXPECT_FLOAT_EQ(result.y, 16);
116 EXPECT_FLOAT_EQ(result.z, 0);
121 const int3 a(21, 16, 0);
122 const int3 b(8, 16, 15);
124 EXPECT_FLOAT_EQ(result.x, 3);
125 EXPECT_FLOAT_EQ(result.y, 1);
126 EXPECT_FLOAT_EQ(result.z, 0);
131 const int3 a(-21, 16, 0);
133 EXPECT_FLOAT_EQ(result.x, -1);
134 EXPECT_FLOAT_EQ(result.y, 1);
135 EXPECT_FLOAT_EQ(result.z, 0);
140 const float3 a(1.0f, 4.0f, 9.0f);
142 EXPECT_NEAR(result.x, 1.0f, 1e-6f);
143 EXPECT_NEAR(result.y, 2.0f, 1e-6f);
144 EXPECT_NEAR(result.z, 3.0f, 1e-6f);
149 const float3 a(1.0f, -4.0f, 9.0f);
151 EXPECT_NEAR(result.x, 1.0f, 1e-6f);
152 EXPECT_NEAR(result.y, 0.0f, 1e-6f);
153 EXPECT_NEAR(result.z, 3.0f, 1e-6f);
158 const float3 a(1.0f, 2.0f, 4.0f);
160 EXPECT_NEAR(result.x, 1.0f, 1e-6f);
161 EXPECT_NEAR(result.y, 0.5f, 1e-6f);
162 EXPECT_NEAR(result.z, 0.25f, 1e-6f);
167 const float3 a(1.0f, 0.0f, 4.0f);
169 EXPECT_NEAR(result.x, 1.0f, 1e-6f);
170 EXPECT_NEAR(result.y, 0.0f, 1e-6f);
171 EXPECT_NEAR(result.z, 0.25f, 1e-6f);
176 const float3 a(1.0f, 2.0f, 3.0f);
178 EXPECT_NEAR(result.x, 2.718281828459045f, 1e-6f);
179 EXPECT_NEAR(result.y, 7.38905609893065f, 1e-6f);
180 EXPECT_NEAR(result.z, 20.085536923187668f, 1e-6f);
185 const float3 a(1.0f, 2.0f, 3.0f);
187 EXPECT_NEAR(result.x, 1.0f, 1e-6f);
188 EXPECT_NEAR(result.y, 4.0f, 1e-6f);
189 EXPECT_NEAR(result.z, 9.0f, 1e-6f);
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
MINLINE void invert_v3_safe(float r[3])
MINLINE void clamp_v2(float vec[2], float min, float max)
MINLINE void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2])
MINLINE void invert_v3(float r[3])
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp
static T Sign(const T &x)
local_group_size(16, 16) .push_constant(Type b
T clamp(const T &a, const T &min, const T &max)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T interpolate(const T &a, const T &b, const FactorT &t)
VecBase< T, Size > ceil_to_multiple(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< T, Size > safe_sqrt(const VecBase< T, Size > &a)
TEST(any, DefaultConstructor)