Merge pull request #47 from mkaravel/feature/distance-default-strategy

Feature/distance default strategy
This commit is contained in:
Barend Gehrels
2014-05-28 15:30:45 +02:00
12 changed files with 65 additions and 34 deletions

View File

@@ -43,7 +43,7 @@ namespace detail { namespace distance
template
<
typename Geometry1,
typename Geometry2,
typename Geometry2 = Geometry1,
typename Tag1 = typename tag_cast
<
typename tag<Geometry1>::type, pointlike_tag
@@ -57,7 +57,7 @@ template
struct default_strategy
: strategy::distance::services::default_strategy
<
segment_tag,
point_tag, segment_tag,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>
@@ -82,7 +82,7 @@ struct default_strategy
pointlike_tag, pointlike_tag, false
> : strategy::distance::services::default_strategy
<
point_tag,
point_tag, point_tag,
typename point_type<Pointlike1>::type,
typename point_type<Pointlike2>::type
>
@@ -93,13 +93,12 @@ template <typename Pointlike, typename Box>
struct default_strategy<Pointlike, Box, pointlike_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
point_tag,
point_tag, box_tag,
typename point_type<Pointlike>::type,
typename point_type<Box>::type,
cartesian_tag,
cartesian_tag,
void,
box_tag
void
>
{};
@@ -108,13 +107,12 @@ template <typename Box1, typename Box2>
struct default_strategy<Box1, Box2, box_tag, box_tag, false>
: strategy::distance::services::default_strategy
<
box_tag,
box_tag, box_tag,
typename point_type<Box1>::type,
typename point_type<Box2>::type,
cartesian_tag,
cartesian_tag,
void,
box_tag
void
>
{};
@@ -125,7 +123,7 @@ template <typename Geometry1, typename Geometry2, typename Strategy>
struct default_ps_strategy
: strategy::distance::services::default_strategy
<
segment_tag,
point_tag, segment_tag,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type,
typename cs_tag<typename point_type<Geometry1>::type>::type,

View File

@@ -241,7 +241,7 @@ length(Geometry const& geometry)
// TODO put this into a resolve_strategy stage
typedef typename strategy::distance::services::default_strategy
<
point_tag, typename point_type<Geometry>::type
point_tag, point_tag, typename point_type<Geometry>::type
>::type strategy_type;
return resolve_variant::length<Geometry>::apply(geometry, strategy_type());

View File

@@ -101,8 +101,7 @@ struct perimeter
{
typedef typename strategy::distance::services::default_strategy
<
point_tag,
typename point_type<Geometry>::type
point_tag, point_tag, typename point_type<Geometry>::type
>::type strategy_type;
return dispatch::perimeter<Geometry>::apply(geometry, strategy_type());

View File

@@ -34,6 +34,8 @@
#include <boost/geometry/algorithms/convert.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
#include <boost/geometry/algorithms/detail/distance/default_strategies.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
@@ -280,7 +282,7 @@ struct simplify
typedef typename strategy::distance::services::default_strategy
<
segment_tag, point_type
point_tag, segment_tag, point_type
>::type ds_strategy_type;
typedef strategy::simplify::douglas_peucker
@@ -323,7 +325,7 @@ struct simplify_insert
typedef typename strategy::distance::services::default_strategy
<
segment_tag, point_type
point_tag, segment_tag, point_type
>::type ds_strategy_type;
typedef strategy::simplify::douglas_peucker

View File

@@ -229,7 +229,11 @@ public :
// of point-to-segment or point-to-linestring.
// Convenient for geographic coordinate systems especially.
template <typename Point, typename PointOfSegment, typename Strategy>
struct default_strategy<segment_tag, Point, PointOfSegment, cartesian_tag, cartesian_tag, Strategy>
struct default_strategy
<
point_tag, segment_tag, Point, PointOfSegment,
cartesian_tag, cartesian_tag, Strategy
>
{
typedef strategy::distance::projected_point
<
@@ -239,7 +243,7 @@ struct default_strategy<segment_tag, Point, PointOfSegment, cartesian_tag, carte
boost::is_void<Strategy>,
typename default_strategy
<
point_tag, Point, PointOfSegment,
point_tag, point_tag, Point, PointOfSegment,
cartesian_tag, cartesian_tag
>::type,
Strategy

View File

@@ -271,7 +271,10 @@ public :
template <typename Point1, typename Point2>
struct default_strategy<point_tag, Point1, Point2, cartesian_tag, cartesian_tag, void>
struct default_strategy
<
point_tag, point_tag, Point1, Point2, cartesian_tag, cartesian_tag
>
{
typedef pythagoras<> type;
};

View File

@@ -318,7 +318,7 @@ public :
template <typename Box1, typename Box2>
struct default_strategy
<
box_tag, Box1, Box2, cartesian_tag, cartesian_tag, void, box_tag
box_tag, box_tag, Box1, Box2, cartesian_tag, cartesian_tag
>
{
typedef pythagoras_box_box<> type;

View File

@@ -314,7 +314,10 @@ public :
template <typename Point, typename Box>
struct default_strategy<point_tag, Point, Box, cartesian_tag, cartesian_tag, void, box_tag>
struct default_strategy
<
point_tag, box_tag, Point, Box, cartesian_tag, cartesian_tag
>
{
typedef pythagoras_point_box<> type;
};

View File

@@ -1,8 +1,13 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// This file was modified by Oracle on 2014.
// Modifications copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@@ -70,7 +75,8 @@ struct result_from_distance {};
\brief Traits class binding a default strategy for distance
to one (or possibly two) coordinate system(s)
\ingroup distance
\tparam GeometryTag tag (point/segment) for which this strategy is the default
\tparam GeometryTag1 tag (point/segment/box) for which this strategy is the default
\tparam GeometryTag2 tag (point/segment/box) for which this strategy is the default
\tparam Point1 first point-type
\tparam Point2 second point-type
\tparam CsTag1 tag of coordinate system of first point type
@@ -78,13 +84,13 @@ struct result_from_distance {};
*/
template
<
typename GeometryTag,
typename GeometryTag1,
typename GeometryTag2,
typename Point1,
typename Point2 = Point1,
typename CsTag1 = typename cs_tag<Point1>::type,
typename CsTag2 = typename cs_tag<Point2>::type,
typename UnderlyingStrategy = void,
typename GeometryTag2 = GeometryTag
typename UnderlyingStrategy = void
>
struct default_strategy
{

View File

@@ -284,7 +284,7 @@ struct default_strategy
template <typename Point, typename PointOfSegment, typename Strategy>
struct default_strategy
<
segment_tag, Point, PointOfSegment,
point_tag, segment_tag, Point, PointOfSegment,
spherical_equatorial_tag, spherical_equatorial_tag,
Strategy
>
@@ -297,7 +297,7 @@ struct default_strategy
boost::is_void<Strategy>,
typename default_strategy
<
point_tag, Point, PointOfSegment,
point_tag, point_tag, Point, PointOfSegment,
spherical_equatorial_tag, spherical_equatorial_tag
>::type,
Strategy

View File

@@ -279,7 +279,11 @@ public :
// Register it as the default for point-types
// in a spherical equatorial coordinate system
template <typename Point1, typename Point2>
struct default_strategy<point_tag, Point1, Point2, spherical_equatorial_tag, spherical_equatorial_tag>
struct default_strategy
<
point_tag, point_tag, Point1, Point2,
spherical_equatorial_tag, spherical_equatorial_tag
>
{
typedef strategy::distance::haversine<typename select_coordinate_type<Point1, Point2>::type> type;
};

View File

@@ -72,7 +72,10 @@ void test_distance_point()
BOOST_CHECK_CLOSE(d, return_type(1.4142135), 0.001);
// Test specifying strategy manually
typename services::default_strategy<bg::point_tag, P>::type strategy;
typename services::default_strategy
<
bg::point_tag, bg::point_tag, P
>::type strategy;
d = bg::distance(p1, p2, strategy);
BOOST_CHECK_CLOSE(d, return_type(1.4142135), 0.001);
@@ -93,7 +96,10 @@ void test_distance_point()
{
// test comparability
typedef typename services::default_strategy<bg::point_tag, P>::type strategy_type;
typedef typename services::default_strategy
<
bg::point_tag, bg::point_tag, P
>::type strategy_type;
typedef typename services::comparable_type<strategy_type>::type comparable_strategy_type;
strategy_type strategy;
@@ -143,12 +149,18 @@ void test_distance_segment()
// Test specifying strategy manually:
// 1) point-point-distance
typename bg::strategy::distance::services::default_strategy<bg::point_tag, P>::type pp_strategy;
typename bg::strategy::distance::services::default_strategy
<
bg::point_tag, bg::point_tag, P
>::type pp_strategy;
d1 = bg::distance(p1, seg, pp_strategy);
BOOST_CHECK_CLOSE(d1, return_type(1), 0.001);
// 2) point-segment-distance
typename bg::strategy::distance::services::default_strategy<bg::segment_tag, P>::type ps_strategy;
typename bg::strategy::distance::services::default_strategy
<
bg::point_tag, bg::segment_tag, P
>::type ps_strategy;
d1 = bg::distance(p1, seg, ps_strategy);
BOOST_CHECK_CLOSE(d1, return_type(1), 0.001);