[strategies][distance] add class to convert a distance result from comparable to regular distance result if needed;

add implementation of this for cartesian coordinates (applies sqrt);
This commit is contained in:
Menelaos Karavelas
2014-05-08 14:47:19 +03:00
parent f9825be6bf
commit 17d3f0e78e
2 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_COMPARABLE_TO_REGULAR_HPP
#define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_COMPARABLE_TO_REGULAR_HPP
#include <cmath>
#include <boost/geometry/strategies/distance_comparable_to_regular.hpp>
#include <boost/geometry/core/point_type.hpp>
namespace boost { namespace geometry
{
namespace strategy { namespace distance
{
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
namespace services
{
template
<
typename ComparableStrategy,
typename Strategy,
typename Geometry1,
typename Geometry2
>
struct comparable_to_regular
<
ComparableStrategy, Strategy,
Geometry1, Geometry2,
cartesian_tag, cartesian_tag
>
{
typedef typename return_type
<
Strategy,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type calculation_type;
typedef typename return_type
<
ComparableStrategy,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type comparable_calculation_type;
static inline calculation_type apply(comparable_calculation_type const& cd)
{
return sqrt( boost::numeric_cast<calculation_type>(cd) );
}
};
template <typename ComparableStrategy, typename Geometry1, typename Geometry2>
struct comparable_to_regular
<
ComparableStrategy,
ComparableStrategy,
Geometry1,
Geometry2,
cartesian_tag,
cartesian_tag
>
{
typedef typename return_type
<
ComparableStrategy,
typename point_type<Geometry1>::type,
typename point_type<Geometry2>::type
>::type comparable_calculation_type;
static inline comparable_calculation_type
apply(comparable_calculation_type const& cd)
{
return cd;
}
};
} // namespace services
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
}} // namespace strategy::distance
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_COMPARABLE_TO_REGULAR_HPP

View File

@@ -0,0 +1,53 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP
#define BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>
namespace boost { namespace geometry
{
namespace strategy { namespace distance
{
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
namespace services
{
template
<
typename ComparableStrategy,
typename Strategy,
typename Geometry1,
typename Geometry2,
typename CsTag1 = typename cs_tag<Geometry1>::type,
typename CsTag2 = typename cs_tag<Geometry2>::type
>
struct comparable_to_regular
: geometry::not_implemented<CsTag1, CsTag2>
{};
} // namespace services
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
}} // namespace strategy::distance
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_COMPARABLE_TO_REGULAR_HPP