DGtal  1.1.0
testAstroid2D.cpp
Go to the documentation of this file.
1 
32 #include <iostream>
34 #include <random>
35 #include "DGtalCatch.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/shapes/parametric/Astroid2D.h"
38 
40 
41 using namespace DGtal;
42 using namespace Z2i;
43 
44 typedef Z2i::Space Space;
45 typedef Z2i::Point Point;
47 
49 
50 double notNullValue(
51  std::uniform_real_distribution<double>& unif,
52  std::default_random_engine& re )
53 {
54  double res;
55  do {
56  res = unif(re);
57  }
58  while ( res == Approx(0.) );
59  return res;
60 }
61 
63  std::uniform_real_distribution<double>& unif,
64  std::default_random_engine& re )
65 {
67 }
68 
69 TEST_CASE("Astroid2D")
70 {
71  std::uniform_real_distribution<double> unif(-10000,10000);
72  std::default_random_engine re;
73 
74  SECTION("center()")
75  {
76  const RealPoint center(unif(re),unif(re));
77  Shape shape( center, unif(re), unif(re) );
78  REQUIRE( shape.center() == center );
79  }
80 
81  SECTION("Lower and upper bounds")
82  {
83  Shape shape( unif(re), unif(re), unif(re), unif(re) );
84  REQUIRE( shape.getLowerBound() <= shape.getUpperBound() );
85  }
86 
87  SECTION("parameter() with null x-radius -> division by 0.")
88  {
89  Shape shape( unif(re), unif(re), 0., notNullValue(unif,re) );
90  REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
91  }
92 
93  SECTION("parameter() with null y-radius -> division by 0.")
94  {
95  Shape shape( unif(re), unif(re), notNullValue(unif,re), 0. );
96  REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
97  }
98 
99  SECTION("parameter() with null x-radius and y-radius -> undefined behaviour.")
100  {
101  Shape shape( unif(re), unif(re), 0., 0. );
102  REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
103  }
104 
105  SECTION("parameter() where (x,y) parameter with x == center -> pi/2 or 3*pi/2")
106  {
107  const double centerX = unif(re);
108  Shape shape( centerX, unif(re), unif(re), unif(re) );
109  const RealPoint point( centerX, unif(re) );
110  REQUIRE_NOTHROW( shape.parameter(point) );
111  double res = shape.parameter(point);
112  REQUIRE_THAT( res, Catch::WithinAbs(M_PI_2,DBL_EPSILON) || Catch::WithinAbs(3*M_PI_2,DBL_EPSILON) );
113  }
114 
115  SECTION("parameter() with point parameter with null y -> 0. or pi")
116  {
117  const double centerY = unif(re);
118  Shape shape( unif(re), centerY, unif(re), unif(re) );
119  const RealPoint point( unif(re), centerY );
120  REQUIRE_NOTHROW( shape.parameter(point) );
121  double res = shape.parameter(point);
122  REQUIRE_THAT( res, Catch::WithinAbs(0.,DBL_EPSILON) || Catch::WithinAbs(M_PI,DBL_EPSILON) );
123  }
124 }
DGtal::Astroid2D< Space >
notNullValue
double notNullValue(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
Definition: testAstroid2D.cpp:50
DGtal::Z2i::Point
Space::Point Point
Definition: StdDefs.h:95
re
std::default_random_engine re
Definition: testShapeMoveCenter.cpp:139
DGtal::Astroid2D::getLowerBound
RealPoint getLowerBound() const
Definition: Astroid2D.h:122
TEST_CASE
TEST_CASE("Astroid2D")
Definition: testAstroid2D.cpp:69
REQUIRE
REQUIRE(domain.isInside(aPoint))
DGtal::Z2i::RealPoint
Space::RealPoint RealPoint
Definition: StdDefs.h:97
notNullRealPoint
RealPoint notNullRealPoint(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
Definition: testAstroid2D.cpp:62
DGtal::SpaceND< 2, Integer >
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::Z2i::Space
SpaceND< 2, Integer > Space
Definition: StdDefs.h:75
DGtal::Astroid2D::parameter
double parameter(const RealPoint &p) const
unif
std::uniform_real_distribution< double > unif(-1000000., 1000000.)
Shape
Astroid2D< Space > Shape
Definition: testAstroid2D.cpp:48
DGtal::PointVector< dim, Integer >
SECTION
SECTION("Testing constant forward iterators")
Definition: testSimpleRandomAccessRangeFromPoint.cpp:66
DGtal::Astroid2D::center
RealPoint center() const
Definition: Astroid2D.h:139
DGtal::Astroid2D::getUpperBound
RealPoint getUpperBound() const
Definition: Astroid2D.h:131