67 const ForwardIterator& first2,
const ForwardIterator& last2 )
69 ASSERT( first2 != last2 );
72 ForwardIterator start1 = find( first1, last1, *first2 );
91 }
while ( (c1 != cEnd1) && (areEqual) );
104 unsigned int nbok = 0;
111 vector<Point> data, g, res;
113 data.push_back(
Point(2,0) );
114 data.push_back(
Point(4,0) );
115 data.push_back(
Point(0,3) );
116 data.push_back(
Point(0,-4) );
117 data.push_back(
Point(3,4) );
118 data.push_back(
Point(5,0) );
119 data.push_back(
Point(4,3) );
120 data.push_back(
Point(0,5) );
121 data.push_back(
Point(-3,-4) );
122 data.push_back(
Point(-5,0) );
123 data.push_back(
Point(-4,-3) );
124 data.push_back(
Point(0,-5) );
125 data.push_back(
Point(3,-4) );
126 data.push_back(
Point(4,-3) );
127 data.push_back(
Point(-3,4) );
128 data.push_back(
Point(-4,3) );
130 g.push_back(
Point(5,0) );
131 g.push_back(
Point(4,3) );
132 g.push_back(
Point(3,4) );
133 g.push_back(
Point(0,5) );
134 g.push_back(
Point(-3,4) );
135 g.push_back(
Point(-4,3) );
136 g.push_back(
Point(-5,0) );
137 g.push_back(
Point(-4,-3) );
138 g.push_back(
Point(-3,-4) );
139 g.push_back(
Point(0,-5) );
140 g.push_back(
Point(3,-4) );
141 g.push_back(
Point(4,-3) );
147 Predicate predicate( functor );
150 using namespace functions::Hull2D;
153 trace.
info() <<
" andrew algorithm " << std::endl;
154 andrewConvexHullAlgorithm( data.begin(), data.end(), back_inserter( res ), predicate );
156 copy(res.begin(), res.end(), ostream_iterator<Point>( cout,
" " ) );
159 if ( (res.size() == g.size()) &&
163 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
167 trace.
info() <<
" graham algorithm " << std::endl;
169 grahamConvexHullAlgorithm( data.begin(), data.end(), back_inserter( res ), predicate, comparator );
171 copy(res.begin(), res.end(), ostream_iterator<Point>( cout,
" " ) );
174 if ( (res.size() == g.size()) &&
178 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
182 trace.
info() <<
" melkman algorithm " << std::endl;
183 sort( data.begin(), data.end() );
184 melkmanConvexHullAlgorithm( data.begin(), data.end(), back_inserter( res ), functor );
186 copy(res.begin(), res.end(), ostream_iterator<Point>( cout,
" " ) );
189 if ( (res.size() == g.size()) &&
193 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
195 trace.
info() <<
"on line convex hull construction" << std::endl;
197 for(vector<Point>::const_iterator it = data.begin(); it != data.end(); it++)
203 unsigned int cvSize = 0;
210 if(res.size() == cvSize && (cvSize ==
ch.size()))
214 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
216 trace.
info() <<
"test copy and [] operator on convex hull:" << std::endl;
218 unsigned int cvSize2 = 0;
223 if(res.size() == cvSize2 &&
ch[0] == ch2[0])
226 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
231 vector<Point> randomData, res1, res2;
232 const int numberOfPoints = 1000;
233 const int numberOfTries = 50;
235 for (
int i = 0; ( (i < numberOfTries)&&(nbok == nb) ); i++)
241 for (
int j = 0; j < numberOfPoints; j++)
242 randomData.push_back(
Point(rand()%256, rand()%256) );
244 andrewConvexHullAlgorithm( randomData.begin(), randomData.end(), back_inserter( res1 ), predicate );
245 grahamConvexHullAlgorithm( randomData.begin(), randomData.end(), back_inserter( res2 ), predicate, comparator );
247 if ( (res1.size() == res2.size()) &&
248 (
circularlyEqual(res1.begin(), res1.end(), res2.begin(), res2.end())) )
251 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
254 sort( randomData.begin(), randomData.end() );
255 melkmanConvexHullAlgorithm( randomData.begin(), randomData.end(), back_inserter( res2 ), functor );
257 if ( (res1.size() == res2.size()) &&
258 (
circularlyEqual(res1.begin(), res1.end(), res2.begin(), res2.end())) )
261 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
276 unsigned int nbok = 0;
291 Point antipodalP, antipodalQ, antipodalS;
299 antipodalP, antipodalQ, antipodalS);
307 aBoard.
drawLine((*it)[0], (*it)[1], (*(it+1))[0], (*(it+1))[1]);
309 aBoard.
drawLine((*it)[0], (*it)[1], (*(
ch.begin()))[0], (*(
ch.begin()))[1]);
315 aBoard.
drawCircle( antipodalS[0], antipodalS[1], 1.0) ;
317 aBoard.
drawCircle(antipodalP[0], antipodalP[1], 1.0);
318 aBoard.
drawCircle(antipodalQ[0], antipodalQ[1], 1.0);
320 aBoard.
drawLine(antipodalP[0], antipodalP[1], antipodalQ[0], antipodalQ[1]);
324 trace.
info() <<
"Expected Thickness HV = " << awaitedThHV << std::endl;
326 trace.
info() <<
"Expected Euclidean Thickness = " << awaitedThE << std::endl;
327 aBoard.
saveEPS(
"testConvexHull2D_Thickness.eps");
330 std::vector<Z2i::RealPoint> hull {
331 {804.56832227024199, -68.471176393526704},
332 {804.96020257363512, -69.494933490400683},
333 {805.35232247974727, -70.519316530915930},
334 {825.15497274857830, -114.34711249674335},
335 {828.67425867587508, -121.69593677670120},
336 {829.05943325037651, -122.39546351563243},
337 {829.42436256177677, -122.73833140123513},
338 {827.82353937509288, -118.87280445059109},
339 {811.06291230576301, -82.124832029926566},
340 {806.83483124583609, -72.890457996792406},
341 {804.92531970702396, -68.803808853026638},
342 {804.55092650722997, -68.125792709291431},
347 std::rotate(hull.begin(), hull.begin() + 1, hull.end());
350 std::rotate(hull.begin(), hull.begin() + 5, hull.end());
353 trace.
info() <<
"Thickness (before change init point) = " << th << std::endl;
354 trace.
info() <<
"Thickness (after change init point) = " << th2 << std::endl;
355 trace.
info() <<
"Thickness (after change init point) = " << th3 << std::endl;
358 thicknessHVb ==
thicknessHV && abs(th - th2) < 0.000001 &&
359 th - 0.604414 < 0.000001 && abs(th - th3) < 0.000001 ;