[strategies] Remove distance() dependency from weighted_length strategy.

Also add optional CalculationType.
This commit is contained in:
Adam Wulkiewicz 2021-03-11 00:45:08 +01:00
parent edc2aa5051
commit 6eb9e238bc
3 changed files with 21 additions and 15 deletions

View File

@ -21,17 +21,17 @@
#include <boost/math/special_functions/fpclassify.hpp> #include <boost/math/special_functions/fpclassify.hpp>
#include <boost/numeric/conversion/cast.hpp> #include <boost/numeric/conversion/cast.hpp>
#include <boost/geometry/algorithms/detail/distance/interface.hpp>
#include <boost/geometry/algorithms/detail/distance/point_to_geometry.hpp>
#include <boost/geometry/arithmetic/arithmetic.hpp> #include <boost/geometry/arithmetic/arithmetic.hpp>
#include <boost/geometry/util/for_each_coordinate.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
#include <boost/geometry/strategies/centroid.hpp>
#include <boost/geometry/strategies/default_distance_result.hpp>
// Helper geometry // Helper geometry
#include <boost/geometry/geometries/point.hpp> #include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
#include <boost/geometry/strategies/centroid.hpp>
#include <boost/geometry/util/for_each_coordinate.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
namespace boost { namespace geometry namespace boost { namespace geometry
{ {
@ -42,19 +42,24 @@ namespace strategy { namespace centroid
template template
< <
typename Ignored1 = void, typename Ignored1 = void,
typename Ignored2 = void typename Ignored2 = void,
typename CalculationType = void
> >
class weighted_length class weighted_length
{ {
private : private :
typedef geometry::strategy::distance::pythagoras<CalculationType> pythagoras_strategy;
template <typename GeometryPoint, typename ResultPoint> template <typename GeometryPoint, typename ResultPoint>
struct calculation_type 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<GeometryPoint>::type, GeometryPoint, ResultPoint
typename default_distance_result<ResultPoint>::type >::type type;
> };
{};
template <typename GeometryPoint, typename ResultPoint> template <typename GeometryPoint, typename ResultPoint>
class sums class sums
@ -94,7 +99,7 @@ public :
{ {
typedef typename calculation_type<GeometryPoint, ResultPoint>::type distance_type; typedef typename calculation_type<GeometryPoint, ResultPoint>::type distance_type;
distance_type const d = geometry::distance(p1, p2); distance_type const d = pythagoras_strategy::apply(p1, p2);
state.length += d; state.length += d;
typename sums<GeometryPoint, ResultPoint>::work_point weighted_median; typename sums<GeometryPoint, ResultPoint>::work_point weighted_median;

View File

@ -48,7 +48,7 @@ struct cartesian
util::is_polylinear<Geometry>::value util::is_polylinear<Geometry>::value
> * = nullptr) > * = nullptr)
{ {
return strategy::centroid::weighted_length<>(); return strategy::centroid::weighted_length<void, void, CalculationType>();
} }
template <typename Geometry> template <typename Geometry>

View File

@ -1,6 +1,6 @@
// Boost.Geometry // 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 // 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. // These includes are required for the following code to compile.
// This is probably wrong. // This is probably wrong.
#include <boost/geometry/algorithms/comparable_distance.hpp>
#include <boost/geometry/algorithms/covered_by.hpp> #include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/disjoint.hpp> #include <boost/geometry/algorithms/disjoint.hpp>
#include <boost/geometry/algorithms/equals.hpp> #include <boost/geometry/algorithms/equals.hpp>