DGtal 1.4.2
Loading...
Searching...
No Matches
testShapeMoveCenter.cpp
Go to the documentation of this file.
1
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31
33#include <iostream>
34#include <random>
35#include "DGtalCatch.h"
36#include "DGtal/helpers/StdDefs.h"
37#include "DGtal/shapes/parametric/AccFlower2D.h"
38#include "DGtal/shapes/parametric/Astroid2D.h"
39#include "DGtal/shapes/parametric/Ball2D.h"
40#include "DGtal/shapes/parametric/Ellipse2D.h"
41#include "DGtal/shapes/parametric/Flower2D.h"
42#include "DGtal/shapes/parametric/Lemniscate2D.h"
43#include "DGtal/shapes/parametric/NGon2D.h"
44#include "DGtal/shapes/implicit/ImplicitBall.h"
45#include "DGtal/shapes/implicit/ImplicitHyperCube.h"
46#include "DGtal/shapes/implicit/ImplicitNorm1Ball.h"
47#include "DGtal/shapes/implicit/ImplicitRoundedHyperCube.h"
48
50
51using namespace DGtal;
52using namespace Z2i;
53
54
55typedef AccFlower2D<Space> MyAccFlower;
56typedef Astroid2D<Space> MyAstroid;
57typedef Ball2D<Space> MyBall;
58typedef Ellipse2D<Space> MyEllipse;
59typedef Flower2D<Space> MyFlower;
60typedef Lemniscate2D<Space> MyLemniscate;
61typedef NGon2D<Space> MyNGon;
62
63typedef ImplicitBall<Space> BallImplicit;
64typedef ImplicitHyperCube<Space> HyperCubeImplicit;
65typedef ImplicitNorm1Ball<Space> Norm1BallImplicit;
66typedef ImplicitRoundedHyperCube<Space> RoundedHyperCubeImplicit;
67
68template<typename Shape>
69Shape createShape( const RealPoint& center, const RealPoint& radii );
70
71template<>
72MyAccFlower createShape( const RealPoint& center, const RealPoint& radii )
73{
74 return MyAccFlower( center, radii[0], radii[1], 12, 2. );
75}
76
77template<>
78MyAstroid createShape( const RealPoint& center, const RealPoint& radii )
79{
80 return MyAstroid( center, radii[0], radii[1] );
81}
82
83template<>
84MyBall createShape( const RealPoint& center, const RealPoint& radii )
85{
86 return MyBall( center, radii[0] );
87}
88
89template<>
90MyEllipse createShape( const RealPoint& center, const RealPoint& radii )
91{
92 return MyEllipse( center, radii[0], radii[1], 2. );
93}
94
95template<>
96MyFlower createShape( const RealPoint& center, const RealPoint& radii )
97{
98 return MyFlower( center, radii[0], radii[1], 5, 2. );
99}
100
101template<>
102MyLemniscate createShape( const RealPoint& center, const RealPoint& radii )
103{
104 return MyLemniscate( center, radii[0] );
105}
106
107template<>
108MyNGon createShape( const RealPoint& center, const RealPoint& radii )
109{
110 return MyNGon( center, radii[0], 20, 2. );
111}
112
113template<>
114BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
115{
116 return BallImplicit( center, radii[0] );
117}
118
119template<>
120HyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
121{
122 return HyperCubeImplicit( center, radii[0] );
123}
124
125template<>
126Norm1BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
127{
128 return Norm1BallImplicit( center, radii[0] );
129}
130
131template<>
132RoundedHyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
133{
134 return RoundedHyperCubeImplicit( center, radii[0], 3. );
135}
136
137std::uniform_real_distribution<double> unif(-1000000.,1000000.);
138std::default_random_engine re;
139
140TEMPLATE_TEST_CASE("Star shapes", "move() method",
141 MyAccFlower, MyAstroid, MyBall, MyEllipse, MyFlower, MyLemniscate, MyNGon,
142 BallImplicit, HyperCubeImplicit, Norm1BallImplicit, RoundedHyperCubeImplicit)
143{
144 const double centerX = unif(re);
145 const double centerY = unif(re);
146 const double radiusX = unif(re);
147 const double radiusY = unif(re);
148
149 TestType shape = createShape<TestType>( RealPoint(centerX, centerY), RealPoint(radiusX, radiusY) );
150
151 SECTION("Center coordinates")
152 {
153 REQUIRE( shape.center() == RealPoint(centerX, centerY) );
154 }
155
156 SECTION("Change center position")
157 {
158 const double newCenterX = unif(re);
159 const double newCenterY = unif(re);
160
161 shape.moveTo( RealPoint( newCenterX, newCenterY ) );
162
163 REQUIRE( shape.center() == RealPoint( newCenterX, newCenterY ) );
164 }
165}
166#endif
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....
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.
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.
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))
PointVector< 3, double > RealPoint