Merge pull request #86 from mkaravel/feature/length_perimeter_result

Feature/length perimeter result
This commit is contained in:
Adam Wulkiewicz
2014-07-10 23:35:26 +02:00
3 changed files with 89 additions and 56 deletions

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.
@@ -181,36 +186,21 @@ namespace resolve_variant {
template <typename Geometry>
struct length
{
typedef typename default_length_result<Geometry>::type result_type;
template <typename Strategy>
static inline result_type apply(Geometry const& geometry,
Strategy const& strategy)
static inline typename default_length_result<Geometry>::type
apply(Geometry const& geometry, Strategy const& strategy)
{
return dispatch::length<Geometry>::apply(geometry, strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct length<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
struct length<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
typedef typename mpl::fold<
typename mpl::transform<
typename variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
default_length_result<mpl::_>
>::type,
mpl::set0<>,
mpl::insert<mpl::_1, mpl::_2>
>::type possible_result_types;
typedef typename mpl::if_<
mpl::greater<
mpl::size<possible_result_types>,
mpl::int_<1>
>,
typename make_variant_over<possible_result_types>::type,
typename mpl::front<possible_result_types>::type
>::type result_type;
typedef typename default_length_result
<
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>
>::type result_type;
template <typename Strategy>
struct visitor
@@ -223,7 +213,7 @@ struct length<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{}
template <typename Geometry>
inline typename length<Geometry>::result_type
inline typename default_length_result<Geometry>::type
operator()(Geometry const& geometry) const
{
return length<Geometry>::apply(geometry, m_strategy);
@@ -255,7 +245,7 @@ struct length<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
\qbk{[length] [length_output]}
*/
template<typename Geometry>
inline typename resolve_variant::length<Geometry>::result_type
inline typename default_length_result<Geometry>::type
length(Geometry const& geometry)
{
concept::check<Geometry const>();
@@ -287,7 +277,7 @@ length(Geometry const& geometry)
\qbk{[length_with_strategy] [length_with_strategy_output]}
*/
template<typename Geometry, typename Strategy>
inline typename resolve_variant::length<Geometry>::result_type
inline typename default_length_result<Geometry>::type
length(Geometry const& geometry, Strategy const& strategy)
{
concept::check<Geometry const>();

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.
@@ -30,8 +35,6 @@
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/strategies/default_length_result.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/compress_variant.hpp>
#include <boost/geometry/util/transform_variant.hpp>
namespace boost { namespace geometry
{
@@ -134,10 +137,8 @@ namespace resolve_variant {
template <typename Geometry>
struct perimeter
{
typedef typename default_length_result<Geometry>::type result_type;
template <typename Strategy>
static inline result_type
static inline typename default_length_result<Geometry>::type
apply(Geometry const& geometry, Strategy const& strategy)
{
concept::check<Geometry const>();
@@ -148,12 +149,10 @@ struct perimeter
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct perimeter<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
typedef typename compress_variant<
typename transform_variant<
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
default_length_result<boost::mpl::placeholders::_>
>::type
>:: type result_type;
typedef typename default_length_result
<
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>
>::type result_type;
template <typename Strategy>
struct visitor: boost::static_visitor<result_type>
@@ -163,7 +162,8 @@ struct perimeter<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
visitor(Strategy const& strategy): m_strategy(strategy) {}
template <typename Geometry>
result_type operator()(Geometry const& geometry) const
typename default_length_result<Geometry>::type
operator()(Geometry const& geometry) const
{
return perimeter<Geometry>::apply(geometry, m_strategy);
}
@@ -193,7 +193,7 @@ struct perimeter<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
\qbk{[include reference/algorithms/perimeter.qbk]}
*/
template<typename Geometry>
inline typename resolve_variant::perimeter<Geometry>::result_type perimeter(
inline typename default_length_result<Geometry>::type perimeter(
Geometry const& geometry)
{
// detail::throw_on_empty_input(geometry);
@@ -215,7 +215,7 @@ inline typename resolve_variant::perimeter<Geometry>::result_type perimeter(
\qbk{[include reference/algorithms/perimeter.qbk]}
*/
template<typename Geometry, typename Strategy>
inline typename resolve_variant::perimeter<Geometry>::result_type perimeter(
inline typename default_length_result<Geometry>::type perimeter(
Geometry const& geometry, Strategy const& strategy)
{
// detail::throw_on_empty_input(geometry);

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.
@@ -14,14 +19,57 @@
#ifndef BOOST_GEOMETRY_STRATEGIES_DEFAULT_LENGTH_RESULT_HPP
#define BOOST_GEOMETRY_STRATEGIES_DEFAULT_LENGTH_RESULT_HPP
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/util/compress_variant.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
#include <boost/geometry/util/transform_variant.hpp>
namespace boost { namespace geometry
{
namespace resolve_strategy
{
template <typename Geometry>
struct default_length_result
{
typedef typename select_most_precise
<
typename coordinate_type<Geometry>::type,
long double
>::type type;
};
} // namespace resolve_strategy
namespace resolve_variant
{
template <typename Geometry>
struct default_length_result
: resolve_strategy::default_length_result<Geometry>
{};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct default_length_result<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
typedef typename compress_variant<
typename transform_variant<
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
resolve_strategy::default_length_result<boost::mpl::placeholders::_>
>::type
>::type type;
};
} // namespace resolve_variant
/*!
\brief Meta-function defining return type of length function
\ingroup length
@@ -32,15 +80,10 @@ namespace boost { namespace geometry
*/
template <typename Geometry>
struct default_length_result
{
typedef typename select_most_precise
<
typename coordinate_type<Geometry>::type,
long double
>::type type;
};
: resolve_variant::default_length_result<Geometry>
{};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_STRATEGIES_DEFAULT_LENGTH_RESULT_HPP