22// Unit Test
33
44// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.
5+ // Copyright (c) 2023, Oracle and/or its affiliates.
6+ // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
57
68// Use, modification and distribution is subject to the Boost Software License,
79// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -16,6 +18,38 @@ namespace
1618 std::string const torg = " POINT(10.3937759 63.4302323)" ;
1719}
1820
21+ template
22+ <
23+ typename FormulaPolicy,
24+ typename Spheroid,
25+ typename CalculationType
26+ >
27+ struct geo_buffer_accurate_area
28+ : public bg::strategies::buffer::geographic<FormulaPolicy, Spheroid, CalculationType>
29+ {
30+ using base_t = bg::strategies::buffer::geographic<FormulaPolicy, Spheroid, CalculationType>;
31+
32+ public:
33+
34+ geo_buffer_accurate_area () = default ;
35+
36+ explicit geo_buffer_accurate_area (Spheroid const & spheroid)
37+ : base_t(spheroid)
38+ {}
39+
40+ template <typename Geometry>
41+ auto area (Geometry const &,
42+ std::enable_if_t <! bg::util::is_box<Geometry>::value> * = nullptr ) const
43+ {
44+ return bg::strategy::area::geographic
45+ <
46+ bg::strategy::karney,
47+ bg::strategy::default_order<bg::strategy::karney>::value,
48+ Spheroid, CalculationType
49+ >(base_t ::m_spheroid);
50+ }
51+ };
52+
1953template <typename Formula, bool Clockwise, typename Point, typename Spheroid>
2054void test_linestring (std::string const & label, Spheroid const & spheroid,
2155 double expected_area_round, double expected_area_miter)
@@ -25,7 +59,9 @@ void test_linestring(std::string const& label, Spheroid const& spheroid,
2559
2660 ut_settings settings (0.1 );
2761
28- bg::strategies::buffer::geographic<Formula, Spheroid> strategy (spheroid);
62+ using CT = typename bg::coordinate_type<Point>::type;
63+ geo_buffer_accurate_area<Formula, Spheroid, CT> strategy (spheroid);
64+
2965 bg::strategy::buffer::geographic_side_straight<Formula, Spheroid> side (spheroid);
3066 bg::strategy::buffer::geographic_join_miter<Formula, Spheroid> join_miter (spheroid);
3167 bg::strategy::buffer::geographic_join_round<Formula, Spheroid> join_round (spheroid, points_per_circle);
@@ -45,7 +81,9 @@ void test_point(std::string const& label, Spheroid const& spheroid, double expec
4581
4682 ut_settings settings (0.01 );
4783
48- bg::strategies::buffer::geographic<Formula, Spheroid> strategy (spheroid);
84+ using CT = typename bg::coordinate_type<Point>::type;
85+ geo_buffer_accurate_area<Formula, Spheroid, CT> strategy (spheroid);
86+
4987 bg::strategy::buffer::geographic_point_circle<Formula, Spheroid> circle (spheroid, points_per_circle);
5088
5189 // All are ignored for points
@@ -57,24 +95,31 @@ void test_point(std::string const& label, Spheroid const& spheroid, double expec
5795 test_one_geo<Point, polygon>(label, torg, strategy, side, circle, join_round, end_round, expected_area, 100.0 , settings);
5896}
5997
60- int test_main (int , char * [])
98+ template <typename test_type>
99+ void test_all ()
61100{
62- BoostGeometryWriteTestConfiguration ();
63-
64- using test_type = default_test_type;
65-
66101 using point_t = bg::model::point<test_type, 2 , bg::cs::geographic<bg::degree>>;
102+ using strategy = bg::strategy::andoyer;
67103
68104 // Use the default spheroid
69105 bg::srs::spheroid<test_type> def_spheroid;
70- test_linestring<bg:: strategy::andoyer , true , point_t >(" line_def" , def_spheroid, 7996.0 , 8093.0 );
71- test_point<bg:: strategy::andoyer , true , point_t >(" point_def" , def_spheroid, 31450.0 );
106+ test_linestring<strategy, true , point_t >(" line_def" , def_spheroid, 8046.26 , 8143.37 );
107+ test_point<strategy, true , point_t >(" point_def" , def_spheroid, 31414.36 );
72108
73109 // Call it with a quite different spheroid (a near sphere), this changes internal geographic calculations
74110 // and should result in different areas. Using CSV creation, it's visible in QGis.
75111 bg::srs::spheroid<test_type> alt_spheroid (6378000.0 , 6375000.0 );
76- test_linestring<bg::strategy::andoyer, true , point_t >(" line_alt" , alt_spheroid, 8097.0 , 8115.3 );
77- test_point<bg::strategy::andoyer, true , point_t >(" point_alt" , alt_spheroid, 31409.0 );
112+ test_linestring<strategy, true , point_t >(" line_alt" , alt_spheroid, 8030.53 , 8127.61 );
113+ test_point<strategy, true , point_t >(" point_alt" , alt_spheroid, 31414.33 );
114+ }
115+
116+ int test_main (int , char * [])
117+ {
118+ BoostGeometryWriteTestConfiguration ();
119+
120+ // There are several issues with float type such as invalid geometries as output and assertion fails
121+ // test_all<float>();
122+ test_all<default_test_type>();
78123
79124 return 0 ;
80125}
0 commit comments