]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Boost.Geometry |
2 | ||
3 | // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | // Copyright (c) 2008-2015 Bruno Lalande, Paris, France. | |
5 | // Copyright (c) 2009-2015 Mateusz Loskot, London, UK. | |
6 | ||
7 | // This file was modified by Oracle on 2015-2022. | |
8 | // Modifications copyright (c) 2015-2022, Oracle and/or its affiliates. | |
9 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
11 | ||
12 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
13 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
14 | ||
15 | // Licensed under the Boost Software License version 1.0. | |
16 | // http://www.boost.org/users/license.html | |
17 | ||
18 | ||
19 | #include <string> | |
20 | ||
21 | #include "test_intersection.hpp" | |
22 | ||
23 | ||
24 | template <typename Box> | |
25 | void test_boxes(std::string const& wkt1, std::string const& wkt2, double expected_area, bool expected_result) | |
26 | { | |
27 | Box box1, box2; | |
28 | bg::read_wkt(wkt1, box1); | |
29 | bg::read_wkt(wkt2, box2); | |
30 | ||
31 | Box box_out; | |
32 | bg::assign_zero(box_out); | |
33 | bool detected = bg::intersection(box1, box2, box_out); | |
34 | typename bg::default_area_result<Box>::type area = bg::area(box_out); | |
35 | ||
36 | BOOST_CHECK_EQUAL(detected, expected_result); | |
37 | if (detected && expected_result) | |
38 | { | |
39 | BOOST_CHECK_CLOSE(area, expected_area, 0.01); | |
40 | } | |
41 | } | |
42 | ||
43 | template <typename P> | |
44 | void test_boxes_per_d(P const& min1, P const& max1, P const& min2, P const& max2, bool expected_result) | |
45 | { | |
46 | using box = bg::model::box<P>; | |
47 | ||
48 | box box_out; | |
49 | bool detected = bg::intersection(box(min1, max1), box(min2, max2), box_out); | |
50 | ||
51 | BOOST_CHECK_EQUAL(detected, expected_result); | |
52 | if (detected && expected_result) | |
53 | { | |
54 | BOOST_CHECK(bg::equals(box_out, box(min2,max1))); | |
55 | } | |
56 | } | |
57 | ||
58 | template <typename CoordinateType> | |
59 | void test_boxes_nd() | |
60 | { | |
61 | using p1 = bg::model::point<CoordinateType, 1, bg::cs::cartesian>; | |
62 | using p2 = bg::model::point<CoordinateType, 2, bg::cs::cartesian>; | |
63 | using p3 = bg::model::point<CoordinateType, 3, bg::cs::cartesian>; | |
64 | ||
65 | test_boxes_per_d(p1(0), p1(5), p1(3), p1(6), true); | |
66 | test_boxes_per_d(p2(0,0), p2(5,5), p2(3,3), p2(6,6), true); | |
67 | test_boxes_per_d(p3(0,0,0), p3(5,5,5), p3(3,3,3), p3(6,6,6), true); | |
68 | } | |
69 | ||
70 | template <typename CoordinateType> | |
71 | void test_box_geo(std::string const& wkt1, std::string const& wkt2, std::string const& wkt_result) | |
72 | { | |
73 | using point_deg = bg::model::point<CoordinateType, 2, bg::cs::geographic<bg::degree> >; | |
74 | using point_rad = bg::model::point<CoordinateType, 2, bg::cs::geographic<bg::radian> >; | |
75 | using box_deg = bg::model::box<point_deg>; | |
76 | using box_rad = bg::model::box<point_rad>; | |
77 | ||
78 | box_deg box1, box2; | |
79 | bg::read_wkt(wkt1, box1); | |
80 | bg::read_wkt(wkt2, box2); | |
81 | box_rad box3{{bg::get_as_radian<0, 0>(box1), bg::get_as_radian<0, 1>(box1)}, | |
82 | {bg::get_as_radian<1, 0>(box1), bg::get_as_radian<1, 1>(box1)}}; | |
83 | box_rad box4{{bg::get_as_radian<0, 0>(box2), bg::get_as_radian<0, 1>(box2)}, | |
84 | {bg::get_as_radian<1, 0>(box2), bg::get_as_radian<1, 1>(box2)}}; | |
85 | ||
86 | box_deg box5; | |
87 | box_rad box6; | |
88 | bool result1 = bg::intersection(box1, box2, box5); | |
89 | bool result2 = bg::intersection(box3, box4, box6); | |
90 | if (wkt_result.empty()) | |
91 | { | |
92 | BOOST_CHECK(! result1 && ! result2); | |
93 | } | |
94 | else | |
95 | { | |
96 | box_deg box7; | |
97 | bg::read_wkt(wkt_result, box7); | |
98 | box_rad box8{{bg::get_as_radian<0, 0>(box7), bg::get_as_radian<0, 1>(box7)}, | |
99 | {bg::get_as_radian<1, 0>(box7), bg::get_as_radian<1, 1>(box7)}}; | |
100 | BOOST_CHECK(result1 && result2); | |
101 | BOOST_CHECK(bg::equals(box5, box7)); | |
102 | BOOST_CHECK(bg::equals(box6, box8)); | |
103 | } | |
104 | } | |
105 | ||
106 | template <typename T> | |
107 | void test_boxes_geo() | |
108 | { | |
109 | test_box_geo<T>("box(0 0, 50 50)", "box(10 10, 40 40)", "box(10 10, 40 40)"); | |
110 | test_box_geo<T>("box(0 0, 50 50)", "box(10 10, 60 60)", "box(10 10, 50 50)"); | |
111 | ||
112 | test_box_geo<T>("box(100 -90, 270 90)", "box(10 10, 150 50)", "box(100 10, 150 50)"); | |
113 | ||
114 | test_box_geo<T>("box(180.0 -90, 180.00000000000034 90.000000000000085)", "box(1 1, 4 4)", ""); | |
115 | } | |
116 | ||
117 | template <typename T> | |
118 | void test_boxes_car() | |
119 | { | |
120 | using point = bg::model::d2::point_xy<T>; | |
121 | using box = bg::model::box<point>; | |
122 | ||
123 | test_boxes<box>("box(2 2,8 8)", "box(4 4,10 10)", 16, true); | |
124 | test_boxes<box>("box(2 2,8 7)", "box(4 4,10 10)", 12, true); | |
125 | test_boxes<box>("box(2 2,8 7)", "box(14 4,20 10)", 0, false); | |
126 | test_boxes<box>("box(2 2,4 4)", "box(4 4,8 8)", 0, true); | |
127 | } | |
128 | ||
129 | int test_main(int, char*[]) | |
130 | { | |
131 | test_boxes_car<default_test_type>(); | |
132 | test_boxes_geo<double>(); | |
133 | ||
134 | #ifndef BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE | |
135 | test_boxes_car<float>(); | |
136 | test_boxes_nd<double>(); | |
137 | #endif | |
138 | ||
139 | return 0; | |
140 | } |