1 #include <gtest/gtest.h> 2 #include <Unittests/unittests_common.hh> 10 class OpenMeshVectorTest :
public testing::Test {
15 virtual void SetUp() {
21 virtual void TearDown() {
38 TEST_F(OpenMeshVectorTest, ComputeTriangleSurfaceWithCrossProduct) {
53 double area = 0.5 *
cross(vec1,vec2).norm();
54 EXPECT_EQ(0.5f , area ) <<
"Wrong area in cross product function";
56 area = 0.5 * ( vec1 % vec2 ).norm();
57 EXPECT_EQ(0.5f , area ) <<
"Wrong area in cross product operator";
63 TEST_F(OpenMeshVectorTest, AbsTest) {
67 EXPECT_EQ( vec1.l8_norm() , 0.5f ) <<
"Wrong l8norm computation";
73 TEST_F(OpenMeshVectorTest, VectorCasting) {
77 EXPECT_EQ(1.f, vecf[0]) <<
"vector type cast failed on component 0";
78 EXPECT_EQ(2.f, vecf[1]) <<
"vector type cast failed on component 1";
79 EXPECT_EQ(3.f, vecf[2]) <<
"vector type cast failed on component 2";
83 EXPECT_EQ(40.0, vecd[0]) <<
"vector dimension cast failed on component 0";
84 EXPECT_EQ(30.0, vecd[1]) <<
"vector dimension cast failed on component 1";
85 EXPECT_EQ(20.0, vecd[2]) <<
"vector dimension cast failed on component 2";
89 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 90 TEST_F(OpenMeshVectorTest, cpp11_constructors) {
93 EXPECT_EQ(1.2, vec1[0]);
94 EXPECT_EQ(2.0, vec1[1]);
95 EXPECT_EQ(3.0, vec1[2]);
99 EXPECT_EQ(1.2f, vec2[0]);
100 EXPECT_EQ(3.5f, vec2[1]);
101 EXPECT_EQ(1.0f, vec2[2]);
102 EXPECT_EQ(0.0f, vec2[3]);
106 EXPECT_EQ(1.2f, vec2b[0]);
107 EXPECT_EQ(3.5f, vec2b[1]);
108 EXPECT_EQ(1.0f, vec2b[2]);
109 EXPECT_EQ(0.0f, vec2b[3]);
112 EXPECT_EQ(1.23, vec4d[0]);
113 EXPECT_EQ(1.23, vec4d[1]);
114 EXPECT_EQ(1.23, vec4d[2]);
115 EXPECT_EQ(1.23, vec4d[3]);
118 TEST_F(OpenMeshVectorTest, cpp11_htmlColorLiteral) {
121 EXPECT_EQ(0xFFC7F1FF_htmlColor, rose);
125 - light_blue).sqrnorm(), 1e-10);
127 const auto light_blue_2 = 0x1FCFFFFF_htmlColor;
129 static_assert(std::is_same<decltype(light_blue_2), decltype(light_blue)>
130 ::value,
"Bad type deduced from _htmlColor literal.");
131 EXPECT_EQ(light_blue, light_blue_2);
139 C(
const C &rhs) { ADD_FAILURE() <<
"Copy constructor used."; }
140 C(C &&rhs) { ++copy_con; }
141 C &operator= (
const C &rhs) {
142 ADD_FAILURE() <<
"Copy assignemnt used.";
145 C &operator= (C &&rhs) { ++copy_ass;
return *
this; }
160 TEST_F(OpenMeshVectorTest, move_constructor_assignment) {
168 EXPECT_EQ(3, C::copy_ass);
169 EXPECT_EQ(0, C::copy_con);
173 EXPECT_EQ(3, C::copy_ass);
174 EXPECT_EQ(3, C::copy_con);
177 TEST_F(OpenMeshVectorTest, iterator_init) {
189 TEST_F(OpenMeshVectorTest, BasicArithmeticInPlace) {
192 const double epsilon = 1e-6;
201 EXPECT_NEAR(4, v2add[0], epsilon);
202 EXPECT_NEAR(6, v2add[1], epsilon);
203 EXPECT_NEAR(9, v2add[2], epsilon);
205 EXPECT_NEAR(2, v2sub[0], epsilon);
206 EXPECT_NEAR(2, v2sub[1], epsilon);
207 EXPECT_NEAR(3, v2sub[2], epsilon);
209 EXPECT_NEAR( 3, v2cmul[0], epsilon);
210 EXPECT_NEAR( 8, v2cmul[1], epsilon);
211 EXPECT_NEAR(18, v2cmul[2], epsilon);
213 EXPECT_NEAR(3, v2cdiv[0], epsilon);
214 EXPECT_NEAR(2, v2cdiv[1], epsilon);
215 EXPECT_NEAR(2, v2cdiv[2], epsilon);
217 EXPECT_NEAR( 6, v2smul[0], epsilon);
218 EXPECT_NEAR( 8, v2smul[1], epsilon);
219 EXPECT_NEAR(12, v2smul[2], epsilon);
221 EXPECT_NEAR(1.5, v2sdiv[0], epsilon);
222 EXPECT_NEAR(2.0, v2sdiv[1], epsilon);
223 EXPECT_NEAR(3.0, v2sdiv[2], epsilon);
226 TEST_F(OpenMeshVectorTest, BasicArithmeticImmutable) {
228 const double epsilon = 1e-6;
238 EXPECT_NEAR(3, v2add[0], epsilon);
239 EXPECT_NEAR(6, v2add[1], epsilon);
240 EXPECT_NEAR(9, v2add[2], epsilon);
242 EXPECT_NEAR(-1, v2sub[0], epsilon);
243 EXPECT_NEAR(-2, v2sub[1], epsilon);
244 EXPECT_NEAR(-3, v2sub[2], epsilon);
246 EXPECT_NEAR( 2, v2cmul[0], epsilon);
247 EXPECT_NEAR( 8, v2cmul[1], epsilon);
248 EXPECT_NEAR(18, v2cmul[2], epsilon);
250 EXPECT_NEAR(0.5, v2cdiv[0], epsilon);
251 EXPECT_NEAR(0.5, v2cdiv[1], epsilon);
252 EXPECT_NEAR(0.5, v2cdiv[2], epsilon);
254 EXPECT_NEAR(2, v2smul[0], epsilon);
255 EXPECT_NEAR(4, v2smul[1], epsilon);
256 EXPECT_NEAR(6, v2smul[2], epsilon);
258 EXPECT_NEAR(0.5, v2sdiv[0], epsilon);
259 EXPECT_NEAR(1.0, v2sdiv[1], epsilon);
260 EXPECT_NEAR(1.5, v2sdiv[2], epsilon);
262 EXPECT_NEAR(-1, v2neg[0], epsilon);
263 EXPECT_NEAR(-2, v2neg[1], epsilon);
264 EXPECT_NEAR(-3, v2neg[2], epsilon);
267 TEST_F(OpenMeshVectorTest, BasicLinearAlgebra) {
269 EXPECT_EQ(v[0], 1.0);
270 EXPECT_EQ(v[1], 2.0);
271 EXPECT_EQ(v[2], 3.0);
293 TEST_F(OpenMeshVectorTest, array_init) {
294 float a[3]; a[0] = 1.0; a[1] = 2.0; a[2] = 3.0;
302 TEST_F(OpenMeshVectorTest, normalized_cond) {
310 EXPECT_NEAR(r1[0], 0.0, 1e-12);
311 EXPECT_NEAR(r1[1], 0.0, 1e-12);
312 EXPECT_NEAR(r1[2], 0.0, 1e-12);
315 TEST_F(OpenMeshVectorTest, size_dim) {
320 EXPECT_EQ(3u, v3d.size());
321 EXPECT_EQ(3, v3d.dim());
322 EXPECT_EQ(3u, v3f.size());
323 EXPECT_EQ(3, v3f.dim());
324 EXPECT_EQ(2u, v2i.size());
325 EXPECT_EQ(2, v2i.dim());
328 class OpenMeshVectorGCCBugTest;
329 void trigger_alignment_bug(OpenMeshVectorGCCBugTest &obj);
336 class OpenMeshVectorGCCBugTest :
public testing::Test {
340 virtual void SetUp() {
346 testfn = trigger_alignment_bug;
352 virtual void TearDown() {
364 void (*testfn)(OpenMeshVectorGCCBugTest &obj);
370 void trigger_alignment_bug(OpenMeshVectorGCCBugTest &obj) {
383 EXPECT_EQ(42, obj.padding);
384 EXPECT_EQ(6.0f, vec3[0]);
385 EXPECT_EQ(8.0f, vec3[1]);
386 EXPECT_EQ(10.0f, vec3[2]);
387 EXPECT_EQ(12.0f, vec3[3]);
390 TEST_F(OpenMeshVectorGCCBugTest, alignment_bug) {
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< float, 4 > Vec4f
VectorT< double, 3 > Vec3d
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
vector_type &::type normalize_cond()
compute squared euclidean norm