DGtal  1.4.beta
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 
51 using namespace DGtal;
52 using namespace Z2i;
53 
54 
55 typedef AccFlower2D<Space> MyAccFlower;
56 typedef Astroid2D<Space> MyAstroid;
57 typedef Ball2D<Space> MyBall;
58 typedef Ellipse2D<Space> MyEllipse;
59 typedef Flower2D<Space> MyFlower;
60 typedef Lemniscate2D<Space> MyLemniscate;
61 typedef NGon2D<Space> MyNGon;
62 
63 typedef ImplicitBall<Space> BallImplicit;
64 typedef ImplicitHyperCube<Space> HyperCubeImplicit;
65 typedef ImplicitNorm1Ball<Space> Norm1BallImplicit;
66 typedef ImplicitRoundedHyperCube<Space> RoundedHyperCubeImplicit;
67 
68 template<typename Shape>
69 Shape createShape( const RealPoint& center, const RealPoint& radii );
70 
71 template<>
72 MyAccFlower createShape( const RealPoint& center, const RealPoint& radii )
73 {
74  return MyAccFlower( center, radii[0], radii[1], 12, 2. );
75 }
76 
77 template<>
78 MyAstroid createShape( const RealPoint& center, const RealPoint& radii )
79 {
80  return MyAstroid( center, radii[0], radii[1] );
81 }
82 
83 template<>
84 MyBall createShape( const RealPoint& center, const RealPoint& radii )
85 {
86  return MyBall( center, radii[0] );
87 }
88 
89 template<>
90 MyEllipse createShape( const RealPoint& center, const RealPoint& radii )
91 {
92  return MyEllipse( center, radii[0], radii[1], 2. );
93 }
94 
95 template<>
96 MyFlower createShape( const RealPoint& center, const RealPoint& radii )
97 {
98  return MyFlower( center, radii[0], radii[1], 5, 2. );
99 }
100 
101 template<>
102 MyLemniscate createShape( const RealPoint& center, const RealPoint& radii )
103 {
104  return MyLemniscate( center, radii[0] );
105 }
106 
107 template<>
108 MyNGon createShape( const RealPoint& center, const RealPoint& radii )
109 {
110  return MyNGon( center, radii[0], 20, 2. );
111 }
112 
113 template<>
114 BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
115 {
116  return BallImplicit( center, radii[0] );
117 }
118 
119 template<>
120 HyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
121 {
122  return HyperCubeImplicit( center, radii[0] );
123 }
124 
125 template<>
126 Norm1BallImplicit createShape( const RealPoint& center, const RealPoint& radii )
127 {
128  return Norm1BallImplicit( center, radii[0] );
129 }
130 
131 template<>
132 RoundedHyperCubeImplicit createShape( const RealPoint& center, const RealPoint& radii )
133 {
134  return RoundedHyperCubeImplicit( center, radii[0], 3. );
135 }
136 
137 std::uniform_real_distribution<double> unif(-1000000.,1000000.);
138 std::default_random_engine re;
139 
140 TEMPLATE_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 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
TEMPLATE_TEST_CASE("STL Container test", "Description", std::list< int >, std::vector< int >, std::set< int >)
[exampleCatch-example1]
Space::RealPoint RealPoint
Definition: StdDefs.h:97
DGtal is the top-level namespace which contains all DGtal functions and types.
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))