File: get_turns_const.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (81 lines) | stat: -rw-r--r-- 2,690 bytes parent folder | download | duplicates (5)
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
// Boost.Geometry
// Unit Test

// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.

// This file was modified by Oracle on 2024.
// Modifications copyright (c) 2024 Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, 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)

#include <test_geometries/const_point.hpp>

#include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>

#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/strategies/relate/cartesian.hpp>
#include <boost/geometry/geometries/helper_geometry.hpp>

#include <geometry_test_common.hpp>


template <typename Ring1, typename Ring2>
void test_get_turns_on_const(Ring1 const &ring1, Ring2 const &ring2,
    const std::vector<const_point>& expectation)
{
    namespace bg = boost::geometry;

    using strategy_type = typename bg::strategies::relate::services::default_strategy<Ring1, Ring2>::type;

    using point_type = typename bg::point_type<Ring1>::type;
    using writable_point_type = typename bg::helper_geometry<point_type>::type;

    using segment_ratio_type = typename bg::segment_ratio_type
        <
            writable_point_type
        >::type;
    using turn_info = bg::detail::overlay::turn_info
        <
            writable_point_type, segment_ratio_type
        >;

    std::vector<turn_info> turns;
    strategy_type strategy;
    bg::detail::get_turns::no_interrupt_policy policy;
    bg::get_turns
        <
            false, false, bg::detail::overlay::assign_null_policy
        >(ring1, ring2,  strategy, turns, policy);

    BOOST_CHECK_EQUAL(turns.size(), expectation.size());

    const double tolerance = 0.001;
    for (std::size_t i = 0; i < turns.size() && i < expectation.size(); i++)
    {
        BOOST_CHECK_CLOSE(expectation[i].GetX(), bg::get<0>(turns[i].point), tolerance);
        BOOST_CHECK_CLOSE(expectation[i].GetY(), bg::get<1>(turns[i].point), tolerance);
    }

#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << bg::wkt(ring1) << " " << bg::wkt(ring2) << std::endl;
    for (const auto& turn : turns)
    {
        std::cout << bg::wkt(turn.point) << std::endl;
    }
#endif
}

int test_main(int, char* [])
{
    // Construct two geometries with visually predictable intersections
    ring_of_const_point rectangle{{2, 2}, {2, 4}, {4, 4}, {4, 2}, {2, 2}};
    ring_of_const_point triangle{{1, 2}, {4, 5}, {5, 4}, {1, 2}};

    test_get_turns_on_const(rectangle, triangle, {{2, 3}, {2, 2.5}, {3, 4}, {4, 3.5}});

    return 0;
}