From 6eb9e238bcb37e26dc31d16acf826784a2ba30f4 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Thu, 11 Mar 2021 00:45:08 +0100 Subject: [PATCH] [strategies] Remove distance() dependency from weighted_length strategy. Also add optional CalculationType. --- .../cartesian/centroid_weighted_length.hpp | 31 +++++++++++-------- .../strategies/centroid/cartesian.hpp | 2 +- test/cs_undefined/index.cpp | 3 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp b/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp index bb7dea775..115956fa3 100644 --- a/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp +++ b/include/boost/geometry/strategies/cartesian/centroid_weighted_length.hpp @@ -21,17 +21,17 @@ #include #include -#include -#include #include -#include -#include -#include -#include // Helper geometry #include +#include +#include + +#include +#include + namespace boost { namespace geometry { @@ -42,19 +42,24 @@ namespace strategy { namespace centroid template < typename Ignored1 = void, - typename Ignored2 = void + typename Ignored2 = void, + typename CalculationType = void > class weighted_length { private : + typedef geometry::strategy::distance::pythagoras pythagoras_strategy; + template struct calculation_type - : select_most_precise + { + // Below the distance between two GeometryPoints is calculated. + // ResultPoint is taken into account by passing them together here. + typedef typename pythagoras_strategy::template calculation_type < - typename default_distance_result::type, - typename default_distance_result::type - > - {}; + GeometryPoint, ResultPoint + >::type type; + }; template class sums @@ -94,7 +99,7 @@ public : { typedef typename calculation_type::type distance_type; - distance_type const d = geometry::distance(p1, p2); + distance_type const d = pythagoras_strategy::apply(p1, p2); state.length += d; typename sums::work_point weighted_median; diff --git a/include/boost/geometry/strategies/centroid/cartesian.hpp b/include/boost/geometry/strategies/centroid/cartesian.hpp index 6870919a7..14b45155a 100644 --- a/include/boost/geometry/strategies/centroid/cartesian.hpp +++ b/include/boost/geometry/strategies/centroid/cartesian.hpp @@ -48,7 +48,7 @@ struct cartesian util::is_polylinear::value > * = nullptr) { - return strategy::centroid::weighted_length<>(); + return strategy::centroid::weighted_length(); } template diff --git a/test/cs_undefined/index.cpp b/test/cs_undefined/index.cpp index 5908aa248..4a3ef8676 100644 --- a/test/cs_undefined/index.cpp +++ b/test/cs_undefined/index.cpp @@ -1,6 +1,6 @@ // Boost.Geometry -// Copyright (c) 2019-2020, Oracle and/or its affiliates. +// Copyright (c) 2019-2021, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle @@ -11,6 +11,7 @@ // These includes are required for the following code to compile. // This is probably wrong. +#include #include #include #include