1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
8 class OpenMeshVectorTest :
public testing::Test {
13 virtual void SetUp() {
19 virtual void TearDown() {
36 TEST_F(OpenMeshVectorTest, ComputeTriangleSurfaceWithCrossProduct) {
51 double area = 0.5 *
cross(vec1,vec2).norm();
52 EXPECT_EQ(0.5f , area ) <<
"Wrong area in cross product function";
54 area = 0.5 * ( vec1 % vec2 ).norm();
55 EXPECT_EQ(0.5f , area ) <<
"Wrong area in cross product operator";
61 TEST_F(OpenMeshVectorTest, AbsTest) {
65 EXPECT_EQ( vec1.l8_norm() , 0.5f ) <<
"Wrong l8norm computation";
71 TEST_F(OpenMeshVectorTest, VectorCasting) {
75 EXPECT_EQ(1.f, vecf[0]) <<
"vector type cast failed on component 0";
76 EXPECT_EQ(2.f, vecf[1]) <<
"vector type cast failed on component 1";
77 EXPECT_EQ(3.f, vecf[2]) <<
"vector type cast failed on component 2";
81 EXPECT_EQ(40.0, vecd[0]) <<
"vector dimension cast failed on component 0";
82 EXPECT_EQ(30.0, vecd[1]) <<
"vector dimension cast failed on component 1";
83 EXPECT_EQ(20.0, vecd[2]) <<
"vector dimension cast failed on component 2";
87 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
88 TEST_F(OpenMeshVectorTest, cpp11_constructors) {
91 EXPECT_EQ(1.2, vec1[0]);
92 EXPECT_EQ(2.0, vec1[1]);
93 EXPECT_EQ(3.0, vec1[2]);
97 EXPECT_EQ(1.2f, vec2[0]);
98 EXPECT_EQ(3.5f, vec2[1]);
99 EXPECT_EQ(1.0f, vec2[2]);
100 EXPECT_EQ(0.0f, vec2[3]);
104 EXPECT_EQ(1.2f, vec2b[0]);
105 EXPECT_EQ(3.5f, vec2b[1]);
106 EXPECT_EQ(1.0f, vec2b[2]);
107 EXPECT_EQ(0.0f, vec2b[3]);
110 EXPECT_EQ(1.23, vec4d[0]);
111 EXPECT_EQ(1.23, vec4d[1]);
112 EXPECT_EQ(1.23, vec4d[2]);
113 EXPECT_EQ(1.23, vec4d[3]);
116 TEST_F(OpenMeshVectorTest, cpp11_htmlColorLiteral) {
119 EXPECT_EQ(0xFFC7F1FF_htmlColor, rose);
123 - light_blue).sqrnorm(), 1e-10);
125 const auto light_blue_2 = 0x1FCFFFFF_htmlColor;
127 static_assert(std::is_same<decltype(light_blue_2), decltype(light_blue)>
128 ::value,
"Bad type deduced from _htmlColor literal.");
129 EXPECT_EQ(light_blue, light_blue_2);
137 C(
const C &rhs) { ADD_FAILURE() <<
"Copy constructor used."; }
138 C(C &&rhs) { ++copy_con; }
139 C &operator= (
const C &rhs) {
140 ADD_FAILURE() <<
"Copy assignemnt used.";
143 C &operator= (C &&rhs) { ++copy_ass;
return *
this; }
158 TEST_F(OpenMeshVectorTest, move_constructor_assignment) {
166 EXPECT_EQ(3, C::copy_ass);
167 EXPECT_EQ(0, C::copy_con);
171 EXPECT_EQ(3, C::copy_ass);
172 EXPECT_EQ(3, C::copy_con);
175 TEST_F(OpenMeshVectorTest, iterator_init) {
187 TEST_F(OpenMeshVectorTest, BasicArithmeticInPlace) {
190 const double epsilon = 1e-6;
199 EXPECT_NEAR(4, v2add[0], epsilon);
200 EXPECT_NEAR(6, v2add[1], epsilon);
201 EXPECT_NEAR(9, v2add[2], epsilon);
203 EXPECT_NEAR(2, v2sub[0], epsilon);
204 EXPECT_NEAR(2, v2sub[1], epsilon);
205 EXPECT_NEAR(3, v2sub[2], epsilon);
207 EXPECT_NEAR( 3, v2cmul[0], epsilon);
208 EXPECT_NEAR( 8, v2cmul[1], epsilon);
209 EXPECT_NEAR(18, v2cmul[2], epsilon);
211 EXPECT_NEAR(3, v2cdiv[0], epsilon);
212 EXPECT_NEAR(2, v2cdiv[1], epsilon);
213 EXPECT_NEAR(2, v2cdiv[2], epsilon);
215 EXPECT_NEAR( 6, v2smul[0], epsilon);
216 EXPECT_NEAR( 8, v2smul[1], epsilon);
217 EXPECT_NEAR(12, v2smul[2], epsilon);
219 EXPECT_NEAR(1.5, v2sdiv[0], epsilon);
220 EXPECT_NEAR(2.0, v2sdiv[1], epsilon);
221 EXPECT_NEAR(3.0, v2sdiv[2], epsilon);
224 TEST_F(OpenMeshVectorTest, BasicArithmeticImmutable) {
226 const double epsilon = 1e-6;
236 EXPECT_NEAR(3, v2add[0], epsilon);
237 EXPECT_NEAR(6, v2add[1], epsilon);
238 EXPECT_NEAR(9, v2add[2], epsilon);
240 EXPECT_NEAR(-1, v2sub[0], epsilon);
241 EXPECT_NEAR(-2, v2sub[1], epsilon);
242 EXPECT_NEAR(-3, v2sub[2], epsilon);
244 EXPECT_NEAR( 2, v2cmul[0], epsilon);
245 EXPECT_NEAR( 8, v2cmul[1], epsilon);
246 EXPECT_NEAR(18, v2cmul[2], epsilon);
248 EXPECT_NEAR(0.5, v2cdiv[0], epsilon);
249 EXPECT_NEAR(0.5, v2cdiv[1], epsilon);
250 EXPECT_NEAR(0.5, v2cdiv[2], epsilon);
252 EXPECT_NEAR(2, v2smul[0], epsilon);
253 EXPECT_NEAR(4, v2smul[1], epsilon);
254 EXPECT_NEAR(6, v2smul[2], epsilon);
256 EXPECT_NEAR(0.5, v2sdiv[0], epsilon);
257 EXPECT_NEAR(1.0, v2sdiv[1], epsilon);
258 EXPECT_NEAR(1.5, v2sdiv[2], epsilon);
260 EXPECT_NEAR(-1, v2neg[0], epsilon);
261 EXPECT_NEAR(-2, v2neg[1], epsilon);
262 EXPECT_NEAR(-3, v2neg[2], epsilon);
265 TEST_F(OpenMeshVectorTest, BasicLinearAlgebra) {
267 EXPECT_EQ(v[0], 1.0);
268 EXPECT_EQ(v[1], 2.0);
269 EXPECT_EQ(v[2], 3.0);
291 TEST_F(OpenMeshVectorTest, array_init) {
292 float a[3]; a[0] = 1.0; a[1] = 2.0; a[2] = 3.0;
300 TEST_F(OpenMeshVectorTest, normalized_cond) {
307 0.8017837257372732) - v1.normalize_cond();
308 EXPECT_NEAR(r1[0], 0.0, 1e-12);
309 EXPECT_NEAR(r1[1], 0.0, 1e-12);
310 EXPECT_NEAR(r1[2], 0.0, 1e-12);
313 TEST_F(OpenMeshVectorTest, size_dim) {
318 EXPECT_EQ(3u, v3d.size());
319 EXPECT_EQ(3, v3d.dim());
320 EXPECT_EQ(3u, v3f.size());
321 EXPECT_EQ(3, v3f.dim());
322 EXPECT_EQ(2u, v2i.size());
323 EXPECT_EQ(2, v2i.dim());
VectorT< double, 3 > Vec3d
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
VectorT< Scalar, N > cross(const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)