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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-03-25 17:57:10 +0300
committerHans Goudey <h.goudey@me.com>2022-03-25 17:57:10 +0300
commit378022c7973db54f1ad8cf335a9359c3bf27ddb5 (patch)
treea69090518a1f7c0ca7661b370dedd05ee37f6b52 /source/blender/blenlib/tests
parent1243cb803e7d096d27e2b5dcdfa05bf0367e248c (diff)
BLI: Adjust interpolation to support integers, other tweaks
In order to allow interpolation of integers with a float, add a separate template parameter for the factor and multiplication types. Also move some helper constexpr variables to the "base" header (reversing the dependency to "base" -> "vector"). This also adds a distance function for scalar types, which is helpful to allow sharing code between vectors and basic types. Differential Revision: https://developer.blender.org/D14446
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r--source/blender/blenlib/tests/BLI_math_base_test.cc5
-rw-r--r--source/blender/blenlib/tests/BLI_math_vector_test.cc20
2 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_math_base_test.cc b/source/blender/blenlib/tests/BLI_math_base_test.cc
index 62f2b2775d0..dd35deef4a8 100644
--- a/source/blender/blenlib/tests/BLI_math_base_test.cc
+++ b/source/blender/blenlib/tests/BLI_math_base_test.cc
@@ -151,4 +151,9 @@ TEST(math_base, Midpoint)
EXPECT_NEAR(math::midpoint(100.0f, 200.0f), 150.0f, 1e-4f);
}
+TEST(math_base, InterpolateInt)
+{
+ EXPECT_EQ(math::interpolate(100, 200, 0.4f), 140);
+}
+
} // namespace blender::tests
diff --git a/source/blender/blenlib/tests/BLI_math_vector_test.cc b/source/blender/blenlib/tests/BLI_math_vector_test.cc
index 8c310645d6d..282be5f1963 100644
--- a/source/blender/blenlib/tests/BLI_math_vector_test.cc
+++ b/source/blender/blenlib/tests/BLI_math_vector_test.cc
@@ -85,4 +85,24 @@ TEST(math_vector, Clamp)
EXPECT_EQ(result_2.z, -50);
}
+TEST(math_vector, InterpolateInt)
+{
+ const int3 a(0, -100, 50);
+ const int3 b(0, 100, 100);
+ const int3 result = math::interpolate(a, b, 0.75);
+ EXPECT_EQ(result.x, 0);
+ EXPECT_EQ(result.y, 50);
+ EXPECT_EQ(result.z, 87);
+}
+
+TEST(math_vector, InterpolateFloat)
+{
+ const float3 a(40.0f, -100.0f, 50.0f);
+ const float3 b(20.0f, 100.0f, 100.0f);
+ const float3 result = math::interpolate(a, b, 0.5);
+ EXPECT_FLOAT_EQ(result.x, 30.0f);
+ EXPECT_FLOAT_EQ(result.y, 0.0f);
+ EXPECT_FLOAT_EQ(result.z, 75.0f);
+}
+
} // namespace blender::tests