Skip to content

Commit

Permalink
[strategies] Remove distance() dependency from weighted_length strategy.
Browse files Browse the repository at this point in the history
Also add optional CalculationType.
  • Loading branch information
awulkiew committed Mar 10, 2021
1 parent edc2aa5 commit 6eb9e23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
#include <boost/math/special_functions/fpclassify.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/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
#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
{
Expand All @@ -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<CalculationType> pythagoras_strategy;

template <typename GeometryPoint, typename ResultPoint>
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,
typename default_distance_result<ResultPoint>::type
>
{};
GeometryPoint, ResultPoint
>::type type;
};

template <typename GeometryPoint, typename ResultPoint>
class sums
Expand Down Expand Up @@ -94,7 +99,7 @@ public :
{
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;

typename sums<GeometryPoint, ResultPoint>::work_point weighted_median;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/geometry/strategies/centroid/cartesian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct cartesian
util::is_polylinear<Geometry>::value
> * = nullptr)
{
return strategy::centroid::weighted_length<>();
return strategy::centroid::weighted_length<void, void, CalculationType>();
}

template <typename Geometry>
Expand Down
3 changes: 2 additions & 1 deletion test/cs_undefined/index.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -11,6 +11,7 @@

// These includes are required for the following code to compile.
// This is probably wrong.
#include <boost/geometry/algorithms/comparable_distance.hpp>
#include <boost/geometry/algorithms/covered_by.hpp>
#include <boost/geometry/algorithms/disjoint.hpp>
#include <boost/geometry/algorithms/equals.hpp>
Expand Down

0 comments on commit 6eb9e23

Please sign in to comment.