DGtal  1.5.beta
testPolarPointComparatorBy2x2DetComputer.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/geometry/tools/PolarPointComparatorBy2x2DetComputer.h"
Include dependency graph for testPolarPointComparatorBy2x2DetComputer.cpp:

Go to the source code of this file.

Functions

bool testPolarPointComparatorBy2x2DetComputer ()
 
bool testSort ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/12/04

Functions for testing class PolarPointComparatorBy2x2DetComputer.

This file is part of the DGtal library.

Definition in file testPolarPointComparatorBy2x2DetComputer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 258 of file testPolarPointComparatorBy2x2DetComputer.cpp.

259 {
260  trace.beginBlock ( "Testing class PolarPointComparatorBy2x2DetComputer" );
261  trace.info() << "Args:";
262  for ( int i = 0; i < argc; ++i )
263  trace.info() << " " << argv[ i ];
264  trace.info() << endl;
265 
267  && testSort();
268 
269  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
270  trace.endBlock();
271  return res ? 0 : 1;
272 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testPolarPointComparatorBy2x2DetComputer()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testPolarPointComparatorBy2x2DetComputer(), testSort(), and DGtal::trace.

◆ testPolarPointComparatorBy2x2DetComputer()

bool testPolarPointComparatorBy2x2DetComputer ( )

Definition at line 47 of file testPolarPointComparatorBy2x2DetComputer.cpp.

48 {
49  unsigned int nbok = 0;
50  unsigned int nb = 0;
51 
52  trace.beginBlock ( "Testing block ..." );
53 
55 
56  Point origin(0,0);
58  trace.info() << comp << endl;
59 
60  //same half-plane
61  trace.info() << "same half-plane" << endl;
62  if ( comp( Point(2,1), Point(1,2) ) )
63  nbok++;
64  nb++;
65  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
66 
67  if ( ! comp( Point(1,2), Point(2,1) ) )
68  nbok++;
69  nb++;
70  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
71 
72  if ( comp( Point(2,1), Point(-1,2) ) )
73  nbok++;
74  nb++;
75  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
76 
77  if ( comp( Point(1,-2), Point(2,-1) ) )
78  nbok++;
79  nb++;
80  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
81 
82  //different half-plane
83  trace.info() << "different half-plane" << endl;
84  if ( comp( Point(1,2), Point(2,-1) ) )
85  nbok++;
86  nb++;
87  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
88 
89  if ( ! comp( Point(2,-1), Point(1,2) ) )
90  nbok++;
91  nb++;
92  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
93 
94  //y-coordinate equal to 0
95  trace.info() << "y-coordinate == 0" << endl;
96  if ( comp( Point(1,0), Point(3,3) ) )
97  nbok++;
98  nb++;
99  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
100 
101  if ( ! comp( Point(3,3), Point(1,0) ) )
102  nbok++;
103  nb++;
104  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
105 
106  if ( comp( Point(3,3), Point(-1,0) ) )
107  nbok++;
108  nb++;
109  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
110 
111  if ( comp( Point(1,0), Point(3,-3) ) )
112  nbok++;
113  nb++;
114  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
115 
116  //aligned
117  trace.info() << "aligned points" << endl;
118  if ( ! comp( Point(3,3), Point(1,1) ) )
119  nbok++;
120  nb++;
121  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
122 
123  if ( comp( Point(1,1), Point(3,3) ) )
124  nbok++;
125  nb++;
126  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
127 
128  if ( ! comp( Point(-3,-3), Point(1,1) ) )
129  nbok++;
130  nb++;
131  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
132 
133  //y-coordinate equal to 0 AND aligned
134  trace.info() << "aligned points on the horizontal axis" << endl;
135  if ( comp( Point(1,0), Point(5,0) ) )
136  nbok++;
137  nb++;
138  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
139 
140  if ( ! comp( Point(5,0), Point(1,0) ) )
141  nbok++;
142  nb++;
143  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
144 
145  if ( comp( Point(1,0), Point(-5,0) ) )
146  nbok++;
147  nb++;
148  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
149 
150  if ( comp( Point(5,0), Point(-5,0) ) )
151  nbok++;
152  nb++;
153  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
154 
155  if ( ! comp( Point(-5,0), Point(5,0) ) )
156  nbok++;
157  nb++;
158  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
159 
160  if ( comp( Point(-1,0), Point(-5,0) ) )
161  nbok++;
162  nb++;
163  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
164 
165  //degenerated
166  trace.info() << "point equality" << endl;
167  if ( comp( Point(0,0), Point(3,3) ) )
168  nbok++;
169  nb++;
170  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
171 
172  if ( comp( Point(0,0), Point(-3,-3) ) )
173  nbok++;
174  nb++;
175  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
176 
177  if ( ! comp( Point(2,1), Point(2,1) ) )
178  nbok++;
179  nb++;
180  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
181 
182  trace.endBlock();
183 
184  return nbok == nb;
185 }
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: Class that implements a binary point predicate, which is able to compare the position of two giv...
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testSort()

bool testSort ( )

Definition at line 190 of file testPolarPointComparatorBy2x2DetComputer.cpp.

191 {
192  unsigned int nbok = 0;
193  unsigned int nb = 0;
194 
195  trace.beginBlock ( "Testing block ..." );
196 
198  Point origin(0,0);
199 
200  std::vector<Point> g, v;
201  //data
202  v.push_back( Point(3,4) );
203  v.push_back( Point(5,0) );
204  v.push_back( Point(4,3) );
205  v.push_back( Point(0,5) );
206  v.push_back( Point(-3,-4) );
207  v.push_back( Point(-5,0) );
208  v.push_back( Point(-4,-3) );
209  v.push_back( Point(0,-5) );
210  v.push_back( Point(3,-4) );
211  v.push_back( Point(4,-3) );
212  v.push_back( Point(-3,4) );
213  v.push_back( Point(-4,3) );
214  //ground truth
215  g.push_back( Point(5,0) );
216  g.push_back( Point(4,3) );
217  g.push_back( Point(3,4) );
218  g.push_back( Point(0,5) );
219  g.push_back( Point(-3,4) );
220  g.push_back( Point(-4,3) );
221  g.push_back( Point(-5,0) );
222  g.push_back( Point(-4,-3) );
223  g.push_back( Point(-3,-4) );
224  g.push_back( Point(0,-5) );
225  g.push_back( Point(3,-4) );
226  g.push_back( Point(4,-3) );
227 
228  //sort
230  std::sort(v.begin(), v.end(), comp);
231  std::copy(v.begin(), v.end(), ostream_iterator<Point>( std::cout, " " ) );
232  std::cout << std::endl;
233 
234  if ( std::equal(v.begin(), v.end(), g.begin()) )
235  nbok++;
236  nb++;
237  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
238 
239  //with a different pole
240  comp.setPole( Point(5,0) );
241  std::sort(v.begin(), v.end(), comp);
242  std::copy(v.begin(), v.end(), ostream_iterator<Point>( std::cout, " " ) );
243  std::cout << std::endl;
244 
245  if ( std::equal(v.begin(), v.end(), g.begin()) )
246  nbok++;
247  nb++;
248  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
249 
250  trace.endBlock();
251 
252  return nbok == nb;
253 }

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::functors::PolarPointComparatorBy2x2DetComputer< TPoint, TDetComputer >::setPole(), and DGtal::trace.

Referenced by main().