5#include "testing/testing.h"
13TEST(math_vector, ClampVecWithFloats)
15 const float min = 0.0f;
16 const float max = 1.0f;
18 float a[2] = {-1.0f, -1.0f};
20 EXPECT_FLOAT_EQ(0.0f, a[0]);
21 EXPECT_FLOAT_EQ(0.0f, a[1]);
23 float b[2] = {0.5f, 0.5f};
25 EXPECT_FLOAT_EQ(0.5f,
b[0]);
26 EXPECT_FLOAT_EQ(0.5f,
b[1]);
28 float c[2] = {2.0f, 2.0f};
30 EXPECT_FLOAT_EQ(1.0f, c[0]);
31 EXPECT_FLOAT_EQ(1.0f, c[1]);
34TEST(math_vector, test_invert_v3_safe)
36 float v3_with_zeroes[3] = {0.0f, 2.0f, 3.0f};
38 EXPECT_FLOAT_EQ(0.0f, v3_with_zeroes[0]);
39 EXPECT_FLOAT_EQ(0.5f, v3_with_zeroes[1]);
40 EXPECT_FLOAT_EQ(0.33333333333f, v3_with_zeroes[2]);
42 float v3_without_zeroes[3] = {1.0f, 2.0f, 3.0f};
43 float inverted_unsafe[3] = {1.0f, 2.0f, 3.0f};
47 EXPECT_FLOAT_EQ(inverted_unsafe[0], v3_without_zeroes[0]);
48 EXPECT_FLOAT_EQ(inverted_unsafe[1], v3_without_zeroes[1]);
49 EXPECT_FLOAT_EQ(inverted_unsafe[2], v3_without_zeroes[2]);
54 const int3 value(0, 100, -100);
76 const float inf = std::numeric_limits<float>::infinity();
80 const float nan = std::numeric_limits<float>::quiet_NaN();
83 EXPECT_TRUE(std::isnan(
result.x));
95 const float inf = std::numeric_limits<float>::infinity();
99 const float nan = std::numeric_limits<float>::quiet_NaN();
102 EXPECT_TRUE(std::isnan(
result.x));
107TEST(math_vector, InterpolateInt)
109 const int3 a(0, -100, 50);
110 const int3 b(0, 100, 100);
117TEST(math_vector, InterpolateFloat)
119 const float3 a(40.0f, -100.0f, 50.0f);
120 const float3 b(20.0f, 100.0f, 100.0f);
122 EXPECT_FLOAT_EQ(
result.x, 30.0f);
123 EXPECT_FLOAT_EQ(
result.y, 0.0f);
124 EXPECT_FLOAT_EQ(
result.z, 75.0f);
127TEST(math_vector, CeilToMultiple)
129 const int3 a(21, 16, 0);
130 const int3 b(8, 16, 15);
132 EXPECT_FLOAT_EQ(
result.x, 24);
133 EXPECT_FLOAT_EQ(
result.y, 16);
134 EXPECT_FLOAT_EQ(
result.z, 0);
139 const int3 a(21, 16, 0);
140 const int3 b(8, 16, 15);
142 EXPECT_FLOAT_EQ(
result.x, 3);
143 EXPECT_FLOAT_EQ(
result.y, 1);
144 EXPECT_FLOAT_EQ(
result.z, 0);
149 const int3 a(-21, 16, 0);
151 EXPECT_FLOAT_EQ(
result.x, -1);
152 EXPECT_FLOAT_EQ(
result.y, 1);
153 EXPECT_FLOAT_EQ(
result.z, 0);
158 const float3 a(1.0f, 4.0f, 9.0f);
160 EXPECT_NEAR(
result.x, 1.0f, 1e-6f);
161 EXPECT_NEAR(
result.y, 2.0f, 1e-6f);
162 EXPECT_NEAR(
result.z, 3.0f, 1e-6f);
167 const float3 a(1.0f, -4.0f, 9.0f);
169 EXPECT_NEAR(
result.x, 1.0f, 1e-6f);
170 EXPECT_NEAR(
result.y, 0.0f, 1e-6f);
171 EXPECT_NEAR(
result.z, 3.0f, 1e-6f);
176 const float3 a(1.0f, 2.0f, 4.0f);
178 EXPECT_NEAR(
result.x, 1.0f, 1e-6f);
179 EXPECT_NEAR(
result.y, 0.5f, 1e-6f);
180 EXPECT_NEAR(
result.z, 0.25f, 1e-6f);
185 const float3 a(1.0f, 0.0f, 4.0f);
187 EXPECT_NEAR(
result.x, 1.0f, 1e-6f);
188 EXPECT_NEAR(
result.y, 0.0f, 1e-6f);
189 EXPECT_NEAR(
result.z, 0.25f, 1e-6f);
194 const float3 a(1.0f, 2.0f, 3.0f);
196 EXPECT_NEAR(
result.x, 2.718281828459045f, 1e-6f);
197 EXPECT_NEAR(
result.y, 7.38905609893065f, 1e-6f);
198 EXPECT_NEAR(
result.z, 20.085536923187668f, 1e-6f);
203 const float3 a(1.0f, 2.0f, 3.0f);
205 EXPECT_NEAR(
result.x, 1.0f, 1e-6f);
206 EXPECT_NEAR(
result.y, 4.0f, 1e-6f);
207 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 invert_v3(float r[3])
static double Clamp(const double x, const double min, const double max)
static T Sign(const T &x)
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 min(const T &a, const T &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)
T max(const T &a, const T &b)
VecBase< T, Size > safe_sqrt(const VecBase< T, Size > &a)
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3