|
27 | 27 | #include <boost/geometry/geometries/ring.hpp> |
28 | 28 | #include <boost/geometry/geometries/polygon.hpp> |
29 | 29 |
|
| 30 | +#include <boost/geometry/strategy/cartesian/precise_area.hpp> |
| 31 | + |
30 | 32 | #include <test_geometries/all_custom_ring.hpp> |
31 | 33 | #include <test_geometries/all_custom_polygon.hpp> |
32 | 34 | //#define BOOST_GEOMETRY_TEST_DEBUG |
33 | 35 |
|
| 36 | +#include <boost/multiprecision/cpp_dec_float.hpp> |
34 | 37 | #include <boost/variant/variant.hpp> |
35 | 38 |
|
36 | 39 | template <typename Polygon> |
@@ -175,6 +178,70 @@ void test_large_integers() |
175 | 178 | BOOST_CHECK_CLOSE(int_area, double_area, 0.0001); |
176 | 179 | } |
177 | 180 |
|
| 181 | +struct precise_cartesian : bg::strategies::detail::cartesian_base |
| 182 | +{ |
| 183 | + template <typename Geometry> |
| 184 | + static auto area(Geometry const&) |
| 185 | + { |
| 186 | + return bg::strategy::area::precise_cartesian<>(); |
| 187 | + } |
| 188 | +}; |
| 189 | + |
| 190 | +void test_accurate_sum_strategy() |
| 191 | +{ |
| 192 | + typedef bg::model::point<double, 2, bg::cs::cartesian> point_type; |
| 193 | + typedef bg::model::point |
| 194 | + < |
| 195 | + boost::multiprecision::cpp_dec_float_50, |
| 196 | + 2, |
| 197 | + bg::cs::cartesian |
| 198 | + > mp_point_type; |
| 199 | + |
| 200 | + auto const poly0_string = "POLYGON((0 0,0 1,1 0,0 0))"; |
| 201 | + |
| 202 | + bg::model::polygon<point_type> poly0; |
| 203 | + bg::read_wkt(poly0_string, poly0); |
| 204 | + |
| 205 | + BOOST_CHECK_CLOSE(bg::area(poly0), 0.5, 0.0001); |
| 206 | + BOOST_CHECK_CLOSE(bg::area(poly0, precise_cartesian()), 0.5, 0.0001); |
| 207 | + |
| 208 | + bg::model::polygon<mp_point_type> mp_poly0; |
| 209 | + bg::read_wkt(poly0_string, mp_poly0); |
| 210 | + |
| 211 | + BOOST_CHECK_CLOSE(bg::area(mp_poly0), 0.5, 0.0001); |
| 212 | + |
| 213 | + auto const poly1_string = "POLYGON((0.10000000000000001 0.10000000000000001,\ |
| 214 | + 0.20000000000000001 0.20000000000000004,\ |
| 215 | + 0.79999999999999993 0.80000000000000004,\ |
| 216 | + 1.267650600228229e30 1.2676506002282291e30,\ |
| 217 | + 0.10000000000000001 0.10000000000000001))"; |
| 218 | + |
| 219 | + bg::model::polygon<point_type> poly1; |
| 220 | + bg::read_wkt(poly1_string, poly1); |
| 221 | + |
| 222 | + BOOST_CHECK_CLOSE(bg::area(poly1), 0, 0.0001); |
| 223 | + BOOST_CHECK_CLOSE(bg::area(poly1, precise_cartesian()), -0.315, 0.0001); |
| 224 | + |
| 225 | + bg::model::polygon<mp_point_type> mp_poly1; |
| 226 | + bg::read_wkt(poly1_string, mp_poly1); |
| 227 | + |
| 228 | + BOOST_CHECK_CLOSE(bg::area(mp_poly1), 34720783012552.6, 0.0001); |
| 229 | + |
| 230 | + auto const poly2_string = "POLYGON((1.267650600228229e30 1.2676506002282291e30,\ |
| 231 | + 0.8 0.8,0.2 0.2,0.1 0.1,1.267650600228229e30 1.2676506002282291e30))"; |
| 232 | + |
| 233 | + bg::model::polygon<point_type> poly2; |
| 234 | + bg::read_wkt(poly2_string, poly2); |
| 235 | + |
| 236 | + BOOST_CHECK_CLOSE(bg::area(poly2), 0, 0.0001); |
| 237 | + BOOST_CHECK_CLOSE(bg::area(poly2, precise_cartesian()), 0.315, 0.0001); |
| 238 | + |
| 239 | + bg::model::polygon<mp_point_type> mp_poly2; |
| 240 | + bg::read_wkt(poly2_string, mp_poly2); |
| 241 | + |
| 242 | + BOOST_CHECK_CLOSE(bg::area(mp_poly2), 35000000000000, 0.0001); |
| 243 | +} |
| 244 | + |
178 | 245 | void test_variant() |
179 | 246 | { |
180 | 247 | typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type; |
@@ -231,6 +298,8 @@ int test_main(int, char* []) |
231 | 298 |
|
232 | 299 | test_variant(); |
233 | 300 |
|
| 301 | + test_accurate_sum_strategy(); |
| 302 | + |
234 | 303 | // test_empty_input<bg::model::d2::point_xy<int> >(); |
235 | 304 |
|
236 | 305 | return 0; |
|
0 commit comments