]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // Boost.Geometry |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2019, Oracle and/or its affiliates. | |
5 | ||
6 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
7 | ||
8 | // Licensed under the Boost Software License version 1.0. | |
9 | // http://www.boost.org/users/license.html | |
10 | ||
11 | ||
12 | #include <geometry_test_common.hpp> | |
13 | ||
14 | #include <boost/geometry/algorithms/detail/calculate_point_order.hpp> | |
15 | ||
16 | #include <boost/geometry/geometries/point.hpp> | |
17 | #include <boost/geometry/geometries/ring.hpp> | |
18 | ||
19 | #include <boost/geometry/io/wkt/wkt.hpp> | |
20 | ||
21 | #include <boost/geometry/strategies/cartesian/point_order.hpp> | |
22 | #include <boost/geometry/strategies/geographic/point_order.hpp> | |
23 | #include <boost/geometry/strategies/spherical/point_order.hpp> | |
24 | ||
20effc67 TL |
25 | //TEMP |
26 | #include <boost/geometry/strategies/area/cartesian.hpp> | |
27 | #include <boost/geometry/strategies/area/geographic.hpp> | |
28 | #include <boost/geometry/strategies/area/spherical.hpp> | |
29 | ||
92f5a8d4 TL |
30 | |
31 | inline const char * order_str(bg::order_selector o) | |
32 | { | |
33 | if (o == bg::clockwise) | |
34 | return "clockwise"; | |
35 | else if (o == bg::counterclockwise) | |
36 | return "counterclockwise"; | |
37 | else | |
38 | return "order_undetermined"; | |
39 | } | |
40 | ||
41 | inline const char * cs_str(bg::cartesian_tag) | |
42 | { | |
43 | return "cartesian"; | |
44 | } | |
45 | ||
46 | inline const char * cs_str(bg::spherical_equatorial_tag) | |
47 | { | |
48 | return "spherical_equatorial"; | |
49 | } | |
50 | ||
51 | inline const char * cs_str(bg::geographic_tag) | |
52 | { | |
53 | return "geographic"; | |
54 | } | |
55 | ||
56 | template <typename Ring> | |
57 | inline void test_one(Ring const& ring, bg::order_selector expected) | |
58 | { | |
59 | typedef typename bg::cs_tag<Ring>::type cs_tag; | |
60 | ||
61 | bg::order_selector result = bg::detail::calculate_point_order(ring); | |
62 | ||
63 | BOOST_CHECK_MESSAGE(result == expected, "Expected: " << order_str(expected) << " for " << bg::wkt(ring) << " in " << cs_str(cs_tag())); | |
64 | ||
65 | if (expected != bg::order_undetermined && result != bg::order_undetermined) | |
66 | { | |
67 | Ring ring_rev = ring; | |
68 | ||
69 | std::reverse(boost::begin(ring_rev), boost::end(ring_rev)); | |
70 | ||
71 | bg::order_selector result_rev = bg::detail::calculate_point_order(ring_rev); | |
72 | ||
73 | BOOST_CHECK_MESSAGE(result != result_rev, "Invalid order of reversed: " << bg::wkt(ring) << " in " << cs_str(cs_tag())); | |
74 | } | |
75 | } | |
76 | ||
77 | template <typename P> | |
78 | inline void test_one(std::string const& ring_wkt, bg::order_selector expected) | |
79 | { | |
80 | //typedef typename bg::cs_tag<P>::type cs_tag; | |
81 | ||
82 | bg::model::ring<P> ring; | |
83 | bg::read_wkt(ring_wkt, ring); | |
84 | ||
85 | std::size_t n = boost::size(ring); | |
86 | for (size_t i = 1; i < n; ++i) | |
87 | { | |
88 | test_one(ring, expected); | |
89 | std::rotate(boost::begin(ring), boost::begin(ring) + 1, boost::end(ring)); | |
90 | ||
91 | // it seems that area method doesn't work for invalid "opened" polygons | |
92 | //if (! boost::is_same<cs_tag, bg::geographic_tag>::value) | |
93 | { | |
94 | P p = bg::range::front(ring); | |
95 | bg::range::push_back(ring, p); | |
96 | } | |
97 | } | |
98 | } | |
99 | ||
100 | template <typename P> | |
101 | void test_all() | |
102 | { | |
103 | // From correct() test, rings rotated and reversed in test_one() | |
104 | test_one<P>("POLYGON((0 0,0 1,1 1,1 0,0 0))", bg::clockwise); | |
105 | test_one<P>("POLYGON((0 0,0 1,1 1,1 0))", bg::clockwise); | |
106 | test_one<P>("POLYGON((0 0,0 4,4 4,4 0,0 0))", bg::clockwise); | |
107 | test_one<P>("POLYGON((1 1,2 1,2 2,1 2,1 1))", bg::counterclockwise); | |
108 | ||
109 | test_one<P>("POLYGON((0 5, 5 5, 5 0, 0 0, 0 5))", bg::clockwise); | |
110 | test_one<P>("POLYGON((0 5, 0 5, 0 6, 0 6, 0 4, 0 5, 5 5, 5 0, 0 0, 0 6, 0 5))", bg::clockwise); | |
111 | test_one<P>("POLYGON((2 0, 2 1, 2 -1, 2 0, 1 0, 1 -1, 0 -1, 0 1, 1 1, 1 0, 2 0))", bg::clockwise); | |
112 | test_one<P>("POLYGON((2 0, 2 1, 2 -1, 2 0, 1 0, 1 -1, 0 -1, 0 1, 1 1, 1 0))", bg::clockwise); | |
113 | test_one<P>("POLYGON((2 0, 2 1, 3 1, 3 -1, 2 -1, 2 0, 1 0, 1 -1, 0 -1, 0 1, 1 1, 1 0, 2 0))", bg::clockwise); | |
114 | test_one<P>("POLYGON((0 85, 5 85, 5 84, 0 84, 0 85))", bg::clockwise); | |
115 | test_one<P>("POLYGON((0 2, 170 2, 170 0, 0 0, 0 2))", bg::clockwise); | |
116 | test_one<P>("POLYGON((0 2, 170 2, 170 1, 160 1, 10 1, 0 1, 0 2))", bg::clockwise); | |
117 | test_one<P>("POLYGON((0 2, 170 2, 170 -2, 0 -2, 0 2))", bg::clockwise); | |
118 | test_one<P>("POLYGON((5 5, 6 5, 6 6, 6 4, 6 5, 5 5, 5 4, 4 4, 4 6, 5 6, 5 5))", bg::clockwise); | |
119 | test_one<P>("POLYGON((5 5, 6 5, 6 6, 6 4, 6 5, 5 5, 5 6, 4 6, 4 4, 5 4, 5 5))", bg::counterclockwise); | |
120 | test_one<P>("POLYGON((5 5, 6 5, 6 5, 6 6, 6 5, 6 4, 6 5, 6 5, 5 5, 5 4, 4 4, 4 6, 5 6, 5 5))", bg::clockwise); | |
121 | ||
122 | // https://github.com/boostorg/geometry/pull/554 | |
123 | test_one<P>("POLYGON((9.8591674311151110 54.602813224425063, 9.8591651519791412 54.602359676428932, 9.8584586199249316 54.602359676428932, 9.8591674311151110 54.602813224425063))", | |
124 | bg::clockwise); | |
125 | } | |
126 | ||
127 | template <typename P> | |
128 | void test_cartesian() | |
129 | { | |
130 | test_one<P>("POLYGON((0 5, 1 5, 1 6, 1 4, 2 4, 0 4, 0 3, 0 5))", bg::clockwise); | |
131 | } | |
132 | ||
133 | template <typename P> | |
134 | void test_spheroidal() | |
135 | { | |
136 | test_one<P>("POLYGON((0 5, 1 5, 1 6, 1 4, 0 4, 0 3, 0 5))", bg::clockwise); | |
137 | ||
138 | test_one<P>("POLYGON((0 45, 120 45, -120 45, 0 45))", bg::counterclockwise); | |
139 | } | |
140 | ||
141 | int test_main(int, char* []) | |
142 | { | |
143 | test_all<bg::model::point<double, 2, bg::cs::cartesian> >(); | |
144 | test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); | |
145 | test_all<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >(); | |
146 | ||
147 | test_cartesian<bg::model::point<double, 2, bg::cs::cartesian> >(); | |
148 | ||
149 | test_spheroidal<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >(); | |
150 | test_spheroidal<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >(); | |
151 | ||
152 | return 0; | |
153 | } |