Blender  V2.93
BLI_math_vector_test.cc
Go to the documentation of this file.
1 /* Apache License, Version 2.0 */
2 
3 #include "testing/testing.h"
4 
5 #include "BLI_math.h"
6 
7 TEST(math_vector, ClampVecWithFloats)
8 {
9  const float min = 0.0f;
10  const float max = 1.0f;
11 
12  float a[2] = {-1.0f, -1.0f};
13  clamp_v2(a, min, max);
14  EXPECT_FLOAT_EQ(0.0f, a[0]);
15  EXPECT_FLOAT_EQ(0.0f, a[1]);
16 
17  float b[2] = {0.5f, 0.5f};
18  clamp_v2(b, min, max);
19  EXPECT_FLOAT_EQ(0.5f, b[0]);
20  EXPECT_FLOAT_EQ(0.5f, b[1]);
21 
22  float c[2] = {2.0f, 2.0f};
23  clamp_v2(c, min, max);
24  EXPECT_FLOAT_EQ(1.0f, c[0]);
25  EXPECT_FLOAT_EQ(1.0f, c[1]);
26 }
27 
28 TEST(math_vector, ClampVecWithVecs)
29 {
30  const float min[2] = {0.0f, 2.0f};
31  const float max[2] = {1.0f, 3.0f};
32 
33  float a[2] = {-1.0f, -1.0f};
35  EXPECT_FLOAT_EQ(0.0f, a[0]);
36  EXPECT_FLOAT_EQ(2.0f, a[1]);
37 
38  float b[2] = {0.5f, 2.5f};
39  clamp_v2_v2v2(b, min, max);
40  EXPECT_FLOAT_EQ(0.5f, b[0]);
41  EXPECT_FLOAT_EQ(2.5f, b[1]);
42 
43  float c[2] = {2.0f, 4.0f};
45  EXPECT_FLOAT_EQ(1.0f, c[0]);
46  EXPECT_FLOAT_EQ(3.0f, c[1]);
47 }
MINLINE void clamp_v2(float vec[2], const float min, const float max)
MINLINE void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2])
TEST(math_vector, ClampVecWithFloats)
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
#define min(a, b)
Definition: sort.c:51
float max