53{
54 using Real = double;
56
61
64 Real t3[] = {1.5,2.5};
65 Real t4[] = {5.5,4.5};
66
67 Point2D p1( t1 );
68 Point2D p2( t2 );
69 RealPoint2D p3(t3);
70 RealPoint2D p4(t4);
71
72 Point3D p1_3d( p1[0], p1[1] );
73 Point3D p2_3d( p2[0], p2[1] );
76
77 SECTION(
"Cross products with integers")
78 {
83 }
84
85 SECTION(
"Cross products with reals")
86 {
91 }
92
93 SECTION(
"Cross products with mixed integers/reals")
94 {
99 }
100 SECTION(
"Access data() of internal container")
101 {
102 const auto d = p1_3d.data();
103 CHECK(d[0] == p1[0]);
104 CHECK(d[1] == p1[1]);
105 }
106}
107
109{
110 using Real = double;
112
115
118 Real t3[] = {1.5,2.5,3.5};
119 Real t4[] = {5.5,4.5,3.5};
120
125
126 SECTION(
"Cross products with integers")
127 {
132 }
133
134 SECTION(
"Cross products with reals")
135 {
140 }
141
142 SECTION(
"Cross products with mixed integers/reals")
143 {
148 }
149}
150
152{
153 using Real = double;
155
158
159 const Real pi = std::acos(Real(-1));
160
163 Real t3[] = {1.0,-1.0,2.0,-2.0};
164 Real t4[] = {5.5,-4.5,3.5,2.5};
165
173
175 {
178
182 }
183
185 {
187 dummy1 = p1;
189
190 Point dummy2(1, 3, 3, 5);
191 dummy2.partialCopy(
Point(0, 2, 0, 4), {1, 3} );
193
194 Point dummy3(2, 2, 1, 4);
195 dummy3.partialCopyInv(
Point(1, 0, 3, 0), {1, 3} );
197
199 dummy1r = p1;
201
203 dummy2r.partialCopy(
Point(0, 2, 0, 4), {1, 3} );
205
207 dummy3r.partialCopyInv(
Point(1, 0, 3, 0), {1, 3} );
209
210 Point dummy4(1, 3, 3, 5);
213
214 Point dummy5(2, 2, 1, 4);
217 }
218
220 {
221
226
227
240
241
254
255
268
269
282 }
283
284 SECTION(
"Min/Max of vector components")
285 {
288 REQUIRE( *p3.maxElement() == 2.0 );
289 REQUIRE( *p3.minElement() == -2.0 );
290 }
291
297
299 {
305 REQUIRE( normalized[0] == Approx( 0.801784) );
306 REQUIRE( normalized[1] == Approx( -0.267261) );
307 REQUIRE( normalized[2] == Approx( 0.534522) );
308 REQUIRE( normalized[3] == Approx( 0.0) );
309 }
310
311 SECTION(
"PointVector Iterator")
312 {
314 for (unsigned int i=0;i<25;++i)
315 aPoint25[i] = i;
316
317 int sum = 0;
319 sum += (*it);
320
324 }
325
326 SECTION(
"Arithmetical operators with integers")
327 {
332
341
343
348
353 }
354
355 SECTION(
"Other operators with integers")
356 {
361
364
365 REQUIRE( p1.cosineSimilarity(p1) == Approx(0.).margin(0.000001));
366 REQUIRE( p1.cosineSimilarity(-p1) == Approx(pi).margin(0.000001));
367 REQUIRE( p1.cosineSimilarity(
Point(-2,1,-4,3) ) == Approx(pi/2).margin(0.000001) );
371
372 REQUIRE( p1.isLower(p2) ==
false );
374 REQUIRE( p2.isUpper(p1) ==
false );
376 p1[3] = 2;
377 REQUIRE( p1.isLower(p2) ==
true );
379 REQUIRE( p2.isUpper(p1) ==
true );
381 }
382
383 SECTION(
"Arithmetical Operators with reals")
384 {
389
398
400
405
410 }
411
412 SECTION(
"Other operators with reals")
413 {
418
421
422 REQUIRE( p3.cosineSimilarity(p3) == Approx(0.).margin(0.000001) );
423 REQUIRE( p3.cosineSimilarity(-p3) == Approx(pi).margin(0.000001) );
424 REQUIRE( p3.cosineSimilarity(
RealPoint(1.0,1.0,2.0,2.0) ) == Approx(pi/2).margin(0.000001) );
428
429 REQUIRE( p3.isLower(p4) ==
false );
431 REQUIRE( p4.isUpper(p3) ==
false );
433 p4[1] = -p4[1];
434 REQUIRE( p3.isLower(p4) ==
true );
436 REQUIRE( p4.isUpper(p3) ==
true );
438 }
439
440 SECTION(
"Arithmetical Operators with mixed integers/reals")
441 {
450
459
468
473
478 }
479
480 SECTION(
"Other operators with mixed integers/reals")
481 {
490
494
495 REQUIRE( p1.cosineSimilarity(
RealPoint(p1)) == Approx(0.).margin(0.000001) );
496 REQUIRE( p1.cosineSimilarity(-
RealPoint(p1)) == Approx(pi).margin(0.000001) );
497 REQUIRE( p1.cosineSimilarity(
RealPoint(-2,1,-4,3) ) == Approx(pi/2).margin(0.000001) );
501
502 REQUIRE( p3.cosineSimilarity(
Point(1,-1,2,-2)) == Approx(0.).margin(0.000001) );
503 REQUIRE( p3.cosineSimilarity(-
Point(1,-1,2,-2)) == Approx(pi).margin(0.000001) );
504 REQUIRE( p3.cosineSimilarity(
Point(1,1,2,2) ) == Approx(pi/2).margin(0.000001) );
508
509 REQUIRE( p2.isLower(p4) ==
false );
511 REQUIRE( p4.isUpper(p2) ==
false );
513 p4[1] = -p4[1];
514 REQUIRE( p2.isLower(p4) ==
true );
516 REQUIRE( p4.isUpper(p2) ==
true );
518 }
519
520}
521
522
524{
527 Point p1 = {1,2,3,4};
528 Point p2 = {3,4,5,6};
529
530 using Real = double;
532 RPoint rp1 = {1,2,3,4};
533 RPoint rp2 = {3,4,5,6};
534
535 CHECK(p1.dot(p2) == 26);
536 CHECK(rp1.dot(rp2) == Approx(26));
537
539 {
540 return p1.dot(p2);
541 };
542
543 BENCHMARK(
"Dot product double (with int->double cast)")
544 {
545 return rp1.dot(p2);
546 };
547
549 {
550 return rp1.dot(rp2);
551 };
552
553}
554
Aim: Implements basic operations that will be used in Point and Vector classes.
PointVector< dim, double, std::array< double, dim > > getNormalized() const
Container::const_iterator ConstIterator
Constant iterator type.
Point::Coordinate Integer
auto crossProduct(PointVector< 3, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< 3, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Cross product of two 3D Points/Vectors.
DGtal::ArithmeticConversionType< LeftEuclideanRing, RightEuclideanRing > dotProduct(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Dot product between two points/vectors.
bool isUpper(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is upper the second point.
double cosineSimilarity(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Positive angle between two vectors, deduced from their scalar product.
auto inf(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the infimum (or greatest lower bound).
boost::int32_t int32_t
signed 32-bit integer.
auto sup(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs) -> decltype(DGtal::constructFromArithmeticConversion(lhs, rhs))
Implements the supremum (or least upper bound).
bool isLower(PointVector< ptDim, LeftEuclideanRing, LeftContainer > const &lhs, PointVector< ptDim, RightEuclideanRing, RightContainer > const &rhs)
Return true if the first point is below the second point.
Z3i::RealPoint RealPoint3D
Functor that rounds to the nearest integer.
BENCHMARK(BM_StringCreation)
TEST_CASE("2D Point Vector Unit tests")
#define COMPARE_VALUE_AND_TYPE(expr, check)
SECTION("Testing constant forward iterators")
PointVector< 3, double > RealPoint