summaryrefslogtreecommitdiff
path: root/boost/geometry/algorithms/detail/relate/implementation_gc.hpp
blob: f0fa11d2af938e7c9b884281463413a78cd27b22 (plain)
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
// Boost.Geometry

// Copyright (c) 2022-2023 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2022 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_IMPLEMENTATION_GC_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_IMPLEMENTATION_GC_HPP


#include <boost/geometry/algorithms/detail/relate/boundary_checker.hpp>
#include <boost/geometry/algorithms/detail/relate/interface.hpp>
#include <boost/geometry/algorithms/difference.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/is_empty.hpp>
#include <boost/geometry/algorithms/union.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/views/detail/geometry_collection_view.hpp>


namespace boost { namespace geometry
{

#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace relate
{

// For fields II IE and EI this handler behaves like matrix_handler.
// It has to be created at the beginning of processing because it relies on the
//   fact that all of the fields are set to F and no geometry was handled yet.
//   This way it can check which fields are required for any mask and matrix
//   without accessing the internals.
// An alternative would be to remove this wrapper and always set the matrix
//   in static_mask_handler even if this is not required.
template <typename Handler>
struct aa_handler_wrapper
{
    bool interrupt = false;

    explicit aa_handler_wrapper(Handler& handler)
        : m_handler(handler)
        , m_overwrite_ii(! handler.template may_update<interior, interior, '2'>())
        , m_overwrite_ie(! handler.template may_update<interior, exterior, '2'>())
        , m_overwrite_ei(! handler.template may_update<exterior, interior, '2'>())
    {}

    template <field F1, field F2, char D>
    inline bool may_update() const
    {
        if ((BOOST_GEOMETRY_CONDITION(F1 == interior && F2 == interior) && m_overwrite_ii)
            || (BOOST_GEOMETRY_CONDITION(F1 == interior && F2 == exterior) && m_overwrite_ie)
            || (BOOST_GEOMETRY_CONDITION(F1 == exterior && F2 == interior) && m_overwrite_ei))
        {
            char const c = m_handler.template get<F1, F2>();
            return D > c || c > '9';
        }
        else
        {
            return m_handler.template may_update<F1, F2, D>();
        }
    }

    template <field F1, field F2, char V>
    inline void update()
    {
        if ((BOOST_GEOMETRY_CONDITION(F1 == interior && F2 == interior) && m_overwrite_ii)
            || (BOOST_GEOMETRY_CONDITION(F1 == interior && F2 == exterior) && m_overwrite_ie)
            || (BOOST_GEOMETRY_CONDITION(F1 == exterior && F2 == interior) && m_overwrite_ei))
        {
            // NOTE: Other handlers first check for potential interruption
            //   and only after that checks update condition.
            char const c = m_handler.template get<F1, F2>();
            // If c == T and V == T it will be set anyway but that's fine.
            if (V > c || c > '9')
            {
                // set may set interrupt flag
                m_handler.template set<F1, F2, V>();
            }
        }
        else
        {
            m_handler.template update<F1, F2, V>();
        }
        interrupt = interrupt || m_handler.interrupt;
    }

private:
    Handler & m_handler;
    bool const m_overwrite_ii;
    bool const m_overwrite_ie;
    bool const m_overwrite_ei;
};


template <typename Geometry1, typename Geometry2>
struct gc_gc
{
    static const bool interruption_enabled = true;

    using mpt1_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry1>::type,
            util::is_multi_point
        >::type;
    using mls1_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry1>::type,
            util::is_multi_linestring
        >::type;
    using mpo1_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry1>::type,
            util::is_multi_polygon
        >::type;
    using pt1_t = typename geometry::point_type<Geometry1>::type;
    using mpt1_t = std::conditional_t
        <
            std::is_void<mpt1_found_t>::value,
            geometry::model::multi_point<pt1_t>,
            mpt1_found_t
        >;
    using mls1_t = std::conditional_t
        <
            std::is_void<mls1_found_t>::value,
            geometry::model::multi_linestring<geometry::model::linestring<pt1_t>>,
            mls1_found_t
        >;
    using mpo1_t = std::conditional_t
        <
            std::is_void<mpo1_found_t>::value,
            geometry::model::multi_polygon<geometry::model::polygon<pt1_t>>,
            mpo1_found_t
        >;
    using tuple1_t = boost::tuple<mpt1_t, mls1_t, mpo1_t>;

    using mpt2_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry2>::type,
            util::is_multi_point
        >::type;
    using mls2_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry2>::type,
            util::is_multi_linestring
        >::type;
    using mpo2_found_t = typename util::sequence_find_if
        <
            typename traits::geometry_types<Geometry2>::type,
            util::is_multi_polygon
        >::type;
    using pt2_t = typename geometry::point_type<Geometry2>::type;
    using mpt2_t = std::conditional_t
        <
            std::is_void<mpt2_found_t>::value,
            geometry::model::multi_point<pt2_t>,
            mpt2_found_t
        >;
    using mls2_t = std::conditional_t
        <
            std::is_void<mls2_found_t>::value,
            geometry::model::multi_linestring<geometry::model::linestring<pt2_t>>,
            mls2_found_t
        >;
    using mpo2_t = std::conditional_t
        <
            std::is_void<mpo2_found_t>::value,
            geometry::model::multi_polygon<geometry::model::polygon<pt2_t>>,
            mpo2_found_t
        >;
    using tuple2_t = boost::tuple<mpt2_t, mls2_t, mpo2_t>;

    template <typename Geometry>
    using kind_id = util::index_constant
        <
            util::is_areal<Geometry>::value ? 2
          : util::is_linear<Geometry>::value ? 1
          : 0
        >;

    template <typename Result, typename Strategy>
    static inline void apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
                             Result & result,
                             Strategy const& strategy)
    {
        using gc1_view_t = random_access_view<Geometry1 const>;
        using gc2_view_t = random_access_view<Geometry2 const>;
        gc1_view_t const gc1_view(geometry1);
        gc2_view_t const gc2_view(geometry2);

        bool inters_found[2][3] = {{false, false, false}, {false, false, false}};
        bool disjoint_found[2][3] = {{false, false, false}, {false, false, false}};
        bool disjoint_linear_boundary_found[2] = {false, false};
        bool has_disjoint = false;

        gc_group_elements(gc1_view, gc2_view, strategy,
            [&](auto const& inters_group)
            {
                tuple1_t tuple1;
                tuple2_t tuple2;

                // Create MPts, MLss and MPos containing all gc elements from this group
                // They may potentially intersect each other
                for (auto const& id : inters_group)
                {
                    BOOST_GEOMETRY_ASSERT(id.source_id == 0 || id.source_id == 1);
                    if (id.source_id == 0)
                    {
                        traits::iter_visit<gc1_view_t>::apply([&](auto const& g1)
                        {
                            merge_geometry(tuple1, g1, strategy);
                        }, boost::begin(gc1_view) + id.gc_id);
                    }
                    else
                    {
                        traits::iter_visit<gc2_view_t>::apply([&](auto const& g2)
                        {
                            merge_geometry(tuple2, g2, strategy);
                        }, boost::begin(gc2_view) + id.gc_id);
                    }
                }

                // Subtract higher topo-dim elements from elements of lower topo-dim
                // MPts do not intersect other geometries, MLss and MPos may touch
                subtract_elements(tuple1, strategy);
                subtract_elements(tuple2, strategy);

                // Helpers
                auto const& mpt1 = boost::get<0>(tuple1);
                auto const& mls1 = boost::get<1>(tuple1);
                auto const& mpo1 = boost::get<2>(tuple1);
                auto const& mpt2 = boost::get<0>(tuple2);
                auto const& mls2 = boost::get<1>(tuple2);
                auto const& mpo2 = boost::get<2>(tuple2);

                // A/A
                if (! geometry::is_empty(mpo1) && ! geometry::is_empty(mpo2))
                {
                    inters_found[0][2] = true;
                    inters_found[1][2] = true;
                    aa_handler_wrapper<Result> wrapper(result);
                    call_relate(mpo1, mpo2, wrapper, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                bool is_aa_ii = result.template get<interior, interior>() != 'F';
                bool is_aa_ie = result.template get<interior, exterior>() != 'F';
                bool is_aa_ei = result.template get<exterior, interior>() != 'F';
                // is_aa_ii implies is_aa_checked and non-empty Areal geometries
                bool are_aa_equal = is_aa_ii && ! is_aa_ie && ! is_aa_ei;

                // Boundary checkers are internally initialized lazily later if a point has to be checked
                boundary_checker<mls1_t, Strategy> mls1_boundary(mls1, strategy);
                boundary_checker<mls2_t, Strategy> mls2_boundary(mls2, strategy);

                // If needed divide MLss into two parts:
                // - inside Areal of other GC
                // - outside of other GC Areal to check WRT Linear of other GC
                mls2_t mls2_diff_mpo1, mls2_inters_mpo1;
                bool is_mls2_divided = false;
                mls1_t mls1_diff_mpo2, mls1_inters_mpo2;
                bool is_mls1_divided = false;
                // If Areal are equal then Linear are outside of both so there is no need to divide
                if (! are_aa_equal && ! geometry::is_empty(mls1) && ! geometry::is_empty(mls2))
                {
                    // LA/L
                    if (! geometry::is_empty(mpo1))
                    {
                        geometry::difference(mls2, mpo1, mls2_diff_mpo1);
                        geometry::intersection(mls2, mpo1, mls2_inters_mpo1);
                        is_mls2_divided = true;
                    }
                    // L/LA
                    if (! geometry::is_empty(mpo2))
                    {
                        geometry::difference(mls1, mpo2, mls1_diff_mpo2);
                        geometry::intersection(mls1, mpo2, mls1_inters_mpo2);
                        is_mls1_divided = true;
                    }
                }

                // A/L
                if (! geometry::is_empty(mpo1) && ! geometry::is_empty(mls2))
                {
                    inters_found[0][2] = true;
                    inters_found[1][1] = true;
                    if (is_aa_ii && ! is_aa_ie && ! is_aa_ei && ! geometry::is_empty(mls1))
                    {
                        // Equal Areal and both Linear non-empty, calculate only L/L below
                    }
                    else if (is_aa_ii && ! is_aa_ie && geometry::is_empty(mls1))
                    {
                        // An alternative would be to calculate L/L with one empty below
                        mpo1_t empty;
                        call_relate_al(empty, mls2, mls2_boundary, result, strategy);
                    }
                    else
                    {
                        if (is_mls2_divided)
                        {
                            if (! geometry::is_empty(mls2_inters_mpo1))
                            {
                                call_relate_al(mpo1, mls2_inters_mpo1, mls2_boundary, result, strategy);
                            }
                        }
                        else
                        {
                            call_relate_al(mpo1, mls2, mls2_boundary, result, strategy);
                        }
                    }
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // L/A
                if (! geometry::is_empty(mls1) && ! geometry::is_empty(mpo2))
                {
                    inters_found[0][1] = true;
                    inters_found[1][2] = true;
                    if (is_aa_ii && ! is_aa_ei && ! is_aa_ie && ! geometry::is_empty(mls2))
                    {
                        // Equal Areal and both Linear non-empty, calculate only L/L below
                    }
                    else if (is_aa_ii && ! is_aa_ei && geometry::is_empty(mls2))
                    {
                        // An alternative would be to calculate L/L with one empty below
                        mpo2_t empty;
                        call_relate_la(mls1, empty, mls1_boundary, result, strategy);
                    }
                    else
                    {
                        if (is_mls1_divided)
                        {
                            if (! geometry::is_empty(mls1_inters_mpo2))
                            {
                                call_relate_la(mls1_inters_mpo2, mpo2, mls1_boundary, result, strategy);
                            }
                        }
                        else
                        {
                            call_relate_la(mls1, mpo2, mls1_boundary, result, strategy);
                        }
                    }
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // L/L
                if (! geometry::is_empty(mls1) && ! geometry::is_empty(mls2))
                {
                    inters_found[0][1] = true;
                    inters_found[1][1] = true;
                    if (is_mls1_divided && is_mls2_divided)
                    {
                        if (! geometry::is_empty(mls1_diff_mpo2) && ! geometry::is_empty(mls2_diff_mpo1))
                        {
                            call_relate_ll(mls1_diff_mpo2, mls2_diff_mpo1, mls1_boundary, mls2_boundary, result, strategy);
                        }
                    }
                    else if (is_mls1_divided)
                    {
                        if (! geometry::is_empty(mls1_diff_mpo2))
                        {
                            call_relate_ll(mls1_diff_mpo2, mls2, mls1_boundary, mls2_boundary, result, strategy);
                        }
                    }
                    else if (is_mls2_divided)
                    {
                        if (! geometry::is_empty(mls2_diff_mpo1))
                        {
                            call_relate_ll(mls1, mls2_diff_mpo1, mls1_boundary, mls2_boundary, result, strategy);
                        }
                    }
                    else
                    {
                        call_relate_ll(mls1, mls2, mls1_boundary, mls2_boundary, result, strategy);
                    }
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // A/P
                if (! geometry::is_empty(mpo1) && ! geometry::is_empty(mpt2))
                {
                    inters_found[0][2] = true;
                    inters_found[1][0] = true;
                    call_relate(mpo1, mpt2, result, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // P/A
                if (! geometry::is_empty(mpt1) && ! geometry::is_empty(mpo2))
                {
                    inters_found[0][0] = true;
                    inters_found[1][2] = true;
                    call_relate(mpt1, mpo2, result, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // L/P
                if (! geometry::is_empty(mls1) && ! geometry::is_empty(mpt2))
                {
                    inters_found[0][1] = true;
                    inters_found[1][0] = true;
                    call_relate(mls1, mpt2, result, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // P/L
                if (! geometry::is_empty(mpt1) && ! geometry::is_empty(mls2))
                {
                    inters_found[0][0] = true;
                    inters_found[1][1] = true;
                    call_relate(mpt1, mls2, result, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                // P/P
                if (! geometry::is_empty(mpt1) && ! geometry::is_empty(mpt2))
                {
                    inters_found[0][0] = true;
                    inters_found[1][0] = true;
                    call_relate(mpt1, mpt2, result, strategy);
                }

                if (BOOST_GEOMETRY_CONDITION(result.interrupt))
                {
                    return false;
                }

                return true;
            },
            [&](auto const& disjoint_group)
            {
                for (auto const& id : disjoint_group)
                {
                    BOOST_GEOMETRY_ASSERT(id.source_id == 0 || id.source_id == 1);
                    if (id.source_id == 0)
                    {
                        traits::iter_visit<gc1_view_t>::apply([&](auto const& g1)
                        {
                            if (! geometry::is_empty(g1))
                            {
                                static const std::size_t index = kind_id<util::remove_cref_t<decltype(g1)>>::value;
                                disjoint_found[0][index] = true;
                                disjoint_linear_boundary_found[0] = has_linear_boundary(g1, strategy);
                                has_disjoint = true;
                            }
                        }, boost::begin(gc1_view) + id.gc_id);
                    }
                    else
                    {
                        traits::iter_visit<gc2_view_t>::apply([&](auto const& g2)
                        {
                            if (! geometry::is_empty(g2))
                            {
                                static const std::size_t index = kind_id<util::remove_cref_t<decltype(g2)>>::value;
                                disjoint_found[1][index] = true;
                                disjoint_linear_boundary_found[1] = has_linear_boundary(g2, strategy);
                                has_disjoint = true;
                            }
                        }, boost::begin(gc2_view) + id.gc_id);
                    }
                }
            }, true);

        // Based on found disjoint geometries as well as those intersecting set exteriors
        if (has_disjoint)
        {
            if (disjoint_found[0][2] == true)
            {
                update<interior, exterior, '2'>(result);
                update<boundary, exterior, '1'>(result);
            }
            else if (disjoint_found[0][1] == true)
            {
                update<interior, exterior, '1'>(result);
                if (disjoint_linear_boundary_found[0])
                {
                    update<boundary, exterior, '0'>(result);
                }
            }
            else if (disjoint_found[0][0] == true)
            {
                update<interior, exterior, '0'>(result);
            }

            if (disjoint_found[1][2] == true)
            {
                update<exterior, interior, '2'>(result);
                update<exterior, boundary, '1'>(result);
            }
            else if (disjoint_found[1][1] == true)
            {
                update<exterior, interior, '1'>(result);
                if (disjoint_linear_boundary_found[1])
                {
                    update<exterior, boundary, '0'>(result);
                }
            }
            else if (disjoint_found[1][0] == true)
            {
                update<exterior, interior, '0'>(result);
            }
        }
    }

private:
    template <typename Tuple, typename Geometry, typename Strategy>
    static inline void merge_geometry(Tuple& tuple, Geometry const& geometry, Strategy const& strategy)
    {
        static const std::size_t index = kind_id<Geometry>::value;
        typename boost::tuples::element<index, Tuple>::type temp_out;
        geometry::union_(boost::get<index>(tuple), geometry, temp_out, strategy);
        boost::get<index>(tuple) = std::move(temp_out);
    }

    template <typename Tuple, typename Strategy>
    static inline void subtract_elements(Tuple& tuple, Strategy const& strategy)
    {
        if (! geometry::is_empty(boost::get<1>(tuple)))
        {
            if (! geometry::is_empty(boost::get<2>(tuple)))
            {
                typename boost::tuples::element<1, Tuple>::type mls;
                geometry::difference(boost::get<1>(tuple), boost::get<2>(tuple), mls, strategy);
                boost::get<1>(tuple) = std::move(mls);
            }
        }
        if (! geometry::is_empty(boost::get<0>(tuple)))
        {
            if (! geometry::is_empty(boost::get<2>(tuple)))
            {
                typename boost::tuples::element<0, Tuple>::type mpt;
                geometry::difference(boost::get<0>(tuple), boost::get<2>(tuple), mpt, strategy);
                boost::get<0>(tuple) = std::move(mpt);
            }
            if (! geometry::is_empty(boost::get<1>(tuple)))
            {
                typename boost::tuples::element<0, Tuple>::type mpt;
                geometry::difference(boost::get<0>(tuple), boost::get<1>(tuple), mpt, strategy);
                boost::get<0>(tuple) = std::move(mpt);
            }
        }
    }

    template
    <
        typename Geometry, typename Strategy,
        std::enable_if_t<util::is_linear<Geometry>::value, int> = 0
    >
    static inline bool has_linear_boundary(Geometry const& geometry, Strategy const& strategy)
    {
        topology_check<Geometry, Strategy> tc(geometry, strategy);
        return tc.has_boundary();
    }

    template
    <
        typename Geometry, typename Strategy,
        std::enable_if_t<! util::is_linear<Geometry>::value, int> = 0
    >
    static inline bool has_linear_boundary(Geometry const& , Strategy const& )
    {
        return false;
    }


    template <typename Multi1, typename Multi2, typename Result, typename Strategy>
    static inline void call_relate(Multi1 const& multi1, Multi2 const& multi2,
                                   Result& result, Strategy const& strategy)
    {
        dispatch::relate
            <
                Multi1, Multi2
            >::apply(multi1, multi2, result, strategy);
    }

    template <typename MLs, typename MPo, typename MLsBoundary, typename Result, typename Strategy>
    static inline void call_relate_la(MLs const& mls, MPo const& mpo,
                                      MLsBoundary const& mls_boundary,
                                      Result& result, Strategy const& strategy)
    {
        linear_areal<MLs, MPo>::apply(mls, mpo, mls_boundary, result, strategy);
    }

    template <typename MPo, typename MLs, typename MLsBoundary, typename Result, typename Strategy>
    static inline void call_relate_al(MPo const& mls, MLs const& mpo,
                                      MLsBoundary const& mls_boundary,
                                      Result& result, Strategy const& strategy)
    {
        areal_linear<MPo, MLs>::apply(mls, mpo, mls_boundary, result, strategy);
    }

    template <typename MLs1, typename MLs2, typename MLs1Boundary, typename MLs2Boundary, typename Result, typename Strategy>
    static inline void call_relate_ll(MLs1 const& mls1, MLs2 const& mls2,
                                      MLs1Boundary const& mls1_boundary,
                                      MLs2Boundary const& mls2_boundary,
                                      Result& result, Strategy const& strategy)
    {
        linear_linear<MLs1, MLs2>::apply(mls1, mls2, mls1_boundary, mls2_boundary,
                                                         result, strategy);
    }


};


}} // namespace detail::relate
#endif // DOXYGEN_NO_DETAIL


#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch {

template <typename Geometry1, typename Geometry2>
struct relate<Geometry1, Geometry2, geometry_collection_tag, geometry_collection_tag, -1, -1, false>
    : detail::relate::gc_gc<Geometry1, Geometry2>
{};


template <typename Geometry1, typename Geometry2, typename Tag1, int TopDim1>
struct relate<Geometry1, Geometry2, Tag1, geometry_collection_tag, TopDim1, -1, false>
{
    static const bool interruption_enabled = true;

    template <typename Result, typename Strategy>
    static inline void apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
                             Result & result,
                             Strategy const& strategy)
    {
        using gc1_view_t = detail::geometry_collection_view<Geometry1>;
        relate<gc1_view_t, Geometry2>::apply(gc1_view_t(geometry1), geometry2, result, strategy);
    }
};

template <typename Geometry1, typename Geometry2, typename Tag2, int TopDim2>
struct relate<Geometry1, Geometry2, geometry_collection_tag, Tag2, -1, TopDim2, false>
{
    static const bool interruption_enabled = true;

    template <typename Result, typename Strategy>
    static inline void apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
                             Result & result,
                             Strategy const& strategy)
    {
        using gc2_view_t = detail::geometry_collection_view<Geometry2>;
        relate<Geometry1, gc2_view_t>::apply(geometry1, gc2_view_t(geometry2), result, strategy);
    }
};

} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH


}} // namespace boost::geometry

#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_IMPLEMENTATION_HPP