DGtal  1.2.0
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 
49 using namespace DGtal;
50 using namespace Z2i;
51 
52 typedef Z2i::Space Space;
53 typedef Z2i::Point Point;
55 
63 
68 
69 template<typename Shape>
70 Shape createShape( const RealPoint& center, const RealPoint& radii );
71 
72 template<>
73 AccFlower createShape( const RealPoint& center, const RealPoint& radii )
74 {
75  return AccFlower( center, radii[0], radii[1], 12, 2. );
76 }
77 
78 template<>
79 Astroid createShape( const RealPoint& center, const RealPoint& radii )
80 {
81  return Astroid( center, radii[0], radii[1] );
82 }
83 
84 template<>
85 Ball createShape( const RealPoint& center, const RealPoint& radii )
86 {
87  return Ball( center, radii[0] );
88 }
89 
90 template<>
91 Ellipse createShape( const RealPoint& center, const RealPoint& radii )
92 {
93  return Ellipse( center, radii[0], radii[1], 2. );
94 }
95 
96 template<>
97 Flower createShape( const RealPoint& center, const RealPoint& radii )
98 {
99  return Flower( center, radii[0], radii[1], 5, 2. );
100 }
101 
102 template<>
103 Lemniscate createShape( const RealPoint& center, const RealPoint& radii )
104 {
105  return Lemniscate( center, radii[0] );
106 }
107 
108 template<>
109 NGon createShape( const RealPoint& center, const RealPoint& radii )
110 {
111  return NGon( center, radii[0], 20, 2. );
112 }
113 
114 template<>
115 BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
116 {
117  return BallImplicit( center, radii[0] );
118 }
119 
120 template<>
121 HyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
122 {
123  return HyperCubeImplicit( center, radii[0] );
124 }
125 
126 template<>
127 Norm1BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
128 {
129  return Norm1BallImplicit( center, radii[0] );
130 }
131 
132 template<>
133 RoundedHyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
134 {
135  return RoundedHyperCubeImplicit( center, radii[0], 3. );
136 }
137 
138 std::uniform_real_distribution<double> unif(-1000000.,1000000.);
139 std::default_random_engine re;
140 
141 TEMPLATE_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 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
Space::RealPoint RealPoint
Definition: StdDefs.h:97
SpaceND< 2, Integer > Space
Definition: StdDefs.h:75
Space::Point Point
Definition: StdDefs.h:95
DGtal is the top-level namespace which contains all DGtal functions and types.
std::default_random_engine re
Ellipse2D< Space > Ellipse
Astroid2D< Space > Astroid
ImplicitHyperCube< Space > HyperCubeImplicit
Shape createShape(const RealPoint &center, const RealPoint &radii)
Ball2D< Space > Ball
std::uniform_real_distribution< double > unif(-1000000., 1000000.)
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
ImplicitBall< Space > BallImplicit
ImplicitRoundedHyperCube< Space > RoundedHyperCubeImplicit
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))