File: point_iterator.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (874 lines) | stat: -rw-r--r-- 26,518 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html


#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_point_iterator
#endif

#include <cstddef>
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>

#include <boost/test/included/unit_test.hpp>

#include <boost/concept_check.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/optional.hpp>

#include <boost/geometry/algorithms/equals.hpp>
#include <boost/geometry/algorithms/make.hpp>
#include <boost/geometry/algorithms/num_points.hpp>

#include <boost/geometry/core/point_type.hpp>

#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/geometry/geometries/register/linestring.hpp>
#include <boost/geometry/geometries/register/multi_point.hpp>

#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/io/dsv/write.hpp>

#include <boost/geometry/iterators/point_iterator.hpp>
#include <boost/geometry/iterators/point_reverse_iterator.hpp>

#include <boost/geometry/policies/compare.hpp>

#include <boost/geometry/strategies/strategies.hpp>

#include <boost/geometry/util/condition.hpp>

#include <test_common/with_pointer.hpp>
#include <test_geometries/copy_on_dereference_geometries.hpp>


namespace bg = ::boost::geometry;

typedef bg::model::point<double, 2, bg::cs::cartesian> point_type;
typedef bg::model::point<double, 3, bg::cs::cartesian> point_type_3d;
typedef bg::model::linestring<point_type> linestring_type;
typedef bg::model::polygon<point_type, false, false> polygon_type; //ccw, open

// multi geometries
typedef bg::model::multi_point<point_type> multi_point_type;
typedef bg::model::multi_point<point_type_3d> multi_point_type_3d;
typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;

typedef boost::tuple<double, double> tuple_point_type;
typedef boost::tuple<double, double, double> tuple_point_type_3d;
typedef std::vector<tuple_point_type> tuple_multi_point_type;
typedef std::vector<tuple_point_type_3d> tuple_multi_point_type_3d;

template <typename T>
struct vector_as_multipoint : std::vector<T> {};

template <typename T>
struct vector_as_linestring : std::vector<T> {};

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_MULTI_POINT(tuple_multi_point_type)
BOOST_GEOMETRY_REGISTER_MULTI_POINT(tuple_multi_point_type_3d)

BOOST_GEOMETRY_REGISTER_MULTI_POINT_TEMPLATED(vector_as_multipoint)
BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(vector_as_linestring)



template <typename Geometry>
inline Geometry from_wkt(std::string const& wkt)
{
    Geometry geometry;
    bg::read_wkt(wkt, geometry);
    return geometry;
}


// this function is implemented because std::max_element() requires ForwardIterator
// but bg::point_iterator<> is InputIterator since it returns non-true reference
template <typename InputIt, typename Pred>
inline boost::optional<typename std::iterator_traits<InputIt>::value_type>
max_value(InputIt first, InputIt last, Pred pred)
{
    typedef typename std::iterator_traits<InputIt>::value_type value_type;
    if (first != last)
    {
        value_type found = *first++;
        for (; first != last; )
        {
            value_type current = *first++;
            if (pred(current, found))
                found = current;
        }
        return found;
    }
    return boost::none;
}


template <typename Iterator>
inline std::ostream& print_point_range(std::ostream& os,
                                       Iterator first,
                                       Iterator beyond,
                                       std::string const& header)
{
    os << header << "(";
    for (Iterator it = first; it != beyond; ++it)
    {
        os << " " << bg::dsv(*it);
    }
    os << " )";
    return os;
}


template
<
    typename Geometry,
    bool Enable = true,
    bool IsConst = std::is_const<Geometry>::value
>
struct test_iterator_concepts
{
    typedef bg::point_iterator<Geometry> iterator;
    BOOST_CONCEPT_ASSERT((boost::BidirectionalIteratorConcept<iterator>));
    BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIteratorConcept<iterator>));
    BOOST_CONCEPT_ASSERT((boost_concepts::LvalueIteratorConcept<iterator>));
    BOOST_CONCEPT_ASSERT
        ((boost_concepts::BidirectionalTraversalConcept<iterator>));
};

template <typename Geometry>
struct test_iterator_concepts<Geometry, true, false>
    : test_iterator_concepts<Geometry, true, true>
{
    typedef bg::point_iterator<Geometry> iterator;
    BOOST_CONCEPT_ASSERT
        ((boost::Mutable_BidirectionalIteratorConcept<iterator>));
    BOOST_CONCEPT_ASSERT
        ((boost_concepts::WritableIteratorConcept<iterator>));
    BOOST_CONCEPT_ASSERT
        ((boost_concepts::SwappableIteratorConcept<iterator>));
};

template <typename Geometry, bool IsConst>
struct test_iterator_concepts<Geometry, false, IsConst>
{};



struct equals
{
    template <typename Iterator>
    static inline std::size_t number_of_elements(Iterator begin,
                                                 Iterator end)
    {
        std::size_t size = std::distance(begin, end);

        std::size_t num_elems(0);
        for (Iterator it = begin; it != end; ++it)
        {
            ++num_elems;
        }
        BOOST_CHECK(size == num_elems);

        num_elems = 0;
        for (Iterator it = end; it != begin; --it)
        {
            ++num_elems;
        }
        BOOST_CHECK(size == num_elems);

        return num_elems;
    }

    template <typename Iterator1, typename Iterator2>
    static inline bool apply(Iterator1 begin1, Iterator1 end1,
                             Iterator2 begin2, Iterator2 end2)
    {
        std::size_t num_points1 = number_of_elements(begin1, end1);
        std::size_t num_points2 = number_of_elements(begin2, end2);

        if (num_points1 != num_points2)
        {
            return false;
        }

        Iterator1 it1 = begin1;
        Iterator2 it2 = begin2;
        for (; it1 != end1; ++it1, ++it2)
        {
            if (! bg::equals(*it1, *it2))
            {
                return false;
            }
        }
        return true;
    }
};


template <bool Enable = true>
struct test_assignment
{
    template <typename Iterator, typename ConstIterator, typename Value>
    static inline void apply(Iterator it, ConstIterator cit,
                             Value const& value1, Value const& value2)
    {
#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << "== before assignment ==" << std::endl;
        std::cout << "value1: " << bg::wkt(value1) << std::endl;
        std::cout << "value2: " << bg::wkt(value2) << std::endl;
        std::cout << "*it   : " << bg::wkt(*it) << std::endl;
        std::cout << "*cit  : " << bg::wkt(*cit) << std::endl;
#endif

        BOOST_CHECK(bg::equals(*it, value1));
        BOOST_CHECK(! bg::equals(*it, value2));
        BOOST_CHECK(bg::equals(*cit, value1));
        BOOST_CHECK(! bg::equals(*cit, value2));

        *it = value2;
        BOOST_CHECK(bg::equals(*it, value2));
        BOOST_CHECK(! bg::equals(*it, value1));
        BOOST_CHECK(bg::equals(*cit, value2));
        BOOST_CHECK(! bg::equals(*cit, value1));

#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << "== after 1st assignment ==" << std::endl;
        std::cout << "value1: " << bg::wkt(value1) << std::endl;
        std::cout << "value2: " << bg::wkt(value2) << std::endl;
        std::cout << "*it   : " << bg::wkt(*it) << std::endl;
        std::cout << "*cit  : " << bg::wkt(*cit) << std::endl;
#endif

        *it = value1;
        BOOST_CHECK(bg::equals(*it, value1));
        BOOST_CHECK(! bg::equals(*it, value2));
        BOOST_CHECK(bg::equals(*cit, value1));
        BOOST_CHECK(! bg::equals(*cit, value2));

#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << "== after 2nd assignment ==" << std::endl;
        std::cout << "value1: " << bg::wkt(value1) << std::endl;
        std::cout << "value2: " << bg::wkt(value2) << std::endl;
        std::cout << "*it   : " << bg::wkt(*it) << std::endl;
        std::cout << "*cit  : " << bg::wkt(*cit) << std::endl;
        std::cout << std::endl;
#endif
    }
};

template <>
struct test_assignment<false>
{
    template <typename Iterator, typename ConstIterator, typename Value>
    static inline void apply(Iterator, ConstIterator,
                             Value const&, Value const&)
    {
    }
};


template
<
    typename Geometry,
    typename PointRange,
    bool EnableConceptChecks = true
>
struct test_point_iterator_of_geometry
{
    typedef typename bg::point_type<Geometry>::type point_type;

    template <typename G>
    static inline void base_test(G& geometry,
                                 PointRange const& point_range,
                                 std::string const& header)
    {
        typedef bg::point_iterator<G> point_iterator;

        test_iterator_concepts<G, EnableConceptChecks>();

        point_iterator begin = bg::points_begin(geometry);
        point_iterator end = bg::points_end(geometry);

        BOOST_CHECK(std::size_t(std::distance(begin, end))
                    ==
                    bg::num_points(geometry));

        BOOST_CHECK(equals::apply(begin, end,
                                  bg::points_begin(point_range),
                                  bg::points_end(point_range))
                    );

        boost::ignore_unused(header);

#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << header << " geometry: " << bg::wkt(geometry) << std::endl;
        print_point_range(std::cout, begin, end, "point range: ");
        std::cout << std::endl;

        typedef bg::point_iterator<PointRange const> point_range_iterator;

        print_point_range(std::cout,
                          bg::points_begin(point_range),
                          bg::points_end(point_range),
                          "expected point range: ");
        std::cout << std::endl;
#endif
    }

    template <typename G, bool Enable>
    struct test_reverse
    {
        template <typename Iterator>
        static inline void apply(Iterator first, Iterator last,
                                 G const& geometry)
        {
            boost::ignore_unused(geometry);

            std::reverse(first, last);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
            print_point_range(std::cout, first, last, "reversed:\n")
                << std::endl;
            std::cout << bg::wkt(geometry) << std::endl;
            std::cout << std::endl;
#endif

            std::reverse(first, last);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
            print_point_range(std::cout, first, last, "re-reversed:\n")
                << std::endl;
            std::cout << bg::wkt(geometry) << std::endl;
            std::cout << std::endl;
            std::cout << std::endl;
#endif
        }
    };

    template <typename G>
    struct test_reverse<G, false>
    {
        template <typename Iterator>
        static inline void apply(Iterator, Iterator, G const&)
        {
        }
    };

    static inline void apply(Geometry geometry,
                             PointRange const& point_range,
                             point_type const& zero_point)
    {
        base_test<Geometry>(geometry, point_range, "non-const");

#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << std::endl;
#endif

        base_test<Geometry const>(geometry, point_range, "const");

#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << std::endl << std::endl;
#endif

        // testing construction of const and non-const iterator
        typedef bg::point_iterator<Geometry> point_iterator;
        typedef bg::point_iterator<Geometry const> const_point_iterator;

        point_iterator begin = bg::points_begin(geometry);
        point_iterator end = bg::points_end(geometry);

        const_point_iterator const_begin = bg::points_begin(geometry);
        const_point_iterator const_end = bg::points_end(geometry);

        // same for reverse iterator
        typedef bg::point_reverse_iterator<Geometry> point_reverse_iterator;
        typedef bg::point_reverse_iterator
            <
                Geometry const
            > const_point_reverse_iterator;

        point_reverse_iterator rbegin = bg::points_rbegin(geometry);
        point_reverse_iterator rend = bg::points_rend(geometry);

        const_point_reverse_iterator const_rbegin = bg::points_rbegin(geometry);
        const_point_reverse_iterator const_rend = bg::points_rend(geometry);

        // testing assignment of non-const to const iterator
        const_begin = begin;
        const_end = end;

        // testing assignment of non-const to const reverse_iterator
        const_rbegin = rbegin;
        const_rend = rend;

        // testing equality/inequality comparison
        BOOST_CHECK(begin == const_begin);
        BOOST_CHECK(end == const_end);
        if (begin != end)
        {
            BOOST_CHECK(begin != const_end);
            BOOST_CHECK(const_begin != end);
        }

        // testing equality/inequality comparison for reverse_iterator
        BOOST_CHECK(rbegin == const_rbegin);
        BOOST_CHECK(rend == const_rend);
        if (rbegin != rend)
        {
            BOOST_CHECK(rbegin != const_rend);
            BOOST_CHECK(const_rbegin != rend);
        }

        if (begin != end)
        {
            BOOST_CHECK(rbegin != rend);

            point_reverse_iterator rlast(rend);
            --rlast;
            BOOST_CHECK(bg::equals(*begin, *rlast));

            point_iterator last(end);
            --last;
            BOOST_CHECK(bg::equals(*rbegin, *last));
        }
        
        // testing dereferencing/assignment

        bool const is_reference = std::is_reference
            <
                typename std::iterator_traits<point_iterator>::reference
            >::value;

        if (begin != end)
        {
            if (BOOST_GEOMETRY_CONDITION(is_reference))
            {
                point_type p = *begin;
                point_type q = zero_point;

                test_assignment<is_reference>::apply(begin, const_begin, p, q);

                *begin = q;
                test_assignment<is_reference>::apply(begin, const_begin, q, p);

                *begin = p;
            }
        }

        // test with algorithms
#ifdef BOOST_GEOMETRY_TEST_DEBUG
        print_point_range(std::cout, begin, end, "original:\n") << std::endl;
        print_point_range(std::cout, rbegin, rend, "reverse traversal:\n")
            << std::endl;
        std::cout << bg::wkt(geometry) << std::endl;
        std::cout << std::endl;
#endif
        test_reverse<Geometry, is_reference>::apply(begin, end, geometry);

        typedef typename std::iterator_traits
            <
                point_iterator
            >::value_type point;
        if (const_begin != const_end)
        {
            boost::optional<point>
                pt_max = max_value(const_begin, const_end, bg::less<point>());
            
            BOOST_CHECK(bool(pt_max)); // to avoid warnings
#ifdef BOOST_GEOMETRY_TEST_DEBUG
            std::cout << "max point: " << bg::dsv(*pt_max) << std::endl;
#endif
        }
#ifdef BOOST_GEOMETRY_TEST_DEBUG
        std::cout << std::endl;
        std::cout << std::endl;
        std::cout << std::endl;
#endif
    }

    static inline void apply(Geometry geometry, PointRange const& point_range)
    {
        apply(geometry, point_range, bg::make_zero<point_type>());
    }
};


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_linestring_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** LINESTRING ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef linestring_type L;

    typedef test_point_iterator_of_geometry<L, TMP> tester;

    tester::apply(from_wkt<L>("LINESTRING()"),
                  TMP()
                  );

    tester::apply(from_wkt<L>("LINESTRING(3 3,4 4,5 5)"),
                  TMP{{3,3},{4,4},{5,5}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_polygon_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** POLYGON ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef polygon_type P;

    typedef test_point_iterator_of_geometry<P, TMP> tester;

    tester::apply(from_wkt<P>("POLYGON()"),
                  TMP()
                  );

    tester::apply(from_wkt<P>("POLYGON(())"),
                  TMP()
                  );

    tester::apply(from_wkt<P>("POLYGON((1 1,9 1,9 9,1 9),(5 5,6 5,6 6,5 6))"),
                  TMP{{1,1},{9,1},{9,9},{1,9},{5,5},{6,5},{6,6},{5,6}}
                  );

    tester::apply(from_wkt<P>("POLYGON((3 3,4 4,5 5),(),(),(),(6 6,7 7,8 8),(),(),(9 9),())"),
                  TMP{{3,3},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9}}
                  );

    tester::apply(from_wkt<P>("POLYGON((),(3 3,4 4,5 5),(),(),(6 6,7 7,8 8),(),(),(9 9),())"),
                  TMP{{3,3},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multipoint_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTIPOINT ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef multi_point_type MP;

    typedef test_point_iterator_of_geometry<MP, TMP> tester;

    tester::apply(from_wkt<MP>("MULTIPOINT()"),
                  TMP()
                  );

    tester::apply(from_wkt<MP>("MULTIPOINT(3 3,4 4,5 5)"),
                  TMP{{3,3},{4,4},{5,5}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multipoint_3d_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTIPOINT 3D ***" << std::endl;
#endif

    typedef tuple_multi_point_type_3d TMP;
    typedef multi_point_type_3d MP;

    typedef test_point_iterator_of_geometry<MP, TMP> tester;

    tester::apply(from_wkt<MP>("MULTIPOINT()"),
                  TMP()
                  );

    tester::apply(from_wkt<MP>("MULTIPOINT(3 3 3,4 4 4,5 5 5)"),
                  TMP{{3,3,3},{4,4,4},{5,5,5}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multilinestring_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTILINESTRING ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef multi_linestring_type ML;

    typedef test_point_iterator_of_geometry<ML, TMP> tester;

    tester::apply(from_wkt<ML>("MULTILINESTRING()"),
                  TMP()
                  );

    tester::apply(from_wkt<ML>("MULTILINESTRING(())"),
                  TMP()
                  );

    tester::apply(from_wkt<ML>("MULTILINESTRING((),(),())"),
                  TMP()
                  );

    tester::apply(from_wkt<ML>("MULTILINESTRING((1 1,2 2,3 3),(3 3,4 4,5 5),(6 6))"),
                  TMP{{1,1},{2,2},{3,3},{3,3},{4,4},{5,5},{6,6}}
                  );

    tester::apply(from_wkt<ML>("MULTILINESTRING((),(),(1 1,2 2,3 3),(),(),(3 3,4 4,5 5),(),(6 6),(),(),())"),
                  TMP{{1,1},{2,2},{3,3},{3,3},{4,4},{5,5},{6,6}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multipolygon_point_iterator )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTIPOLYGON ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef multi_polygon_type MPL;

    typedef test_point_iterator_of_geometry<MPL, TMP> tester;

    tester::apply(from_wkt<MPL>("MULTIPOLYGON()"),
                  TMP()
                  );

    tester::apply(from_wkt<MPL>("MULTIPOLYGON( () )"),
                  TMP()
                  );

    tester::apply(from_wkt<MPL>("MULTIPOLYGON( (()) )"),
                  TMP()
                  );

    tester::apply(from_wkt<MPL>("MULTIPOLYGON( ((),()) )"),
                  TMP()
                  );

    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)))"),
                  TMP{{3,3},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},
                      {1,1},{2,2},{10,10},{11,11},{12,12}}
                  );

    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),()))"),
                  TMP{{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}}
                  );

    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),()),((),(),()))"),
                  TMP{{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}}
                  );

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl << std::endl;
#endif
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multipoint_of_point_pointers )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTIPOINT OF POINT POINTERS ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef vector_as_multipoint<test::test_point_xy*> MP;

    MP multipoint;
    for (int i = 1; i < 10; i++)
    {
        test::test_point_xy* p = new test::test_point_xy;
        p->x = i;
        p->y = -i;
        multipoint.push_back(p);
    }

    test::test_point_xy* zero = new test::test_point_xy;
    zero->x = 0;
    zero->y = 0;

    typedef test_point_iterator_of_geometry<MP, TMP> tester;

    tester::apply(multipoint,
                  TMP{{1,-1},{2,-2},{3,-3},{4,-4},{5,-5},{6,-6},
                      {7,-7},{8,-8},{9,-9}},
                  zero
                  );

    for (unsigned int i = 0; i < multipoint.size(); i++)
    {
        delete multipoint[i];
    }
    delete zero;
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_linestring_of_point_pointers )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** LINESTRING OF POINT POINTERS ***" << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef vector_as_linestring<test::test_point_xy*> L;

    L linestring;
    for (int i = 1; i < 10; i++)
    {
        test::test_point_xy* p = new test::test_point_xy;
        p->x = i;
        p->y = -i;
        linestring.push_back(p);
    }

    test::test_point_xy* zero = new test::test_point_xy;
    zero->x = 0;
    zero->y = 0;

    typedef test_point_iterator_of_geometry<L, TMP> tester;

    tester::apply(linestring,
                  TMP{{1,-1},{2,-2},{3,-3},{4,-4},{5,-5},{6,-6},
                      {7,-7},{8,-8},{9,-9}},
                  zero
                  );

    for (unsigned int i = 0; i < linestring.size(); i++)
    {
        delete linestring[i];
    }
    delete zero;
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_multipoint_copy_on_dereference )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** MULTIPOINT WITH COPY-ON-DEREFERENCE ITERATOR ***"
              << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef multipoint_copy_on_dereference<point_type> MP;

    typedef test_point_iterator_of_geometry
        <
            MP, TMP, false // no concept checks
        > tester;

    // bg::read_wkt does not work for this multipoint type so we have
    // to initialize the multipoint manually
    MP multipoint;
    for (int i = 1; i < 10; ++i)
    {
        multipoint.push_back(point_type(i, -i));
    }

    tester::apply(multipoint,
                  // from_wkt<MP>("MULTIPOINT(1 -1,2 -2,3 -3,4 -4,5 -5,6 -6, 7 -7,8 -8,9 -9)"),
                  TMP{{1,-1},{2,-2},{3,-3},{4,-4},{5,-5},{6,-6},
                      {7,-7},{8,-8},{9,-9}}
                  );
}


//======================================================================
//======================================================================


BOOST_AUTO_TEST_CASE( test_linestring_copy_on_dereference )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << "*** LINESTRING WITH COPY-ON-DEREFERENCE ITERATOR ***"
              << std::endl;
#endif

    typedef tuple_multi_point_type TMP;
    typedef linestring_copy_on_dereference<point_type> L;

    typedef test_point_iterator_of_geometry
        <
            L, TMP, false // no concept checks
        > tester;

    tester::apply(from_wkt<L>("LINESTRING(1 -1,2 -2,3 -3,4 -4,5 -5,6 -6, 7 -7,8 -8,9 -9)"),
                  TMP{{1,-1},{2,-2},{3,-3},{4,-4},{5,-5},{6,-6},
                      {7,-7},{8,-8},{9,-9}}
                  );
}