DGtal  1.3.beta
testShapeMoveCenter.cpp
Go to the documentation of this file.
1 
30 #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 }
DGtal::ImplicitHyperCube
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create an hypercube in n...
Definition: ImplicitHyperCube.h:59
Ball
Ball2D< Space > Ball
Definition: testShapeMoveCenter.cpp:58
Flower
Flower2D< Space > Flower
Definition: testShapeMoveCenter.cpp:60
DGtal::Astroid2D< Space >
DGtal::Z2i::Point
Space::Point Point
Definition: StdDefs.h:95
DGtal::ImplicitRoundedHyperCube
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a rounded hypercu...
Definition: ImplicitRoundedHyperCube.h:62
DGtal::AccFlower2D
Aim: Model of the concept StarShaped represents any accelerated flower in the plane.
Definition: AccFlower2D.h:64
re
std::default_random_engine re
Definition: testShapeMoveCenter.cpp:139
Lemniscate
Lemniscate2D< Space > Lemniscate
Definition: testShapeMoveCenter.cpp:61
REQUIRE
REQUIRE(domain.isInside(aPoint))
DGtal::Z2i::RealPoint
Space::RealPoint RealPoint
Definition: StdDefs.h:97
DGtal::Ball2D
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:60
DGtal::SpaceND< 2, Integer >
AccFlower
AccFlower2D< Space > AccFlower
Definition: testShapeMoveCenter.cpp:56
DGtal::NGon2D
Aim: Model of the concept StarShaped represents any regular k-gon in the plane.
Definition: NGon2D.h:63
DGtal::ImplicitNorm1Ball
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball for the L_...
Definition: ImplicitNorm1Ball.h:59
HyperCubeImplicit
ImplicitHyperCube< Space > HyperCubeImplicit
Definition: testShapeMoveCenter.cpp:65
BallImplicit
ImplicitBall< Space > BallImplicit
Definition: testShapeMoveCenter.cpp:64
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Astroid
Astroid2D< Space > Astroid
Definition: testShapeMoveCenter.cpp:57
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:64
DGtal::Z2i::Space
SpaceND< 2, Integer > Space
Definition: StdDefs.h:75
RoundedHyperCubeImplicit
ImplicitRoundedHyperCube< Space > RoundedHyperCubeImplicit
Definition: testShapeMoveCenter.cpp:67
unif
std::uniform_real_distribution< double > unif(-1000000., 1000000.)
Norm1BallImplicit
ImplicitNorm1Ball< Space > Norm1BallImplicit
Definition: testShapeMoveCenter.cpp:66
DGtal::Ellipse2D
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
DGtal::PointVector< dim, Integer >
SECTION
SECTION("Testing constant forward iterators")
Definition: testSimpleRandomAccessRangeFromPoint.cpp:66
Ellipse
Ellipse2D< Space > Ellipse
Definition: testShapeMoveCenter.cpp:59
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
NGon
NGon2D< Space > NGon
Definition: testShapeMoveCenter.cpp:62
createShape
Shape createShape(const RealPoint &center, const RealPoint &radii)
Definition: testShapeMoveCenter.cpp:73
DGtal::Lemniscate2D
Aim: Model of the concept StarShaped represents a lemniscate.
Definition: Lemniscate2D.h:61
TEMPLATE_TEST_CASE
TEMPLATE_TEST_CASE("Star shapes", "move() method", AccFlower, Astroid, Ball, Ellipse, Flower, Lemniscate, NGon, BallImplicit, HyperCubeImplicit, Norm1BallImplicit, RoundedHyperCubeImplicit)
Definition: testShapeMoveCenter.cpp:141