From f83cb027b5b9fa7ed05dc5f15fd33c6aad7f3886 Mon Sep 17 00:00:00 2001 From: Vissarion Fysikopoulos Date: Mon, 18 Feb 2019 14:04:32 +0200 Subject: [PATCH] [strategy] [test] Use radius in spherical line_interpolate strategy --- .../spherical/line_interpolate_point.hpp | 25 ++- test/algorithms/line_interpolate_point.cpp | 171 +++++++++++------- 2 files changed, 121 insertions(+), 75 deletions(-) diff --git a/include/boost/geometry/strategies/spherical/line_interpolate_point.hpp b/include/boost/geometry/strategies/spherical/line_interpolate_point.hpp index 79e18efff..04c693433 100644 --- a/include/boost/geometry/strategies/spherical/line_interpolate_point.hpp +++ b/include/boost/geometry/strategies/spherical/line_interpolate_point.hpp @@ -48,6 +48,19 @@ class spherical { public: + typedef typename DistanceStrategy::radius_type radius_type; + + inline spherical() + {} + + explicit inline spherical(typename DistanceStrategy::radius_type const& r) + : m_strategy(r) + {} + + inline spherical(DistanceStrategy const& s) + : m_strategy(s) + {} + // point-point strategy getters struct distance_pp_strategy { @@ -56,8 +69,7 @@ public: inline typename distance_pp_strategy::type get_distance_pp_strategy() const { - typedef typename distance_pp_strategy::type distance_type; - return distance_type(); + return m_strategy; } template @@ -65,7 +77,7 @@ public: Point const& p1, Fraction const& fraction, Point & p, - Distance const& distance) const + Distance const&) const { typedef typename select_calculation_type_alt < @@ -80,9 +92,8 @@ public: typedef model::point point3d_t; point3d_t const xyz0 = formula::sph_to_cart3d(p0); point3d_t const xyz1 = formula::sph_to_cart3d(p1); - //calc_t const dot01 = geometry::dot_product(xyz0, xyz1); - //calc_t const angle01 = acos(dot01); - calc_t const angle01 = distance; + calc_t const dot01 = geometry::dot_product(xyz0, xyz1); + calc_t const angle01 = acos(dot01); point3d_t axis; if (! math::equals(angle01, pi)) @@ -135,6 +146,8 @@ public: p = formula::cart3d_to_sph(v_rot); } +private : + DistanceStrategy m_strategy; }; diff --git a/test/algorithms/line_interpolate_point.cpp b/test/algorithms/line_interpolate_point.cpp index 2c6b15b12..f35350c38 100644 --- a/test/algorithms/line_interpolate_point.cpp +++ b/test/algorithms/line_interpolate_point.cpp @@ -115,11 +115,28 @@ inline void test_distance(std::string const& wkt1, check_points

::apply(p1, o); } +template +inline void test_distance(std::string const& wkt1, + double distance, + std::string const& wkt2, + S str) +{ + G g; + bg::read_wkt(wkt1, g); + + P o; + bg::read_wkt(wkt2, o); + + P p1; + bg::line_interpolate_point(g, distance, p1, str); + check_points

::apply(p1, o); +} + std::string const s = "SEGMENT(1 1, 2 2)"; -std::string const l = "LINESTRING(1 1, 2 1, 2 2, 1 2, 1 3)"; -std::string const l0 = "LINESTRING()"; -std::string const l1 = "LINESTRING(1 1)"; +std::string const l1 = "LINESTRING(1 1, 2 1, 2 2, 1 2, 1 3)"; std::string const l2 = "LINESTRING(0 2, 5 2, 5 1, 20 1)"; +std::string const l00 = "LINESTRING()"; +std::string const l01 = "LINESTRING(1 1)"; void test_car_edge_cases() { @@ -128,21 +145,21 @@ void test_car_edge_cases() typedef bg::model::linestring

LS; //negative input distance - test_distance(l, -1, "POINT(1 1)"); - test_distance(l, -1, "MULTIPOINT((1 1))"); + test_distance(l1, -1, "POINT(1 1)"); + test_distance(l1, -1, "MULTIPOINT((1 1))"); //input distance longer than total length - test_distance(l, 5, "POINT(1 3)"); - test_distance(l, 5, "MULTIPOINT((1 3))"); + test_distance(l1, 5, "POINT(1 3)"); + test_distance(l1, 5, "MULTIPOINT((1 3))"); //linestring with only one point - test_distance(l1, 1, "POINT(1 1)"); - test_distance(l1, 1, "MULTIPOINT((1 1))"); + test_distance(l01, 1, "POINT(1 1)"); + test_distance(l01, 1, "MULTIPOINT((1 1))"); //empty linestring try { - test_distance(l0, 1, "POINT(1 1)"); + test_distance(l00, 1, "POINT(1 1)"); } catch(bg::empty_input_exception const& ) { @@ -162,30 +179,30 @@ void test_car() test(s, 0.5, "POINT(1.5 1.5)"); test(s, 1, "POINT(2 2)"); - test(l, 0, "POINT(1 1)"); - test(l, 0.1, "POINT(1.4 1)"); - test(l, 0.2, "POINT(1.8 1)"); - test(l, 0.3, "POINT(2 1.2)"); - test(l, 0.4, "POINT(2 1.6)"); - test(l, 0.5, "POINT(2 2)"); - test(l, 0.6, "POINT(1.6 2)"); - test(l, 0.7, "POINT(1.2 2)"); - test(l, 0.8, "POINT(1 2.2)"); - test(l, 0.9, "POINT(1 2.6)"); - test(l, 1, "POINT(1 3)"); + test(l1, 0, "POINT(1 1)"); + test(l1, 0.1, "POINT(1.4 1)"); + test(l1, 0.2, "POINT(1.8 1)"); + test(l1, 0.3, "POINT(2 1.2)"); + test(l1, 0.4, "POINT(2 1.6)"); + test(l1, 0.5, "POINT(2 2)"); + test(l1, 0.6, "POINT(1.6 2)"); + test(l1, 0.7, "POINT(1.2 2)"); + test(l1, 0.8, "POINT(1 2.2)"); + test(l1, 0.9, "POINT(1 2.6)"); + test(l1, 1, "POINT(1 3)"); - test(l, 0, "MULTIPOINT((1 1))"); + test(l1, 0, "MULTIPOINT((1 1))"); //(1 3) missing due to floating point round off errors - test(l, 0.1, "MULTIPOINT((1.4 1)(1.8 1)(2 1.2)(2 1.6)(2 2)(1.6 2)\ + test(l1, 0.1, "MULTIPOINT((1.4 1)(1.8 1)(2 1.2)(2 1.6)(2 2)(1.6 2)\ (1.2 2)(1 2.2)(1 2.6))"); //(1 3) is not missing if you directly pass the distance - test_distance(l, 0.4, "MULTIPOINT((1.4 1)(1.8 1)(2 1.2)(2 1.6)(2 2)(1.6 2)\ + test_distance(l1, 0.4, "MULTIPOINT((1.4 1)(1.8 1)(2 1.2)(2 1.6)(2 2)(1.6 2)\ (1.2 2)(1 2.2)(1 2.6)(1 3))"); - test(l, 0.2, "MULTIPOINT((1.8 1)(2 1.6)(1.6 2)(1 2.2))");//(1 3) missing - test(l, 0.4, "MULTIPOINT((2 1.6)(1 2.2))"); - test(l, 0.5, "MULTIPOINT((2 2)(1 3))"); - test(l, 0.6, "MULTIPOINT((1.6 2))"); - test(l, 1, "MULTIPOINT((1 3))"); + test(l1, 0.2, "MULTIPOINT((1.8 1)(2 1.6)(1.6 2)(1 2.2))");//(1 3) missing + test(l1, 0.4, "MULTIPOINT((2 1.6)(1 2.2))"); + test(l1, 0.5, "MULTIPOINT((2 2)(1 3))"); + test(l1, 0.6, "MULTIPOINT((1.6 2))"); + test(l1, 1, "MULTIPOINT((1 3))"); } void test_sph() @@ -199,20 +216,20 @@ void test_sph() test(s, 0.5, "POINT(1.4998857365615981 1.5000570914791198)"); test(s, 1, "POINT(2 2)"); - test(l, 0, "POINT(1 1)"); - test(l, 0.1, "POINT(1.39998476912905323 1.0000365473536286)"); - test(l, 0.2, "POINT(1.79996953825810646 1.0000243679448551)"); - test(l, 0.3, "POINT(2 1.1999238595669637)"); - test(l, 0.4, "POINT(2 1.5998477098527744)"); - test(l, 0.5, "POINT(2 1.9997715601390484)"); - test(l, 0.6, "POINT(1.6000609543036084 2.0000730473928678)"); - test(l, 0.7, "POINT(1.1998933176222553 2.0000486811516014)"); - test(l, 0.8, "POINT(1 2.2001522994279883)"); - test(l, 0.9, "POINT(1 2.6000761497139444)"); - test(l, 1, "POINT(1 3)"); + test(l1, 0, "POINT(1 1)"); + test(l1, 0.1, "POINT(1.39998476912905323 1.0000365473536286)"); + test(l1, 0.2, "POINT(1.79996953825810646 1.0000243679448551)"); + test(l1, 0.3, "POINT(2 1.1999238595669637)"); + test(l1, 0.4, "POINT(2 1.5998477098527744)"); + test(l1, 0.5, "POINT(2 1.9997715601390484)"); + test(l1, 0.6, "POINT(1.6000609543036084 2.0000730473928678)"); + test(l1, 0.7, "POINT(1.1998933176222553 2.0000486811516014)"); + test(l1, 0.8, "POINT(1 2.2001522994279883)"); + test(l1, 0.9, "POINT(1 2.6000761497139444)"); + test(l1, 1, "POINT(1 3)"); - test(l, 0, "MULTIPOINT((1 1))"); - test(l, 0.1, "MULTIPOINT((1.39998476912905323 1.0000365473536286)\ + test(l1, 0, "MULTIPOINT((1 1))"); + test(l1, 0.1, "MULTIPOINT((1.39998476912905323 1.0000365473536286)\ (1.79996953825810646 1.0000243679448551)\ (2 1.1999238595669637)\ (2 1.5998477098527744)\ @@ -222,15 +239,15 @@ void test_sph() (1 2.2001522994279883)\ (1 2.6000761497139444)\ )");//(1,3) - test(l, 0.2, "MULTIPOINT((1.79996953825810646 1.0000243679448551)\ + test(l1, 0.2, "MULTIPOINT((1.79996953825810646 1.0000243679448551)\ (2 1.5998477098527744)\ (1.6000609543036084 2.0000730473928678)\ (1 2.2001522994279883)\ )");//(1,3) - test(l, 0.4, "MULTIPOINT((2 1.5998477098527744)(1 2.2001522994279883))"); - test(l, 0.5, "MULTIPOINT((2 1.9997715601385837)(1 3))"); - test(l, 0.6, "MULTIPOINT((1.6000609543036084 2.0000730473928678))"); - test(l, 1, "MULTIPOINT((1 3))"); + test(l1, 0.4, "MULTIPOINT((2 1.5998477098527744)(1 2.2001522994279883))"); + test(l1, 0.5, "MULTIPOINT((2 1.9997715601385837)(1 3))"); + test(l1, 0.6, "MULTIPOINT((1.6000609543036084 2.0000730473928678))"); + test(l1, 1, "MULTIPOINT((1 3))"); test(l2, 0.3, "MULTIPOINT((5.3014893312120446 1.0006787676128222)\ (11.600850053156366 1.0085030143490989)\ @@ -238,6 +255,20 @@ void test_sph() } +template +void test_sph(Strategy str) +{ + typedef bg::model::point > P; + typedef bg::model::segment

S; + + test_distance(s, 0, "POINT(1 1)", str); + test_distance(s, 0.01, "POINT(1.4051065077123643 1.405268220524982)"); + test_distance(s, 0.01, "POINT(1.0040505023484179 1.0040529633262307)", str); + test_distance(s, 1, "POINT(1.4051065077123015 1.405268220524919)", str); + test_distance(s, 1, "POINT(2 2)"); + test_distance(s, 10, "POINT(2 2)"); +} + template void test_geo(Strategy str) { @@ -250,26 +281,26 @@ void test_geo(Strategy str) test(s, 0.5, "POINT(1.4998780900539985 1.5000558288006378)", str); test(s, 1, "POINT(2 2)", str); - test(l, 0, "POINT(1 1)", str); - test(l, 0.1, "POINT(1.3986445638301882 1.0000367522730751)", str); - test(l, 0.2, "POINT(1.79728912766037641 1.0000247772611039)", str); - test(l, 0.3, "POINT(2 1.1972285554368427)", str); - test(l, 0.4, "POINT(2 1.598498298996567)", str); - test(l, 0.5, "POINT(2 1.9997664696834965)", str); - test(l, 0.6, "POINT(1.6013936980010324 2.0000734568388099)", str); - test(l, 0.7, "POINT(1.2025664628960846 2.0000494983098767)", str); - test(l, 0.8, "POINT(1 2.1974612279909937)", str); - test(l, 0.9, "POINT(1 2.5987263175375022)", str); - test(l, 1, "POINT(1 3)", str); + test(l1, 0, "POINT(1 1)", str); + test(l1, 0.1, "POINT(1.3986445638301882 1.0000367522730751)", str); + test(l1, 0.2, "POINT(1.79728912766037641 1.0000247772611039)", str); + test(l1, 0.3, "POINT(2 1.1972285554368427)", str); + test(l1, 0.4, "POINT(2 1.598498298996567)", str); + test(l1, 0.5, "POINT(2 1.9997664696834965)", str); + test(l1, 0.6, "POINT(1.6013936980010324 2.0000734568388099)", str); + test(l1, 0.7, "POINT(1.2025664628960846 2.0000494983098767)", str); + test(l1, 0.8, "POINT(1 2.1974612279909937)", str); + test(l1, 0.9, "POINT(1 2.5987263175375022)", str); + test(l1, 1, "POINT(1 3)", str); - test(l, 0, "MULTIPOINT((1 1))", str); + test(l1, 0, "MULTIPOINT((1 1))", str); //adnoyer is missing the last point in the following cases // of linestrings due to inaccuracy if (!boost::is_same >::value) { - test(l, 0.1, "MULTIPOINT((1.3986445638301882 1.0000367522730751)\ + test(l1, 0.1, "MULTIPOINT((1.3986445638301882 1.0000367522730751)\ (1.79728912766037641 1.0000247772582571)\ (2 1.1972285554368427)\ (2 1.598498298996567)\ @@ -280,16 +311,16 @@ void test_geo(Strategy str) (1 2.5987263175375022)\ (1 3))", str); - test(l, 0.2, "MULTIPOINT((1.79728912766037641 1.0000247772613331)\ - (2 1.598498298996567)\ - (1.6013936980010324 2.0000734568388099)\ - (1 2.1974612279909937)\ - (1 3))", str); + test(l1, 0.2, "MULTIPOINT((1.79728912766037641 1.0000247772613331)\ + (2 1.598498298996567)\ + (1.6013936980010324 2.0000734568388099)\ + (1 2.1974612279909937)\ + (1 3))", str); } - test(l, 0.4, "MULTIPOINT((2 1.598498298996567)(1 2.1974612279909937))", str); - test(l, 0.5, "MULTIPOINT((2 1.9997664696834965)(1 3))", str); - test(l, 0.6, "MULTIPOINT((1.6013936980010324 2.0000734568388099))", str); - test(l, 1, "MULTIPOINT((1 3))", str); + test(l1, 0.4, "MULTIPOINT((2 1.598498298996567)(1 2.1974612279909937))", str); + test(l1, 0.5, "MULTIPOINT((2 1.9997664696834965)(1 3))", str); + test(l1, 0.6, "MULTIPOINT((1.6013936980010324 2.0000734568388099))", str); + test(l1, 1, "MULTIPOINT((1 3))", str); test(l2, 0.3, "MULTIPOINT((5.306157814 1.0006937303)\ (11.60351281 1.0085614548123072)\ @@ -311,7 +342,9 @@ int test_main(int, char* []) { test_car(); test_car_edge_cases(); + test_sph(); + test_sph(bg::strategy::line_interpolate_point::spherical<>(100)); typedef typename bg::srs::spheroid stype;