]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/iterators/point_iterator.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / iterators / point_iterator.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2016, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
11
12
13 #ifndef BOOST_TEST_MODULE
14 #define BOOST_TEST_MODULE test_point_iterator
15 #endif
16
17 #include <cstddef>
18 #include <iostream>
19 #include <string>
20 #include <iterator>
21 #include <algorithm>
22
23 #include <boost/test/included/unit_test.hpp>
24
25 #include <boost/assign/list_of.hpp>
26 #include <boost/concept_check.hpp>
27 #include <boost/core/ignore_unused.hpp>
28 #include <boost/iterator/iterator_concepts.hpp>
29 #include <boost/tuple/tuple.hpp>
30 #include <boost/type_traits/is_const.hpp>
31 #include <boost/optional.hpp>
32 #include <boost/type_traits/is_reference.hpp>
33
34 #include <boost/geometry/core/point_type.hpp>
35
36 #include <boost/geometry/geometries/geometries.hpp>
37 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
38 #include <boost/geometry/geometries/register/linestring.hpp>
39 #include <boost/geometry/geometries/register/multi_point.hpp>
40
41 #include <boost/geometry/algorithms/equals.hpp>
42 #include <boost/geometry/algorithms/make.hpp>
43 #include <boost/geometry/algorithms/num_points.hpp>
44
45 #include <boost/geometry/policies/compare.hpp>
46
47 #include <boost/geometry/util/condition.hpp>
48
49 #include <boost/geometry/io/wkt/wkt.hpp>
50 #include <boost/geometry/io/dsv/write.hpp>
51
52 #include <boost/geometry/iterators/point_iterator.hpp>
53 #include <boost/geometry/iterators/point_reverse_iterator.hpp>
54
55 #include <test_common/with_pointer.hpp>
56 #include <test_geometries/copy_on_dereference_geometries.hpp>
57
58 namespace bg = ::boost::geometry;
59 namespace ba = ::boost::assign;
60
61 typedef bg::model::point<double, 2, bg::cs::cartesian> point_type;
62 typedef bg::model::point<double, 3, bg::cs::cartesian> point_type_3d;
63 typedef bg::model::linestring<point_type> linestring_type;
64 typedef bg::model::polygon<point_type, false, false> polygon_type; //ccw, open
65
66 // multi geometries
67 typedef bg::model::multi_point<point_type> multi_point_type;
68 typedef bg::model::multi_point<point_type_3d> multi_point_type_3d;
69 typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
70 typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
71
72 typedef boost::tuple<double, double> tuple_point_type;
73 typedef boost::tuple<double, double, double> tuple_point_type_3d;
74 typedef std::vector<tuple_point_type> tuple_multi_point_type;
75 typedef std::vector<tuple_point_type_3d> tuple_multi_point_type_3d;
76
77 template <typename T>
78 struct vector_as_multipoint : std::vector<T> {};
79
80 template <typename T>
81 struct vector_as_linestring : std::vector<T> {};
82
83 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
84 BOOST_GEOMETRY_REGISTER_MULTI_POINT(tuple_multi_point_type)
85 BOOST_GEOMETRY_REGISTER_MULTI_POINT(tuple_multi_point_type_3d)
86
87 BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED(vector_as_multipoint)
88 BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(vector_as_linestring)
89
90
91
92 template <typename Geometry>
93 inline Geometry from_wkt(std::string const& wkt)
94 {
95 Geometry geometry;
96 boost::geometry::read_wkt(wkt, geometry);
97 return geometry;
98 }
99
100
101 // this function is implemented because std::max_element() requires ForwardIterator
102 // but bg::point_iterator<> is InputIterator since it returns non-true reference
103 template <typename InputIt, typename Pred>
104 inline boost::optional<typename std::iterator_traits<InputIt>::value_type>
105 max_value(InputIt first, InputIt last, Pred pred)
106 {
107 typedef typename std::iterator_traits<InputIt>::value_type value_type;
108 if (first != last)
109 {
110 value_type found = *first++;
111 for (; first != last; )
112 {
113 value_type current = *first++;
114 if (pred(current, found))
115 found = current;
116 }
117 return found;
118 }
119 return boost::none;
120 }
121
122
123 template <typename Iterator>
124 inline std::ostream& print_point_range(std::ostream& os,
125 Iterator first,
126 Iterator beyond,
127 std::string const& header)
128 {
129 os << header << "(";
130 for (Iterator it = first; it != beyond; ++it)
131 {
132 os << " " << bg::dsv(*it);
133 }
134 os << " )";
135 return os;
136 }
137
138
139 template
140 <
141 typename Geometry,
142 bool Enable = true,
143 bool IsConst = boost::is_const<Geometry>::value
144 >
145 struct test_iterator_concepts
146 {
147 typedef bg::point_iterator<Geometry> iterator;
148 BOOST_CONCEPT_ASSERT((boost::BidirectionalIteratorConcept<iterator>));
149 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<iterator>));
150 BOOST_CONCEPT_ASSERT((boost_concepts::LvalueIteratorConcept<iterator>));
151 BOOST_CONCEPT_ASSERT
152 ((boost_concepts::BidirectionalTraversalConcept<iterator>));
153 };
154
155 template <typename Geometry>
156 struct test_iterator_concepts<Geometry, true, false>
157 : test_iterator_concepts<Geometry, true, true>
158 {
159 typedef bg::point_iterator<Geometry> iterator;
160 BOOST_CONCEPT_ASSERT
161 ((boost::Mutable_BidirectionalIteratorConcept<iterator>));
162 BOOST_CONCEPT_ASSERT
163 ((boost_concepts::WritableIteratorConcept<iterator>));
164 BOOST_CONCEPT_ASSERT
165 ((boost_concepts::SwappableIteratorConcept<iterator>));
166 };
167
168 template <typename Geometry, bool IsConst>
169 struct test_iterator_concepts<Geometry, false, IsConst>
170 {};
171
172
173
174 struct equals
175 {
176 template <typename Iterator>
177 static inline std::size_t number_of_elements(Iterator begin,
178 Iterator end)
179 {
180 std::size_t size = std::distance(begin, end);
181
182 std::size_t num_elems(0);
183 for (Iterator it = begin; it != end; ++it)
184 {
185 ++num_elems;
186 }
187 BOOST_CHECK(size == num_elems);
188
189 num_elems = 0;
190 for (Iterator it = end; it != begin; --it)
191 {
192 ++num_elems;
193 }
194 BOOST_CHECK(size == num_elems);
195
196 return num_elems;
197 }
198
199 template <typename Iterator1, typename Iterator2>
200 static inline bool apply(Iterator1 begin1, Iterator1 end1,
201 Iterator2 begin2, Iterator2 end2)
202 {
203 std::size_t num_points1 = number_of_elements(begin1, end1);
204 std::size_t num_points2 = number_of_elements(begin2, end2);
205
206 if (num_points1 != num_points2)
207 {
208 return false;
209 }
210
211 Iterator1 it1 = begin1;
212 Iterator2 it2 = begin2;
213 for (; it1 != end1; ++it1, ++it2)
214 {
215 if (! bg::equals(*it1, *it2))
216 {
217 return false;
218 }
219 }
220 return true;
221 }
222 };
223
224
225 template <bool Enable = true>
226 struct test_assignment
227 {
228 template <typename Iterator, typename ConstIterator, typename Value>
229 static inline void apply(Iterator it, ConstIterator cit,
230 Value const& value1, Value const& value2)
231 {
232 #ifdef BOOST_GEOMETRY_TEST_DEBUG
233 std::cout << "== before assignment ==" << std::endl;
234 std::cout << "value1: " << bg::wkt(value1) << std::endl;
235 std::cout << "value2: " << bg::wkt(value2) << std::endl;
236 std::cout << "*it : " << bg::wkt(*it) << std::endl;
237 std::cout << "*cit : " << bg::wkt(*cit) << std::endl;
238 #endif
239
240 BOOST_CHECK(bg::equals(*it, value1));
241 BOOST_CHECK(! bg::equals(*it, value2));
242 BOOST_CHECK(bg::equals(*cit, value1));
243 BOOST_CHECK(! bg::equals(*cit, value2));
244
245 *it = value2;
246 BOOST_CHECK(bg::equals(*it, value2));
247 BOOST_CHECK(! bg::equals(*it, value1));
248 BOOST_CHECK(bg::equals(*cit, value2));
249 BOOST_CHECK(! bg::equals(*cit, value1));
250
251 #ifdef BOOST_GEOMETRY_TEST_DEBUG
252 std::cout << "== after 1st assignment ==" << std::endl;
253 std::cout << "value1: " << bg::wkt(value1) << std::endl;
254 std::cout << "value2: " << bg::wkt(value2) << std::endl;
255 std::cout << "*it : " << bg::wkt(*it) << std::endl;
256 std::cout << "*cit : " << bg::wkt(*cit) << std::endl;
257 #endif
258
259 *it = value1;
260 BOOST_CHECK(bg::equals(*it, value1));
261 BOOST_CHECK(! bg::equals(*it, value2));
262 BOOST_CHECK(bg::equals(*cit, value1));
263 BOOST_CHECK(! bg::equals(*cit, value2));
264
265 #ifdef BOOST_GEOMETRY_TEST_DEBUG
266 std::cout << "== after 2nd assignment ==" << std::endl;
267 std::cout << "value1: " << bg::wkt(value1) << std::endl;
268 std::cout << "value2: " << bg::wkt(value2) << std::endl;
269 std::cout << "*it : " << bg::wkt(*it) << std::endl;
270 std::cout << "*cit : " << bg::wkt(*cit) << std::endl;
271 std::cout << std::endl;
272 #endif
273 }
274 };
275
276 template <>
277 struct test_assignment<false>
278 {
279 template <typename Iterator, typename ConstIterator, typename Value>
280 static inline void apply(Iterator, ConstIterator,
281 Value const&, Value const&)
282 {
283 }
284 };
285
286
287 template
288 <
289 typename Geometry,
290 typename PointRange,
291 bool EnableConceptChecks = true
292 >
293 struct test_point_iterator_of_geometry
294 {
295 typedef typename bg::point_type<Geometry>::type point_type;
296
297 template <typename G>
298 static inline void base_test(G& geometry,
299 PointRange const& point_range,
300 std::string const& header)
301 {
302 typedef bg::point_iterator<G> point_iterator;
303
304 test_iterator_concepts<G, EnableConceptChecks>();
305
306 point_iterator begin = bg::points_begin(geometry);
307 point_iterator end = bg::points_end(geometry);
308
309 BOOST_CHECK(std::size_t(std::distance(begin, end))
310 ==
311 bg::num_points(geometry));
312
313 BOOST_CHECK(equals::apply(begin, end,
314 bg::points_begin(point_range),
315 bg::points_end(point_range))
316 );
317
318 boost::ignore_unused(header);
319
320 #ifdef BOOST_GEOMETRY_TEST_DEBUG
321 std::cout << header << " geometry: " << bg::wkt(geometry) << std::endl;
322 print_point_range(std::cout, begin, end, "point range: ");
323 std::cout << std::endl;
324
325 typedef bg::point_iterator<PointRange const> point_range_iterator;
326
327 print_point_range(std::cout,
328 bg::points_begin(point_range),
329 bg::points_end(point_range),
330 "expected point range: ");
331 std::cout << std::endl;
332 #endif
333 }
334
335 template <typename G, bool Enable>
336 struct test_reverse
337 {
338 template <typename Iterator>
339 static inline void apply(Iterator first, Iterator last,
340 G const& geometry)
341 {
342 std::reverse(first, last);
343 #ifdef BOOST_GEOMETRY_TEST_DEBUG
344 print_point_range(std::cout, first, last, "reversed:\n")
345 << std::endl;
346 std::cout << bg::wkt(geometry) << std::endl;
347 std::cout << std::endl;
348 #endif
349
350 std::reverse(first, last);
351 #ifdef BOOST_GEOMETRY_TEST_DEBUG
352 print_point_range(std::cout, first, last, "re-reversed:\n")
353 << std::endl;
354 std::cout << bg::wkt(geometry) << std::endl;
355 std::cout << std::endl;
356 std::cout << std::endl;
357 #endif
358 }
359 };
360
361 template <typename G>
362 struct test_reverse<G, false>
363 {
364 template <typename Iterator>
365 static inline void apply(Iterator, Iterator, G const&)
366 {
367 }
368 };
369
370 static inline void apply(Geometry geometry,
371 PointRange const& point_range,
372 point_type const& zero_point)
373 {
374 base_test<Geometry>(geometry, point_range, "non-const");
375
376 #ifdef BOOST_GEOMETRY_TEST_DEBUG
377 std::cout << std::endl;
378 #endif
379
380 base_test<Geometry const>(geometry, point_range, "const");
381
382 #ifdef BOOST_GEOMETRY_TEST_DEBUG
383 std::cout << std::endl << std::endl;
384 #endif
385
386 // testing construction of const and non-const iterator
387 typedef bg::point_iterator<Geometry> point_iterator;
388 typedef bg::point_iterator<Geometry const> const_point_iterator;
389
390 point_iterator begin = bg::points_begin(geometry);
391 point_iterator end = bg::points_end(geometry);
392
393 const_point_iterator const_begin = bg::points_begin(geometry);
394 const_point_iterator const_end = bg::points_end(geometry);
395
396 // same for reverse iterator
397 typedef bg::point_reverse_iterator<Geometry> point_reverse_iterator;
398 typedef bg::point_reverse_iterator
399 <
400 Geometry const
401 > const_point_reverse_iterator;
402
403 point_reverse_iterator rbegin = bg::points_rbegin(geometry);
404 point_reverse_iterator rend = bg::points_rend(geometry);
405
406 const_point_reverse_iterator const_rbegin = bg::points_rbegin(geometry);
407 const_point_reverse_iterator const_rend = bg::points_rend(geometry);
408
409 // testing assignment of non-const to const iterator
410 const_begin = begin;
411 const_end = end;
412
413 // testing assignment of non-const to const reverse_iterator
414 const_rbegin = rbegin;
415 const_rend = rend;
416
417 // testing equality/inequality comparison
418 BOOST_CHECK(begin == const_begin);
419 BOOST_CHECK(end == const_end);
420 if (begin != end)
421 {
422 BOOST_CHECK(begin != const_end);
423 BOOST_CHECK(const_begin != end);
424 }
425
426 // testing equality/inequality comparison for reverse_iterator
427 BOOST_CHECK(rbegin == const_rbegin);
428 BOOST_CHECK(rend == const_rend);
429 if (rbegin != rend)
430 {
431 BOOST_CHECK(rbegin != const_rend);
432 BOOST_CHECK(const_rbegin != rend);
433 }
434
435 if (begin != end)
436 {
437 BOOST_CHECK(rbegin != rend);
438
439 point_reverse_iterator rlast(rend);
440 --rlast;
441 BOOST_CHECK(bg::equals(*begin, *rlast));
442
443 point_iterator last(end);
444 --last;
445 BOOST_CHECK(bg::equals(*rbegin, *last));
446 }
447
448 // testing dereferencing/assignment
449
450 bool const is_reference = boost::is_reference
451 <
452 typename std::iterator_traits<point_iterator>::reference
453 >::value;
454
455 if (begin != end)
456 {
457 if (BOOST_GEOMETRY_CONDITION(is_reference))
458 {
459 point_type p = *begin;
460 point_type q = zero_point;
461
462 test_assignment<is_reference>::apply(begin, const_begin, p, q);
463
464 *begin = q;
465 test_assignment<is_reference>::apply(begin, const_begin, q, p);
466
467 *begin = p;
468 }
469 }
470
471 // test with algorithms
472 #ifdef BOOST_GEOMETRY_TEST_DEBUG
473 print_point_range(std::cout, begin, end, "original:\n") << std::endl;
474 print_point_range(std::cout, rbegin, rend, "reverse traversal:\n")
475 << std::endl;
476 std::cout << bg::wkt(geometry) << std::endl;
477 std::cout << std::endl;
478 #endif
479 test_reverse<Geometry, is_reference>::apply(begin, end, geometry);
480
481 typedef typename std::iterator_traits
482 <
483 point_iterator
484 >::value_type point;
485 if (const_begin != const_end)
486 {
487 boost::optional<point>
488 pt_max = max_value(const_begin, const_end, bg::less<point>());
489
490 BOOST_CHECK(bool(pt_max)); // to avoid warnings
491 #ifdef BOOST_GEOMETRY_TEST_DEBUG
492 std::cout << "max point: " << bg::dsv(*pt_max) << std::endl;
493 #endif
494 }
495 #ifdef BOOST_GEOMETRY_TEST_DEBUG
496 std::cout << std::endl;
497 std::cout << std::endl;
498 std::cout << std::endl;
499 #endif
500 }
501
502 static inline void apply(Geometry geometry, PointRange const& point_range)
503 {
504 apply(geometry, point_range, bg::make_zero<point_type>());
505 }
506 };
507
508
509 //======================================================================
510 //======================================================================
511
512
513 BOOST_AUTO_TEST_CASE( test_linestring_point_iterator )
514 {
515 #ifdef BOOST_GEOMETRY_TEST_DEBUG
516 std::cout << "*** LINESTRING ***" << std::endl;
517 #endif
518
519 typedef tuple_multi_point_type TMP;
520 typedef linestring_type L;
521
522 typedef test_point_iterator_of_geometry<L, TMP> tester;
523
524 tester::apply(from_wkt<L>("LINESTRING()"),
525 TMP()
526 );
527
528 tester::apply(from_wkt<L>("LINESTRING(3 3,4 4,5 5)"),
529 ba::tuple_list_of(3,3)(4,4)(5,5)
530 );
531
532 #ifdef BOOST_GEOMETRY_TEST_DEBUG
533 std::cout << std::endl << std::endl << std::endl;
534 #endif
535 }
536
537
538 //======================================================================
539 //======================================================================
540
541
542 BOOST_AUTO_TEST_CASE( test_polygon_point_iterator )
543 {
544 #ifdef BOOST_GEOMETRY_TEST_DEBUG
545 std::cout << "*** POLYGON ***" << std::endl;
546 #endif
547
548 typedef tuple_multi_point_type TMP;
549 typedef polygon_type P;
550
551 typedef test_point_iterator_of_geometry<P, TMP> tester;
552
553 tester::apply(from_wkt<P>("POLYGON()"),
554 TMP()
555 );
556
557 tester::apply(from_wkt<P>("POLYGON(())"),
558 TMP()
559 );
560
561 tester::apply(from_wkt<P>("POLYGON((1 1,9 1,9 9,1 9),(5 5,6 5,6 6,5 6))"),
562 ba::tuple_list_of(1,1)(9,1)(9,9)(1,9)(5,5)(6,5)(6,6)(5,6)
563 );
564
565 tester::apply(from_wkt<P>("POLYGON((3 3,4 4,5 5),(),(),(),(6 6,7 7,8 8),(),(),(9 9),())"),
566 ba::tuple_list_of(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)
567 );
568
569 tester::apply(from_wkt<P>("POLYGON((),(3 3,4 4,5 5),(),(),(6 6,7 7,8 8),(),(),(9 9),())"),
570 ba::tuple_list_of(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)
571 );
572
573 #ifdef BOOST_GEOMETRY_TEST_DEBUG
574 std::cout << std::endl << std::endl;
575 #endif
576 }
577
578
579 //======================================================================
580 //======================================================================
581
582
583 BOOST_AUTO_TEST_CASE( test_multipoint_point_iterator )
584 {
585 #ifdef BOOST_GEOMETRY_TEST_DEBUG
586 std::cout << "*** MULTIPOINT ***" << std::endl;
587 #endif
588
589 typedef tuple_multi_point_type TMP;
590 typedef multi_point_type MP;
591
592 typedef test_point_iterator_of_geometry<MP, TMP> tester;
593
594 tester::apply(from_wkt<MP>("MULTIPOINT()"),
595 TMP()
596 );
597
598 tester::apply(from_wkt<MP>("MULTIPOINT(3 3,4 4,5 5)"),
599 ba::tuple_list_of(3,3)(4,4)(5,5)
600 );
601
602 #ifdef BOOST_GEOMETRY_TEST_DEBUG
603 std::cout << std::endl << std::endl << std::endl;
604 #endif
605 }
606
607
608 //======================================================================
609 //======================================================================
610
611
612 BOOST_AUTO_TEST_CASE( test_multipoint_3d_point_iterator )
613 {
614 #ifdef BOOST_GEOMETRY_TEST_DEBUG
615 std::cout << "*** MULTIPOINT 3D ***" << std::endl;
616 #endif
617
618 typedef tuple_multi_point_type_3d TMP;
619 typedef multi_point_type_3d MP;
620
621 typedef test_point_iterator_of_geometry<MP, TMP> tester;
622
623 tester::apply(from_wkt<MP>("MULTIPOINT()"),
624 TMP()
625 );
626
627 tester::apply(from_wkt<MP>("MULTIPOINT(3 3 3,4 4 4,5 5 5)"),
628 ba::tuple_list_of(3,3,3)(4,4,4)(5,5,5)
629 );
630
631 #ifdef BOOST_GEOMETRY_TEST_DEBUG
632 std::cout << std::endl << std::endl << std::endl;
633 #endif
634 }
635
636
637 //======================================================================
638 //======================================================================
639
640
641 BOOST_AUTO_TEST_CASE( test_multilinestring_point_iterator )
642 {
643 #ifdef BOOST_GEOMETRY_TEST_DEBUG
644 std::cout << "*** MULTILINESTRING ***" << std::endl;
645 #endif
646
647 typedef tuple_multi_point_type TMP;
648 typedef multi_linestring_type ML;
649
650 typedef test_point_iterator_of_geometry<ML, TMP> tester;
651
652 tester::apply(from_wkt<ML>("MULTILINESTRING()"),
653 TMP()
654 );
655
656 tester::apply(from_wkt<ML>("MULTILINESTRING(())"),
657 TMP()
658 );
659
660 tester::apply(from_wkt<ML>("MULTILINESTRING((),(),())"),
661 TMP()
662 );
663
664 tester::apply(from_wkt<ML>("MULTILINESTRING((1 1,2 2,3 3),(3 3,4 4,5 5),(6 6))"),
665 ba::tuple_list_of(1,1)(2,2)(3,3)(3,3)(4,4)(5,5)(6,6)
666 );
667
668 tester::apply(from_wkt<ML>("MULTILINESTRING((),(),(1 1,2 2,3 3),(),(),(3 3,4 4,5 5),(),(6 6),(),(),())"),
669 ba::tuple_list_of(1,1)(2,2)(3,3)(3,3)(4,4)(5,5)(6,6)
670 );
671
672 #ifdef BOOST_GEOMETRY_TEST_DEBUG
673 std::cout << std::endl << std::endl;
674 #endif
675 }
676
677
678 //======================================================================
679 //======================================================================
680
681
682 BOOST_AUTO_TEST_CASE( test_multipolygon_point_iterator )
683 {
684 #ifdef BOOST_GEOMETRY_TEST_DEBUG
685 std::cout << "*** MULTIPOLYGON ***" << std::endl;
686 #endif
687
688 typedef tuple_multi_point_type TMP;
689 typedef multi_polygon_type MPL;
690
691 typedef test_point_iterator_of_geometry<MPL, TMP> tester;
692
693 tester::apply(from_wkt<MPL>("MULTIPOLYGON()"),
694 TMP()
695 );
696
697 tester::apply(from_wkt<MPL>("MULTIPOLYGON( () )"),
698 TMP()
699 );
700
701 tester::apply(from_wkt<MPL>("MULTIPOLYGON( (()) )"),
702 TMP()
703 );
704
705 tester::apply(from_wkt<MPL>("MULTIPOLYGON( ((),()) )"),
706 TMP()
707 );
708
709 tester::apply(from_wkt<MPL>("MULTIPOLYGON(((3 3,4 4,5 5),(6 6,7 7,8 8),(9 9)),((1 1,2 2,10 10),(11 11,12 12)))"),
710 ba::tuple_list_of(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)\
711 (1,1)(2,2)(10,10)(11,11)(12,12)
712 );
713
714 tester::apply(from_wkt<MPL>("MULTIPOLYGON(((3 3,4 4,5 5),(),(),(),(6 6,7 7,8 8),(),(),(9 9),()),((),(1 1,2 2,10 10),(),(),(),(11 11,12 12),(),(),(13 13),()))"),
715 ba::tuple_list_of(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)\
716 (1,1)(2,2)(10,10)(11,11)(12,12)(13,13)
717 );
718
719 tester::apply(from_wkt<MPL>("MULTIPOLYGON(((3 3,4 4,5 5),(),(),(),(6 6,7 7,8 8),(),(),(9 9),()),((),(1 1,2 2,10 10),(),(),(),(11 11,12 12),(),(),(13 13),()),((),(),()))"),
720 ba::tuple_list_of(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)\
721 (1,1)(2,2)(10,10)(11,11)(12,12)(13,13)
722 );
723
724 #ifdef BOOST_GEOMETRY_TEST_DEBUG
725 std::cout << std::endl << std::endl;
726 #endif
727 }
728
729
730 //======================================================================
731 //======================================================================
732
733
734 BOOST_AUTO_TEST_CASE( test_multipoint_of_point_pointers )
735 {
736 #ifdef BOOST_GEOMETRY_TEST_DEBUG
737 std::cout << "*** MULTIPOINT OF POINT POINTERS ***" << std::endl;
738 #endif
739
740 typedef tuple_multi_point_type TMP;
741 typedef vector_as_multipoint<test::test_point_xy*> MP;
742
743 MP multipoint;
744 for (int i = 1; i < 10; i++)
745 {
746 test::test_point_xy* p = new test::test_point_xy;
747 p->x = i;
748 p->y = -i;
749 multipoint.push_back(p);
750 }
751
752 test::test_point_xy* zero = new test::test_point_xy;
753 zero->x = 0;
754 zero->y = 0;
755
756 typedef test_point_iterator_of_geometry<MP, TMP> tester;
757
758 tester::apply(multipoint,
759 ba::tuple_list_of(1,-1)(2,-2)(3,-3)(4,-4)(5,-5)(6,-6)\
760 (7,-7)(8,-8)(9,-9),
761 zero
762 );
763
764 for (unsigned int i = 0; i < multipoint.size(); i++)
765 {
766 delete multipoint[i];
767 }
768 delete zero;
769 }
770
771
772 //======================================================================
773 //======================================================================
774
775
776 BOOST_AUTO_TEST_CASE( test_linestring_of_point_pointers )
777 {
778 #ifdef BOOST_GEOMETRY_TEST_DEBUG
779 std::cout << "*** LINESTRING OF POINT POINTERS ***" << std::endl;
780 #endif
781
782 typedef tuple_multi_point_type TMP;
783 typedef vector_as_linestring<test::test_point_xy*> L;
784
785 L linestring;
786 for (int i = 1; i < 10; i++)
787 {
788 test::test_point_xy* p = new test::test_point_xy;
789 p->x = i;
790 p->y = -i;
791 linestring.push_back(p);
792 }
793
794 test::test_point_xy* zero = new test::test_point_xy;
795 zero->x = 0;
796 zero->y = 0;
797
798 typedef test_point_iterator_of_geometry<L, TMP> tester;
799
800 tester::apply(linestring,
801 ba::tuple_list_of(1,-1)(2,-2)(3,-3)(4,-4)(5,-5)(6,-6)\
802 (7,-7)(8,-8)(9,-9),
803 zero
804 );
805
806 for (unsigned int i = 0; i < linestring.size(); i++)
807 {
808 delete linestring[i];
809 }
810 delete zero;
811 }
812
813
814 //======================================================================
815 //======================================================================
816
817
818 BOOST_AUTO_TEST_CASE( test_multipoint_copy_on_dereference )
819 {
820 #ifdef BOOST_GEOMETRY_TEST_DEBUG
821 std::cout << "*** MULTIPOINT WITH COPY-ON-DEREFERENCE ITERATOR ***"
822 << std::endl;
823 #endif
824
825 typedef tuple_multi_point_type TMP;
826 typedef multipoint_copy_on_dereference<point_type> MP;
827
828 typedef test_point_iterator_of_geometry
829 <
830 MP, TMP, false // no concept checks
831 > tester;
832
833 // bg::read_wkt does not work for this multipoint type so we have
834 // to initialize the multipoint manually
835 MP multipoint;
836 for (int i = 1; i < 10; ++i)
837 {
838 multipoint.push_back(point_type(i, -i));
839 }
840
841 tester::apply(multipoint,
842 // from_wkt<MP>("MULTIPOINT(1 -1,2 -2,3 -3,4 -4,5 -5,6 -6, 7 -7,8 -8,9 -9)"),
843 ba::tuple_list_of(1,-1)(2,-2)(3,-3)(4,-4)(5,-5)(6,-6)\
844 (7,-7)(8,-8)(9,-9)
845 );
846 }
847
848
849 //======================================================================
850 //======================================================================
851
852
853 BOOST_AUTO_TEST_CASE( test_linestring_copy_on_dereference )
854 {
855 #ifdef BOOST_GEOMETRY_TEST_DEBUG
856 std::cout << "*** LINESTRING WITH COPY-ON-DEREFERENCE ITERATOR ***"
857 << std::endl;
858 #endif
859
860 typedef tuple_multi_point_type TMP;
861 typedef linestring_copy_on_dereference<point_type> L;
862
863 typedef test_point_iterator_of_geometry
864 <
865 L, TMP, false // no concept checks
866 > tester;
867
868 tester::apply(from_wkt<L>("LINESTRING(1 -1,2 -2,3 -3,4 -4,5 -5,6 -6, 7 -7,8 -8,9 -9)"),
869 ba::tuple_list_of(1,-1)(2,-2)(3,-3)(4,-4)(5,-5)(6,-6)\
870 (7,-7)(8,-8)(9,-9)
871 );
872 }