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:
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r--source/blender/blenlib/tests/BLI_delaunay_2d_test.cc3
-rw-r--r--source/blender/blenlib/tests/BLI_math_vec_types_test.cc149
-rw-r--r--source/blender/blenlib/tests/BLI_memory_utils_test.cc2
-rw-r--r--source/blender/blenlib/tests/BLI_mesh_boolean_test.cc2
-rw-r--r--source/blender/blenlib/tests/BLI_mesh_intersect_test.cc2
5 files changed, 153 insertions, 5 deletions
diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc
index 70e3a99e57a..eac3faa6d15 100644
--- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc
+++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc
@@ -21,10 +21,9 @@ extern "C" {
#define DO_RANDOM_TESTS 0
#include "BLI_array.hh"
-#include "BLI_double2.hh"
#include "BLI_math_boolean.hh"
#include "BLI_math_mpq.hh"
-#include "BLI_mpq2.hh"
+#include "BLI_math_vec_mpq_types.hh"
#include "BLI_vector.hh"
#include "BLI_delaunay_2d.h"
diff --git a/source/blender/blenlib/tests/BLI_math_vec_types_test.cc b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc
new file mode 100644
index 00000000000..8aa1f90fde2
--- /dev/null
+++ b/source/blender/blenlib/tests/BLI_math_vec_types_test.cc
@@ -0,0 +1,149 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+
+#include "BLI_math_vec_types.hh"
+
+namespace blender::tests {
+
+using namespace blender::math;
+
+TEST(math_vec_types, ScalarConstructorUnsigned)
+{
+ float2 u(5u);
+ EXPECT_EQ(u[0], 5.0f);
+ EXPECT_EQ(u[1], 5.0f);
+}
+
+TEST(math_vec_types, ScalarConstructorInt)
+{
+ float2 i(-5);
+ EXPECT_EQ(i[0], -5.0f);
+ EXPECT_EQ(i[1], -5.0f);
+}
+
+TEST(math_vec_types, ScalarConstructorFloat)
+{
+ float2 f(5.2f);
+ EXPECT_FLOAT_EQ(f[0], 5.2f);
+ EXPECT_FLOAT_EQ(f[1], 5.2f);
+}
+
+TEST(math_vec_types, ScalarConstructorDouble)
+{
+ float2 d(5.2);
+ EXPECT_FLOAT_EQ(d[0], 5.2f);
+ EXPECT_FLOAT_EQ(d[1], 5.2f);
+}
+
+TEST(math_vec_types, MultiScalarConstructorVec2)
+{
+ int2 i(5.5f, -1.8);
+ EXPECT_EQ(i[0], 5);
+ EXPECT_EQ(i[1], -1);
+}
+
+TEST(math_vec_types, MultiScalarConstructorVec3)
+{
+ int3 i(5.5f, -1.8, 6u);
+ EXPECT_EQ(i[0], 5);
+ EXPECT_EQ(i[1], -1);
+ EXPECT_EQ(i[2], 6);
+}
+
+TEST(math_vec_types, MultiScalarConstructorVec4)
+{
+ int4 i(5.5f, -1.8, 6u, 0.888f);
+ EXPECT_EQ(i[0], 5);
+ EXPECT_EQ(i[1], -1);
+ EXPECT_EQ(i[2], 6);
+ EXPECT_EQ(i[3], 0);
+}
+
+TEST(math_vec_types, MixedScalarVectorConstructorVec3)
+{
+ float3 fl_v2(float2(5.5f), 1.8f);
+ EXPECT_FLOAT_EQ(fl_v2[0], 5.5f);
+ EXPECT_FLOAT_EQ(fl_v2[1], 5.5f);
+ EXPECT_FLOAT_EQ(fl_v2[2], 1.8f);
+
+ float3 v2_fl(1.8f, float2(5.5f));
+ EXPECT_FLOAT_EQ(v2_fl[0], 1.8f);
+ EXPECT_FLOAT_EQ(v2_fl[1], 5.5f);
+ EXPECT_FLOAT_EQ(v2_fl[2], 5.5f);
+}
+
+TEST(math_vec_types, MixedScalarVectorConstructorVec4)
+{
+ int4 v2_fl_fl(float2(1), 2, 3);
+ EXPECT_EQ(v2_fl_fl[0], 1);
+ EXPECT_EQ(v2_fl_fl[1], 1);
+ EXPECT_EQ(v2_fl_fl[2], 2);
+ EXPECT_EQ(v2_fl_fl[3], 3);
+
+ float4 fl_v2_fl(1, int2(2), 3);
+ EXPECT_EQ(fl_v2_fl[0], 1);
+ EXPECT_EQ(fl_v2_fl[1], 2);
+ EXPECT_EQ(fl_v2_fl[2], 2);
+ EXPECT_EQ(fl_v2_fl[3], 3);
+
+ double4 fl_fl_v2(1, 2, double2(3));
+ EXPECT_EQ(fl_fl_v2[0], 1);
+ EXPECT_EQ(fl_fl_v2[1], 2);
+ EXPECT_EQ(fl_fl_v2[2], 3);
+ EXPECT_EQ(fl_fl_v2[3], 3);
+
+ int4 v2_v2(float2(1), uint2(2));
+ EXPECT_EQ(v2_v2[0], 1);
+ EXPECT_EQ(v2_v2[1], 1);
+ EXPECT_EQ(v2_v2[2], 2);
+ EXPECT_EQ(v2_v2[3], 2);
+
+ float4 v3_fl(uint3(1), 2);
+ EXPECT_EQ(v3_fl[0], 1);
+ EXPECT_EQ(v3_fl[1], 1);
+ EXPECT_EQ(v3_fl[2], 1);
+ EXPECT_EQ(v3_fl[3], 2);
+
+ uint4 fl_v3(1, float3(2));
+ EXPECT_EQ(fl_v3[0], 1);
+ EXPECT_EQ(fl_v3[1], 2);
+ EXPECT_EQ(fl_v3[2], 2);
+ EXPECT_EQ(fl_v3[3], 2);
+}
+
+TEST(math_vec_types, ComponentMasking)
+{
+ int4 i(0, 1, 2, 3);
+ float2 f2 = float2(i);
+ EXPECT_EQ(f2[0], 0.0f);
+ EXPECT_EQ(f2[1], 1.0f);
+}
+
+TEST(math_vec_types, PointerConversion)
+{
+ float array[3] = {1.0f, 2.0f, 3.0f};
+ float3 farray(array);
+ EXPECT_EQ(farray[0], 1.0f);
+ EXPECT_EQ(farray[1], 2.0f);
+ EXPECT_EQ(farray[2], 3.0f);
+}
+
+TEST(math_vec_types, PointerArrayConversion)
+{
+ float array[1][3] = {{1.0f, 2.0f, 3.0f}};
+ float(*ptr)[3] = array;
+ float3 fptr(ptr);
+ EXPECT_EQ(fptr[0], 1.0f);
+ EXPECT_EQ(fptr[1], 2.0f);
+ EXPECT_EQ(fptr[2], 3.0f);
+}
+
+TEST(math_vec_types, VectorTypeConversion)
+{
+ double2 d(int2(float2(5.75f, -1.57f)));
+ EXPECT_EQ(d[0], 5.0);
+ EXPECT_EQ(d[1], -1.0);
+}
+
+} // namespace blender::tests
diff --git a/source/blender/blenlib/tests/BLI_memory_utils_test.cc b/source/blender/blenlib/tests/BLI_memory_utils_test.cc
index 207f310d902..74e54151a06 100644
--- a/source/blender/blenlib/tests/BLI_memory_utils_test.cc
+++ b/source/blender/blenlib/tests/BLI_memory_utils_test.cc
@@ -1,6 +1,6 @@
/* Apache License, Version 2.0 */
-#include "BLI_float3.hh"
+#include "BLI_math_vec_types.hh"
#include "BLI_memory_utils.hh"
#include "BLI_strict_flags.h"
#include "testing/testing.h"
diff --git a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc
index d759f0c3be4..2b8fb3dbea4 100644
--- a/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc
+++ b/source/blender/blenlib/tests/BLI_mesh_boolean_test.cc
@@ -11,8 +11,8 @@
#include "BLI_array.hh"
#include "BLI_map.hh"
#include "BLI_math_mpq.hh"
+#include "BLI_math_vec_mpq_types.hh"
#include "BLI_mesh_boolean.hh"
-#include "BLI_mpq3.hh"
#include "BLI_vector.hh"
#ifdef WITH_GMP
diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
index 68111fb8eb1..d2d76593129 100644
--- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
+++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
@@ -10,8 +10,8 @@
#include "BLI_array.hh"
#include "BLI_math_mpq.hh"
+#include "BLI_math_vec_mpq_types.hh"
#include "BLI_mesh_intersect.hh"
-#include "BLI_mpq3.hh"
#include "BLI_task.h"
#include "BLI_vector.hh"