File: intersection_integer.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (122 lines) | stat: -rw-r--r-- 4,116 bytes parent folder | download | duplicates (2)
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
// Boost.Geometry
// Unit Test

// Copyright (c) 2007-2023 Barend Gehrels, Amsterdam, the Netherlands.

// This file was modified by Oracle on 2015-2022.
// Modifications copyright (c) 2015-2022, 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

// 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_intersection.hpp"
#include <algorithms/test_overlay.hpp>

#include <algorithms/overlay/overlay_cases.hpp>

#define TEST_INTERSECTION(caseid, clips, points, area) \
    (test_one<Polygon, Polygon, Polygon>) \
    ( #caseid, caseid[0], caseid[1], clips, points, area, settings)

namespace
{
    std::string rectangles[2] =
    {
        "POLYGON((1000 1000,2000 1000,2000 2000,1000 2000))",
        "POLYGON((500 500,1500 500,1500 1500,500 1500))"
    };

    std::string start_within[2] =
    {
        "POLYGON((1000 1000,2000 1000,2000 2000,1000 2000))",
        "POLYGON((1250 1250,1500 750,1750 1250,1750 1750))"
    };
}


template <typename Polygon>
void test_areal()
{
    static bool is_open = bg::closure<Polygon>::value == bg::open;

    ut_settings settings;
    settings.test_point_count = true;

    TEST_INTERSECTION(rectangles, 1, is_open ? 4 : 5, 250000.0);
    TEST_INTERSECTION(start_within, 1, is_open ? 5 : 6, 218750.0);
    TEST_INTERSECTION(issue_1184, 1, is_open ? 3 : 4, 156.0);
}

template <typename P>
void test_all()
{
    using polygon = bg::model::polygon<P>;
    using polygon_ccw = bg::model::polygon<P, false>;
    using polygon_open = bg::model::polygon<P, true, false>;
    using polygon_ccw_open = bg::model::polygon<P, false, false>;
    test_areal<polygon>();
    test_areal<polygon_ccw>();
    test_areal<polygon_open>();
    test_areal<polygon_ccw_open>();
}

template <typename CoordinateType>
void test_ticket_10868(/*std::string const& wkt_out*/)
{
    using point_type = bg::model::point<CoordinateType, 2, bg::cs::cartesian>;
    using polygon_type = bg::model::polygon
        <
            point_type, /*ClockWise*/false, /*Closed*/false
        >;
    using multipolygon_type = bg::model::multi_polygon<polygon_type>;

    polygon_type polygon1;
    polygon_type polygon2;
    bg::read_wkt(ticket_10868[0], polygon1);
    bg::read_wkt(ticket_10868[1], polygon2);

    multipolygon_type multipolygon_out;
    bg::intersection(polygon1, polygon2, multipolygon_out);
    std::stringstream stream;
    stream << bg::wkt(multipolygon_out);

    // BOOST_CHECK_EQUAL(stream.str(), wkt_out);

    test_one<polygon_type, polygon_type, polygon_type>("ticket_10868",
        ticket_10868[0], ticket_10868[1],
        1, 7, 20266195244586.0);
}



int test_main(int, char* [])
{
    BoostGeometryWriteTestConfiguration();

    test_all<bg::model::d2::point_xy<std::int32_t> >();


#if defined(BOOST_GEOMETRY_TEST_FAILURES)
    // ticket #10868 still fails for 32-bit integers
    test_ticket_10868<std::int32_t>("MULTIPOLYGON(((33520458 6878575,33480192 14931538,31446819 18947953,30772384 19615678,30101303 19612322,30114725 16928001,33520458 6878575)))");

    test_ticket_10868<std::int64_t>("MULTIPOLYGON(((33520458 6878575,33480192 14931538,31446819 18947953,30772384 19615678,30101303 19612322,30114725 16928001,33520458 6878575)))");
#endif

 #if defined(BOOST_GEOMETRY_TEST_FAILURES)
    // Ticket #10868 was normally not run for other types
    // It results in a different area (might be fine)
    // and it reports self intersections.
    if (BOOST_GEOMETRY_CONDITION(sizeof(long) * CHAR_BIT >= 64))
    {
        test_ticket_10868<long>("MULTIPOLYGON(((33520458 6878575,33480192 14931538,31446819 18947953,30772384 19615678,30101303 19612322,30114725 16928001,33520458 6878575)))");
    }

    test_ticket_10868<long long>("MULTIPOLYGON(((33520458 6878575,33480192 14931538,31446819 18947953,30772384 19615678,30101303 19612322,30114725 16928001,33520458 6878575)))");
 #endif

    return 0;
}