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
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
108
110{
111 using Real = double;
113
116
119 Real t3[] = {1.5,2.5,3.5};
120 Real t4[] = {5.5,4.5,3.5};
121
126
127 SECTION(
"Cross products with integers")
128 {
133 }
134
135 SECTION(
"Cross products with reals")
136 {
141 }
142
143 SECTION(
"Cross products with mixed integers/reals")
144 {
149 }
150}
151
153{
154 using Real = double;
156
159
160 const Real pi = std::acos(Real(-1));
161
164 Real t3[] = {1.0,-1.0,2.0,-2.0};
165 Real t4[] = {5.5,-4.5,3.5,2.5};
166
174
176 {
179
183 }
184
186 {
188 dummy1 = p1;
190
191 Point dummy2(1, 3, 3, 5);
192 dummy2.partialCopy(
Point(0, 2, 0, 4), {1, 3} );
194
195 Point dummy3(2, 2, 1, 4);
196 dummy3.partialCopyInv(
Point(1, 0, 3, 0), {1, 3} );
198
200 dummy1r = p1;
202
204 dummy2r.partialCopy(
Point(0, 2, 0, 4), {1, 3} );
206
208 dummy3r.partialCopyInv(
Point(1, 0, 3, 0), {1, 3} );
210
211 Point dummy4(1, 3, 3, 5);
214
215 Point dummy5(2, 2, 1, 4);
218 }
219
221 {
222
227
228
241
242
255
256
269
270
283 }
284
285 SECTION(
"Min/Max of vector components")
286 {
289 REQUIRE( *p3.maxElement() == 2.0 );
290 REQUIRE( *p3.minElement() == -2.0 );
291 }
292
298
300 {
306 REQUIRE( normalized[0] == Approx( 0.801784) );
307 REQUIRE( normalized[1] == Approx( -0.267261) );
308 REQUIRE( normalized[2] == Approx( 0.534522) );
309 REQUIRE( normalized[3] == Approx( 0.0) );
310 }
311
312 SECTION(
"PointVector Iterator")
313 {
315 for (unsigned int i=0;i<25;++i)
316 aPoint25[i] = i;
317
318 int sum = 0;
320 sum += (*it);
321
325 }
326
327 SECTION(
"Arithmetical operators with integers")
328 {
333
342
344
349
354 }
355
356 SECTION(
"Other operators with integers")
357 {
362
365
366 REQUIRE( p1.cosineSimilarity(p1) == Approx(0.).margin(0.000001));
367 REQUIRE( p1.cosineSimilarity(-p1) == Approx(pi).margin(0.000001));
368 REQUIRE( p1.cosineSimilarity(
Point(-2,1,-4,3) ) == Approx(pi/2).margin(0.000001) );
372
373 REQUIRE( p1.isLower(p2) ==
false );
375 REQUIRE( p2.isUpper(p1) ==
false );
377 p1[3] = 2;
378 REQUIRE( p1.isLower(p2) ==
true );
380 REQUIRE( p2.isUpper(p1) ==
true );
382 }
383
384 SECTION(
"Arithmetical Operators with reals")
385 {
390
399
401
406
411 }
412
413 SECTION(
"Other operators with reals")
414 {
419
422
423 REQUIRE( p3.cosineSimilarity(p3) == Approx(0.).margin(0.000001) );
424 REQUIRE( p3.cosineSimilarity(-p3) == Approx(pi).margin(0.000001) );
425 REQUIRE( p3.cosineSimilarity(
RealPoint(1.0,1.0,2.0,2.0) ) == Approx(pi/2).margin(0.000001) );
429
430 REQUIRE( p3.isLower(p4) ==
false );
432 REQUIRE( p4.isUpper(p3) ==
false );
434 p4[1] = -p4[1];
435 REQUIRE( p3.isLower(p4) ==
true );
437 REQUIRE( p4.isUpper(p3) ==
true );
439 }
440
441 SECTION(
"Arithmetical Operators with mixed integers/reals")
442 {
451
460
469
474
479 }
480
481 SECTION(
"Other operators with mixed integers/reals")
482 {
491
495
496 REQUIRE( p1.cosineSimilarity(
RealPoint(p1)) == Approx(0.).margin(0.000001) );
497 REQUIRE( p1.cosineSimilarity(-
RealPoint(p1)) == Approx(pi).margin(0.000001) );
498 REQUIRE( p1.cosineSimilarity(
RealPoint(-2,1,-4,3) ) == Approx(pi/2).margin(0.000001) );
502
503 REQUIRE( p3.cosineSimilarity(
Point(1,-1,2,-2)) == Approx(0.).margin(0.000001) );
504 REQUIRE( p3.cosineSimilarity(-
Point(1,-1,2,-2)) == Approx(pi).margin(0.000001) );
505 REQUIRE( p3.cosineSimilarity(
Point(1,1,2,2) ) == Approx(pi/2).margin(0.000001) );
509
510 REQUIRE( p2.isLower(p4) ==
false );
512 REQUIRE( p4.isUpper(p2) ==
false );
514 p4[1] = -p4[1];
515 REQUIRE( p2.isLower(p4) ==
true );
517 REQUIRE( p4.isUpper(p2) ==
true );
519 }
520
521}
522
523
525{
528 Point p1 = {1,2,3,4};
529 Point p2 = {3,4,5,6};
530
531 using Real = double;
533 RPoint rp1 = {1,2,3,4};
534 RPoint rp2 = {3,4,5,6};
535
536 CHECK(p1.dot(p2) == 26);
537 CHECK(rp1.dot(rp2) == Approx(26));
538
540 {
541 return p1.dot(p2);
542 };
543
544 BENCHMARK(
"Dot product double (with int->double cast)")
545 {
546 return rp1.dot(p2);
547 };
548
550 {
551 return rp1.dot(rp2);
552 };
553
554}
555
Aim: Implements basic operations that will be used in Point and Vector classes.
Container::const_iterator ConstIterator
Constant iterator type.
Point::Coordinate Integer
std::int32_t int32_t
signed 32-bit 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).
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