DGtal 1.3.0
Loading...
Searching...
No Matches
testShapeMoveCenter.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <random>
33#include "DGtalCatch.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/shapes/parametric/AccFlower2D.h"
36#include "DGtal/shapes/parametric/Astroid2D.h"
37#include "DGtal/shapes/parametric/Ball2D.h"
38#include "DGtal/shapes/parametric/Ellipse2D.h"
39#include "DGtal/shapes/parametric/Flower2D.h"
40#include "DGtal/shapes/parametric/Lemniscate2D.h"
41#include "DGtal/shapes/parametric/NGon2D.h"
42#include "DGtal/shapes/implicit/ImplicitBall.h"
43#include "DGtal/shapes/implicit/ImplicitHyperCube.h"
44#include "DGtal/shapes/implicit/ImplicitNorm1Ball.h"
45#include "DGtal/shapes/implicit/ImplicitRoundedHyperCube.h"
46
48
49using namespace DGtal;
50using namespace Z2i;
51
55
63
68
69template<typename Shape>
70Shape createShape( const RealPoint& center, const RealPoint& radii );
71
72template<>
73AccFlower createShape( const RealPoint& center, const RealPoint& radii )
74{
75 return AccFlower( center, radii[0], radii[1], 12, 2. );
76}
77
78template<>
79Astroid createShape( const RealPoint& center, const RealPoint& radii )
80{
81 return Astroid( center, radii[0], radii[1] );
82}
83
84template<>
85Ball createShape( const RealPoint& center, const RealPoint& radii )
86{
87 return Ball( center, radii[0] );
88}
89
90template<>
91Ellipse createShape( const RealPoint& center, const RealPoint& radii )
92{
93 return Ellipse( center, radii[0], radii[1], 2. );
94}
95
96template<>
97Flower createShape( const RealPoint& center, const RealPoint& radii )
98{
99 return Flower( center, radii[0], radii[1], 5, 2. );
100}
101
102template<>
103Lemniscate createShape( const RealPoint& center, const RealPoint& radii )
104{
105 return Lemniscate( center, radii[0] );
106}
107
108template<>
109NGon createShape( const RealPoint& center, const RealPoint& radii )
110{
111 return NGon( center, radii[0], 20, 2. );
112}
113
114template<>
115BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
116{
117 return BallImplicit( center, radii[0] );
118}
119
120template<>
121HyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
122{
123 return HyperCubeImplicit( center, radii[0] );
124}
125
126template<>
127Norm1BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
128{
129 return Norm1BallImplicit( center, radii[0] );
130}
131
132template<>
134{
135 return RoundedHyperCubeImplicit( center, radii[0], 3. );
136}
137
138std::uniform_real_distribution<double> unif(-1000000.,1000000.);
139std::default_random_engine re;
140
141TEMPLATE_TEST_CASE("Star shapes", "move() method",
144{
145 const double centerX = unif(re);
146 const double centerY = unif(re);
147 const double radiusX = unif(re);
148 const double radiusY = unif(re);
149
150 TestType shape = createShape<TestType>( RealPoint(centerX, centerY), RealPoint(radiusX, radiusY) );
151
152 SECTION("Center coordinates")
153 {
154 REQUIRE( shape.center() == RealPoint(centerX, centerY) );
155 }
156
157 SECTION("Change center position")
158 {
159 const double newCenterX = unif(re);
160 const double newCenterY = unif(re);
161
162 shape.moveTo( RealPoint( newCenterX, newCenterY ) );
163
164 REQUIRE( shape.center() == RealPoint( newCenterX, newCenterY ) );
165 }
166}
Aim: Model of the concept StarShaped represents any accelerated flower in the plane.
Definition: AccFlower2D.h:65
Aim: Model of the concept StarShaped represents an astroid.
Definition: Astroid2D.h:62
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:61
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:65
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:65
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create an hypercube in n...
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball for the L_...
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a rounded hypercu...
Aim: Model of the concept StarShaped represents a lemniscate.
Definition: Lemniscate2D.h:62
Aim: Model of the concept StarShaped represents any regular k-gon in the plane.
Definition: NGon2D.h:64
DGtal is the top-level namespace which contains all DGtal functions and types.
Z2i::Space Space
Z2i::Point Point
std::default_random_engine re
std::uniform_real_distribution< double > unif(-1000000., 1000000.)
Ellipse2D< Space > Ellipse
Astroid2D< Space > Astroid
ImplicitHyperCube< Space > HyperCubeImplicit
Shape createShape(const RealPoint &center, const RealPoint &radii)
Ball2D< Space > Ball
AccFlower2D< Space > AccFlower
NGon2D< Space > NGon
ImplicitNorm1Ball< Space > Norm1BallImplicit
TEMPLATE_TEST_CASE("Star shapes", "move() method", AccFlower, Astroid, Ball, Ellipse, Flower, Lemniscate, NGon, BallImplicit, HyperCubeImplicit, Norm1BallImplicit, RoundedHyperCubeImplicit)
Lemniscate2D< Space > Lemniscate
Flower2D< Space > Flower
Z2i::RealPoint RealPoint
ImplicitBall< Space > BallImplicit
ImplicitRoundedHyperCube< Space > RoundedHyperCubeImplicit
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))