DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testAstroid2D.cpp
Go to the documentation of this file.
1
16
31
33
#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
45
typedef
Astroid2D<Space>
Shape
;
46
47
double
notNullValue
(
48
std::uniform_real_distribution<double>& unif,
49
std::default_random_engine& re )
50
{
51
double
res;
52
do
{
53
res = unif(re);
54
}
55
while
( res == Approx(0.) );
56
return
res;
57
}
58
59
RealPoint
notNullRealPoint
(
60
std::uniform_real_distribution<double>& unif,
61
std::default_random_engine& re )
62
{
63
return
RealPoint
(
notNullValue
(unif,re),
notNullValue
(unif,re));
64
}
65
66
TEST_CASE
(
"Astroid2D"
)
67
{
68
std::uniform_real_distribution<double> unif(-10000,10000);
69
std::default_random_engine re;
70
71
SECTION
(
"center()"
)
72
{
73
const
RealPoint
center(unif(re),unif(re));
74
Shape
shape( center, unif(re), unif(re) );
75
REQUIRE
( shape.
center
() == center );
76
}
77
78
SECTION
(
"Lower and upper bounds"
)
79
{
80
Shape
shape( unif(re), unif(re), unif(re), unif(re) );
81
REQUIRE
( shape.
getLowerBound
() <= shape.
getUpperBound
() );
82
}
83
84
SECTION
(
"parameter() with null x-radius -> division by 0."
)
85
{
86
Shape
shape( unif(re), unif(re), 0.,
notNullValue
(unif,re) );
87
REQUIRE_NOTHROW( shape.
parameter
(
notNullRealPoint
(unif,re)) );
88
}
89
90
SECTION
(
"parameter() with null y-radius -> division by 0."
)
91
{
92
Shape
shape( unif(re), unif(re),
notNullValue
(unif,re), 0. );
93
REQUIRE_NOTHROW( shape.
parameter
(
notNullRealPoint
(unif,re)) );
94
}
95
96
SECTION
(
"parameter() with null x-radius and y-radius -> undefined behaviour."
)
97
{
98
Shape
shape( unif(re), unif(re), 0., 0. );
99
REQUIRE_NOTHROW( shape.
parameter
(
notNullRealPoint
(unif,re)) );
100
}
101
102
SECTION
(
"parameter() where (x,y) parameter with x == center -> pi/2 or 3*pi/2"
)
103
{
104
const
double
centerX = unif(re);
105
Shape
shape( centerX, unif(re), unif(re), unif(re) );
106
const
RealPoint
point( centerX, unif(re) );
107
REQUIRE_NOTHROW( shape.
parameter
(point) );
108
double
res = shape.
parameter
(point);
109
REQUIRE_THAT( res, Catch::WithinAbs(M_PI_2,DBL_EPSILON) || Catch::WithinAbs(3*M_PI_2,DBL_EPSILON) );
110
}
111
112
SECTION
(
"parameter() with point parameter with null y -> 0. or pi"
)
113
{
114
const
double
centerY = unif(re);
115
Shape
shape( unif(re), centerY, unif(re), unif(re) );
116
const
RealPoint
point( unif(re), centerY );
117
REQUIRE_NOTHROW( shape.
parameter
(point) );
118
double
res = shape.
parameter
(point);
119
REQUIRE_THAT( res, Catch::WithinAbs(0.,DBL_EPSILON) || Catch::WithinAbs(M_PI,DBL_EPSILON) );
120
}
121
}
DGtal::Astroid2D
Aim: Model of the concept StarShaped represents an astroid.
Definition
Astroid2D.h:62
DGtal::Astroid2D::getLowerBound
RealPoint getLowerBound() const
Definition
Astroid2D.h:122
DGtal::Astroid2D::center
RealPoint center() const
Definition
Astroid2D.h:139
DGtal::Astroid2D::getUpperBound
RealPoint getUpperBound() const
Definition
Astroid2D.h:131
DGtal::Astroid2D::parameter
double parameter(const RealPoint &p) const
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::Z2i::RealPoint
Space::RealPoint RealPoint
Definition
StdDefs.h:97
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
notNullRealPoint
RealPoint notNullRealPoint(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
Definition
testAstroid2D.cpp:59
Shape
Astroid2D< Space > Shape
Definition
testAstroid2D.cpp:45
notNullValue
double notNullValue(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
Definition
testAstroid2D.cpp:47
TEST_CASE
TEST_CASE("int container traits", "[int][traits]")
Definition
testContainerTraits.cpp:53
SECTION
SECTION("Testing constant forward iterators")
Definition
testSimpleRandomAccessRangeFromPoint.cpp:66
REQUIRE
REQUIRE(domain.isInside(aPoint))
tests
shapes
testAstroid2D.cpp
Generated on
for DGtal by
1.18.0