40#include "DGtal/base/Common.h"
41#include "DGtal/kernel/PointVector.h"
43#include "DGtalCatch.h"
49#define COMPARE_VALUE_AND_TYPE(expr, check) \
50 REQUIRE( (expr) == (check) ); \
51 REQUIRE( ( std::is_same<decltype(expr)::Component, decltype(check)::Component>::value ) );
65 Real t3[] = {1.5,2.5};
66 Real t4[] = {5.5,4.5};
73 Point3D p1_3d( p1[0], p1[1] );
74 Point3D p2_3d( p2[0], p2[1] );
78 SECTION(
"Cross products with integers")
86 SECTION(
"Cross products with reals")
94 SECTION(
"Cross products with mixed integers/reals")
101 SECTION(
"Access data() of internal container")
103 const auto d = p1_3d.data();
104 CHECK(d[0] == p1[0]);
105 CHECK(d[1] == p1[1]);
119 Real t3[] = {1.5,2.5,3.5};
120 Real t4[] = {5.5,4.5,3.5};
127 SECTION(
"Cross products with integers")
135 SECTION(
"Cross products with reals")
143 SECTION(
"Cross products with mixed integers/reals")
160 const Real pi = std::acos(Real(-1));
164 Real t3[] = {1.0,-1.0,2.0,-2.0};
165 Real t4[] = {5.5,-4.5,3.5,2.5};
191 Point dummy2(1, 3, 3, 5);
192 dummy2.partialCopy(
Point(0, 2, 0, 4), {1, 3} );
195 Point dummy3(2, 2, 1, 4);
196 dummy3.partialCopyInv(
Point(1, 0, 3, 0), {1, 3} );
211 Point dummy4(1, 3, 3, 5);
215 Point dummy5(2, 2, 1, 4);
285 SECTION(
"Min/Max of vector components")
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) );
312 SECTION(
"PointVector Iterator")
315 for (
unsigned int i=0;i<25;++i)
327 SECTION(
"Arithmetical operators with integers")
356 SECTION(
"Other operators with integers")
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) );
373 REQUIRE( p1.isLower(p2) ==
false );
375 REQUIRE( p2.isUpper(p1) ==
false );
378 REQUIRE( p1.isLower(p2) ==
true );
380 REQUIRE( p2.isUpper(p1) ==
true );
384 SECTION(
"Arithmetical Operators with reals")
413 SECTION(
"Other operators with reals")
441 SECTION(
"Arithmetical Operators with mixed integers/reals")
481 SECTION(
"Other operators with mixed integers/reals")
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) );
510 REQUIRE( p2.isLower(p4) ==
false );
515 REQUIRE( p2.isLower(p4) ==
true );
528 Point p1 = {1,2,3,4};
529 Point p2 = {3,4,5,6};
533 RPoint rp1 = {1,2,3,4};
534 RPoint rp2 = {3,4,5,6};
536 CHECK(p1.dot(p2) == 26);
537 CHECK(rp1.dot(rp2) == Approx(26));
544 BENCHMARK(
"Dot product double (with int->double cast)")
Aim: Implements basic operations that will be used in Point and Vector classes.
bool isLower(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is below a given point.
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
Self & partialCopyInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
auto inf(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::inf(*this, aPoint))
Implements the infimum (or greatest lower bound).
auto sup(const PointVector< dim, OtherComponent, OtherStorage > &aPoint) const -> decltype(DGtal::sup(*this, aPoint))
Implements the supremum (or least upper bound).
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
bool isUpper(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is upper a given point.
Container::const_iterator ConstIterator
Constant iterator type.
double cosineSimilarity(const PointVector< dim, OtherComponent, OtherStorage > &v) const
Positive angle between two vectors, deduced from their scalar product.
Self & partialCopy(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
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")
REQUIRE(domain.isInside(aPoint))
PointVector< 3, double > RealPoint