stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork
This commit is contained in:
+341
@@ -0,0 +1,341 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2014-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2014-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2014-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// This file was modified by Oracle on 2015.
|
||||
// Modifications copyright (c) 2015, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_floating_point.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/tag_cast.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/envelope.hpp>
|
||||
#include <boost/geometry/algorithms/expand.hpp>
|
||||
#include <boost/geometry/algorithms/is_empty.hpp>
|
||||
#include <boost/geometry/algorithms/detail/recalculate.hpp>
|
||||
#include <boost/geometry/algorithms/detail/get_max_size.hpp>
|
||||
#include <boost/geometry/policies/robustness/robust_type.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/point.hpp>
|
||||
#include <boost/geometry/geometries/box.hpp>
|
||||
|
||||
#include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
|
||||
#include <boost/geometry/policies/robustness/rescale_policy.hpp>
|
||||
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace get_rescale_policy
|
||||
{
|
||||
|
||||
template
|
||||
<
|
||||
typename Box,
|
||||
typename Point,
|
||||
typename RobustPoint,
|
||||
typename Factor
|
||||
>
|
||||
inline void scale_box_to_integer_range(Box const& box,
|
||||
Point& min_point,
|
||||
RobustPoint& min_robust_point,
|
||||
Factor& factor)
|
||||
{
|
||||
// Scale box to integer-range
|
||||
typedef typename promote_floating_point
|
||||
<
|
||||
typename geometry::coordinate_type<Point>::type
|
||||
>::type num_type;
|
||||
num_type const diff = boost::numeric_cast<num_type>(detail::get_max_size(box));
|
||||
num_type const range = 10000000.0; // Define a large range to get precise integer coordinates
|
||||
num_type const half = 0.5;
|
||||
if (math::equals(diff, num_type())
|
||||
|| diff >= range
|
||||
|| ! boost::math::isfinite(diff))
|
||||
{
|
||||
factor = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
factor = boost::numeric_cast<num_type>(
|
||||
boost::numeric_cast<boost::long_long_type>(half + range / diff));
|
||||
BOOST_GEOMETRY_ASSERT(factor >= 1);
|
||||
}
|
||||
|
||||
// Assign input/output minimal points
|
||||
detail::assign_point_from_index<0>(box, min_point);
|
||||
num_type const two = 2;
|
||||
boost::long_long_type const min_coordinate
|
||||
= boost::numeric_cast<boost::long_long_type>(-range / two);
|
||||
assign_values(min_robust_point, min_coordinate, min_coordinate);
|
||||
}
|
||||
|
||||
template <typename Point, typename RobustPoint, typename Geometry, typename Factor>
|
||||
static inline void init_rescale_policy(Geometry const& geometry,
|
||||
Point& min_point,
|
||||
RobustPoint& min_robust_point,
|
||||
Factor& factor)
|
||||
{
|
||||
if (geometry::is_empty(geometry))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get bounding boxes
|
||||
model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry);
|
||||
|
||||
scale_box_to_integer_range(env, min_point, min_robust_point, factor);
|
||||
}
|
||||
|
||||
template <typename Point, typename RobustPoint, typename Geometry1, typename Geometry2, typename Factor>
|
||||
static inline void init_rescale_policy(Geometry1 const& geometry1,
|
||||
Geometry2 const& geometry2,
|
||||
Point& min_point,
|
||||
RobustPoint& min_robust_point,
|
||||
Factor& factor)
|
||||
{
|
||||
// Get bounding boxes (when at least one of the geometries is not empty)
|
||||
bool const is_empty1 = geometry::is_empty(geometry1);
|
||||
bool const is_empty2 = geometry::is_empty(geometry2);
|
||||
if (is_empty1 && is_empty2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
model::box<Point> env;
|
||||
if (is_empty1)
|
||||
{
|
||||
geometry::envelope(geometry2, env);
|
||||
}
|
||||
else if (is_empty2)
|
||||
{
|
||||
geometry::envelope(geometry1, env);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The following approach (envelope + expand) may not give the
|
||||
// optimal MBR when then two geometries are in the spherical
|
||||
// equatorial or geographic coordinate systems.
|
||||
// TODO: implement envelope for two (or possibly more geometries)
|
||||
geometry::envelope(geometry1, env);
|
||||
model::box<Point> env2 = geometry::return_envelope
|
||||
<
|
||||
model::box<Point>
|
||||
>(geometry2);
|
||||
geometry::expand(env, env2);
|
||||
}
|
||||
|
||||
scale_box_to_integer_range(env, min_point, min_robust_point, factor);
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
bool IsFloatingPoint
|
||||
>
|
||||
struct rescale_policy_type
|
||||
{
|
||||
typedef no_rescale_policy type;
|
||||
};
|
||||
|
||||
// We rescale only all FP types
|
||||
template
|
||||
<
|
||||
typename Point
|
||||
>
|
||||
struct rescale_policy_type<Point, true>
|
||||
{
|
||||
typedef typename geometry::coordinate_type<Point>::type coordinate_type;
|
||||
typedef model::point
|
||||
<
|
||||
typename detail::robust_type<coordinate_type>::type,
|
||||
geometry::dimension<Point>::value,
|
||||
typename geometry::coordinate_system<Point>::type
|
||||
> robust_point_type;
|
||||
typedef typename promote_floating_point<coordinate_type>::type factor_type;
|
||||
typedef detail::robust_policy<Point, robust_point_type, factor_type> type;
|
||||
};
|
||||
|
||||
template <typename Policy>
|
||||
struct get_rescale_policy
|
||||
{
|
||||
template <typename Geometry>
|
||||
static inline Policy apply(Geometry const& geometry)
|
||||
{
|
||||
typedef typename point_type<Geometry>::type point_type;
|
||||
typedef typename geometry::coordinate_type<Geometry>::type coordinate_type;
|
||||
typedef typename promote_floating_point<coordinate_type>::type factor_type;
|
||||
typedef model::point
|
||||
<
|
||||
typename detail::robust_type<coordinate_type>::type,
|
||||
geometry::dimension<point_type>::value,
|
||||
typename geometry::coordinate_system<point_type>::type
|
||||
> robust_point_type;
|
||||
|
||||
point_type min_point;
|
||||
robust_point_type min_robust_point;
|
||||
factor_type factor;
|
||||
init_rescale_policy(geometry, min_point, min_robust_point, factor);
|
||||
|
||||
return Policy(min_point, min_robust_point, factor);
|
||||
}
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
static inline Policy apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
|
||||
{
|
||||
typedef typename point_type<Geometry1>::type point_type;
|
||||
typedef typename geometry::coordinate_type<Geometry1>::type coordinate_type;
|
||||
typedef typename promote_floating_point<coordinate_type>::type factor_type;
|
||||
typedef model::point
|
||||
<
|
||||
typename detail::robust_type<coordinate_type>::type,
|
||||
geometry::dimension<point_type>::value,
|
||||
typename geometry::coordinate_system<point_type>::type
|
||||
> robust_point_type;
|
||||
|
||||
point_type min_point;
|
||||
robust_point_type min_robust_point;
|
||||
factor_type factor;
|
||||
init_rescale_policy(geometry1, geometry2, min_point, min_robust_point, factor);
|
||||
|
||||
return Policy(min_point, min_robust_point, factor);
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for no-rescaling
|
||||
template <>
|
||||
struct get_rescale_policy<no_rescale_policy>
|
||||
{
|
||||
template <typename Geometry>
|
||||
static inline no_rescale_policy apply(Geometry const& )
|
||||
{
|
||||
return no_rescale_policy();
|
||||
}
|
||||
|
||||
template <typename Geometry1, typename Geometry2>
|
||||
static inline no_rescale_policy apply(Geometry1 const& , Geometry2 const& )
|
||||
{
|
||||
return no_rescale_policy();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace detail::get_rescale_policy
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
template<typename Point>
|
||||
struct rescale_policy_type
|
||||
: public detail::get_rescale_policy::rescale_policy_type
|
||||
<
|
||||
Point,
|
||||
#if defined(BOOST_GEOMETRY_NO_ROBUSTNESS)
|
||||
false
|
||||
#else
|
||||
boost::is_floating_point
|
||||
<
|
||||
typename geometry::coordinate_type<Point>::type
|
||||
>::type::value
|
||||
&&
|
||||
boost::is_same
|
||||
<
|
||||
typename geometry::coordinate_system<Point>::type,
|
||||
geometry::cs::cartesian
|
||||
>::value
|
||||
#endif
|
||||
>
|
||||
{
|
||||
static const bool is_point
|
||||
= boost::is_same
|
||||
<
|
||||
typename geometry::tag<Point>::type,
|
||||
geometry::point_tag
|
||||
>::type::value;
|
||||
|
||||
BOOST_MPL_ASSERT_MSG((is_point),
|
||||
INVALID_INPUT_GEOMETRY,
|
||||
(typename geometry::tag<Point>::type));
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Geometry1,
|
||||
typename Geometry2,
|
||||
typename Tag1 = typename tag_cast
|
||||
<
|
||||
typename tag<Geometry1>::type,
|
||||
box_tag,
|
||||
pointlike_tag,
|
||||
linear_tag,
|
||||
areal_tag
|
||||
>::type,
|
||||
typename Tag2 = typename tag_cast
|
||||
<
|
||||
typename tag<Geometry2>::type,
|
||||
box_tag,
|
||||
pointlike_tag,
|
||||
linear_tag,
|
||||
areal_tag
|
||||
>::type
|
||||
>
|
||||
struct rescale_overlay_policy_type
|
||||
// Default: no rescaling
|
||||
: public detail::get_rescale_policy::rescale_policy_type
|
||||
<
|
||||
typename geometry::point_type<Geometry1>::type,
|
||||
false
|
||||
>
|
||||
{};
|
||||
|
||||
// Areal/areal: get rescale policy based on coordinate type
|
||||
template
|
||||
<
|
||||
typename Geometry1,
|
||||
typename Geometry2
|
||||
>
|
||||
struct rescale_overlay_policy_type<Geometry1, Geometry2, areal_tag, areal_tag>
|
||||
: public rescale_policy_type
|
||||
<
|
||||
typename geometry::point_type<Geometry1>::type
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
template <typename Policy, typename Geometry>
|
||||
inline Policy get_rescale_policy(Geometry const& geometry)
|
||||
{
|
||||
return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry);
|
||||
}
|
||||
|
||||
template <typename Policy, typename Geometry1, typename Geometry2>
|
||||
inline Policy get_rescale_policy(Geometry1 const& geometry1, Geometry2 const& geometry2)
|
||||
{
|
||||
return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry1, geometry2);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_GET_RESCALE_POLICY_HPP
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2013 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2013 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_NO_RESCALE_POLICY_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_NO_RESCALE_POLICY_HPP
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/policies/robustness/robust_point_type.hpp>
|
||||
#include <boost/geometry/policies/robustness/segment_ratio.hpp>
|
||||
#include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Probably this will be moved out of namespace detail
|
||||
struct no_rescale_policy
|
||||
{
|
||||
static bool const enabled = false;
|
||||
|
||||
// We don't rescale but return the reference of the input
|
||||
template <std::size_t Dimension, typename Value>
|
||||
inline Value const& apply(Value const& value) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif
|
||||
|
||||
|
||||
// Implement meta-functions for this policy
|
||||
template <typename Point>
|
||||
struct robust_point_type<Point, detail::no_rescale_policy>
|
||||
{
|
||||
// The point itself
|
||||
typedef Point type;
|
||||
};
|
||||
|
||||
template <typename Point>
|
||||
struct segment_ratio_type<Point, detail::no_rescale_policy>
|
||||
{
|
||||
// Define a segment_ratio defined on coordinate type, e.g.
|
||||
// int/int or float/float
|
||||
typedef typename geometry::coordinate_type<Point>::type coordinate_type;
|
||||
typedef segment_ratio<coordinate_type> type;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_NO_RESCALE_POLICY_HPP
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2014-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2014-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2014-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Copyright (c) 2015, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/geometry/policies/robustness/segment_ratio.hpp>
|
||||
#include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
|
||||
#include <boost/geometry/policies/robustness/robust_point_type.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename FpPoint, typename IntPoint, typename CalculationType>
|
||||
struct robust_policy
|
||||
{
|
||||
static bool const enabled = true;
|
||||
|
||||
typedef typename geometry::coordinate_type<IntPoint>::type output_ct;
|
||||
|
||||
robust_policy(FpPoint const& fp_min, IntPoint const& int_min, CalculationType const& the_factor)
|
||||
: m_fp_min(fp_min)
|
||||
, m_int_min(int_min)
|
||||
, m_multiplier(the_factor)
|
||||
{
|
||||
}
|
||||
|
||||
template <std::size_t Dimension, typename Value>
|
||||
inline output_ct apply(Value const& value) const
|
||||
{
|
||||
// a + (v-b)*f
|
||||
CalculationType const a = static_cast<CalculationType>(get<Dimension>(m_int_min));
|
||||
CalculationType const b = static_cast<CalculationType>(get<Dimension>(m_fp_min));
|
||||
CalculationType const result = a + (value - b) * m_multiplier;
|
||||
|
||||
return geometry::math::rounding_cast<output_ct>(result);
|
||||
}
|
||||
|
||||
FpPoint m_fp_min;
|
||||
IntPoint m_int_min;
|
||||
CalculationType m_multiplier;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif
|
||||
|
||||
|
||||
// Implement meta-functions for this policy
|
||||
|
||||
// Define the IntPoint as a robust-point type
|
||||
template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
|
||||
struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
|
||||
{
|
||||
typedef IntPoint type;
|
||||
};
|
||||
|
||||
// Meta function for rescaling, if rescaling is done segment_ratio is based on long long
|
||||
template <typename Point, typename FpPoint, typename IntPoint, typename CalculationType>
|
||||
struct segment_ratio_type<Point, detail::robust_policy<FpPoint, IntPoint, CalculationType> >
|
||||
{
|
||||
typedef segment_ratio<boost::long_long_type> type;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_HPP
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2013 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2013 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_POINT_TYPE_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_POINT_TYPE_HPP
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
// Meta-function to typedef a robust point type for a policy
|
||||
template <typename Point, typename Policy>
|
||||
struct robust_point_type
|
||||
{
|
||||
// By default, the point itself is the robust type
|
||||
typedef Point type;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_POINT_TYPE_HPP
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2014 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2014 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_TYPE_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_TYPE_HPP
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/type_traits/is_floating_point.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
|
||||
namespace detail_dispatch
|
||||
{
|
||||
|
||||
template <typename CoordinateType, typename IsFloatingPoint>
|
||||
struct robust_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename CoordinateType>
|
||||
struct robust_type<CoordinateType, boost::false_type>
|
||||
{
|
||||
typedef CoordinateType type;
|
||||
};
|
||||
|
||||
template <typename CoordinateType>
|
||||
struct robust_type<CoordinateType, boost::true_type>
|
||||
{
|
||||
typedef boost::long_long_type type;
|
||||
};
|
||||
|
||||
} // namespace detail_dispatch
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename CoordinateType>
|
||||
struct robust_type
|
||||
{
|
||||
typedef typename detail_dispatch::robust_type
|
||||
<
|
||||
CoordinateType,
|
||||
typename boost::is_floating_point<CoordinateType>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_TYPE_HPP
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2016.
|
||||
// Modifications copyright (c) 2016 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/rational.hpp>
|
||||
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace detail { namespace segment_ratio
|
||||
{
|
||||
|
||||
template
|
||||
<
|
||||
typename Type,
|
||||
bool IsIntegral = boost::is_integral<Type>::type::value
|
||||
>
|
||||
struct less {};
|
||||
|
||||
template <typename Type>
|
||||
struct less<Type, true>
|
||||
{
|
||||
template <typename Ratio>
|
||||
static inline bool apply(Ratio const& lhs, Ratio const& rhs)
|
||||
{
|
||||
return boost::rational<Type>(lhs.numerator(), lhs.denominator())
|
||||
< boost::rational<Type>(rhs.numerator(), rhs.denominator());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct less<Type, false>
|
||||
{
|
||||
template <typename Ratio>
|
||||
static inline bool apply(Ratio const& lhs, Ratio const& rhs)
|
||||
{
|
||||
BOOST_GEOMETRY_ASSERT(lhs.denominator() != 0);
|
||||
BOOST_GEOMETRY_ASSERT(rhs.denominator() != 0);
|
||||
return lhs.numerator() * rhs.denominator()
|
||||
< rhs.numerator() * lhs.denominator();
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename Type,
|
||||
bool IsIntegral = boost::is_integral<Type>::type::value
|
||||
>
|
||||
struct equal {};
|
||||
|
||||
template <typename Type>
|
||||
struct equal<Type, true>
|
||||
{
|
||||
template <typename Ratio>
|
||||
static inline bool apply(Ratio const& lhs, Ratio const& rhs)
|
||||
{
|
||||
return boost::rational<Type>(lhs.numerator(), lhs.denominator())
|
||||
== boost::rational<Type>(rhs.numerator(), rhs.denominator());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct equal<Type, false>
|
||||
{
|
||||
template <typename Ratio>
|
||||
static inline bool apply(Ratio const& lhs, Ratio const& rhs)
|
||||
{
|
||||
BOOST_GEOMETRY_ASSERT(lhs.denominator() != 0);
|
||||
BOOST_GEOMETRY_ASSERT(rhs.denominator() != 0);
|
||||
return geometry::math::equals
|
||||
(
|
||||
lhs.numerator() * rhs.denominator(),
|
||||
rhs.numerator() * lhs.denominator()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
//! Small class to keep a ratio (e.g. 1/4)
|
||||
//! Main purpose is intersections and checking on 0, 1, and smaller/larger
|
||||
//! The prototype used Boost.Rational. However, we also want to store FP ratios,
|
||||
//! (so numerator/denominator both in float)
|
||||
//! and Boost.Rational starts with GCD which we prefer to avoid if not necessary
|
||||
//! On a segment means: this ratio is between 0 and 1 (both inclusive)
|
||||
//!
|
||||
template <typename Type>
|
||||
class segment_ratio
|
||||
{
|
||||
public :
|
||||
typedef Type numeric_type;
|
||||
|
||||
// Type-alias for the type itself
|
||||
typedef segment_ratio<Type> thistype;
|
||||
|
||||
inline segment_ratio()
|
||||
: m_numerator(0)
|
||||
, m_denominator(1)
|
||||
, m_approximation(0)
|
||||
{}
|
||||
|
||||
inline segment_ratio(const Type& nominator, const Type& denominator)
|
||||
: m_numerator(nominator)
|
||||
, m_denominator(denominator)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
inline Type const& numerator() const { return m_numerator; }
|
||||
inline Type const& denominator() const { return m_denominator; }
|
||||
|
||||
inline void assign(const Type& nominator, const Type& denominator)
|
||||
{
|
||||
m_numerator = nominator;
|
||||
m_denominator = denominator;
|
||||
initialize();
|
||||
}
|
||||
|
||||
inline void initialize()
|
||||
{
|
||||
// Minimal normalization
|
||||
// 1/-4 => -1/4, -1/-4 => 1/4
|
||||
if (m_denominator < 0)
|
||||
{
|
||||
m_numerator = -m_numerator;
|
||||
m_denominator = -m_denominator;
|
||||
}
|
||||
|
||||
m_approximation =
|
||||
m_denominator == 0 ? 0
|
||||
: (
|
||||
boost::numeric_cast<fp_type>(m_numerator) * scale()
|
||||
/ boost::numeric_cast<fp_type>(m_denominator)
|
||||
);
|
||||
}
|
||||
|
||||
inline bool is_zero() const { return math::equals(m_numerator, 0); }
|
||||
inline bool is_one() const { return math::equals(m_numerator, m_denominator); }
|
||||
inline bool on_segment() const
|
||||
{
|
||||
// e.g. 0/4 or 4/4 or 2/4
|
||||
return m_numerator >= 0 && m_numerator <= m_denominator;
|
||||
}
|
||||
inline bool in_segment() const
|
||||
{
|
||||
// e.g. 1/4
|
||||
return m_numerator > 0 && m_numerator < m_denominator;
|
||||
}
|
||||
inline bool on_end() const
|
||||
{
|
||||
// e.g. 0/4 or 4/4
|
||||
return is_zero() || is_one();
|
||||
}
|
||||
inline bool left() const
|
||||
{
|
||||
// e.g. -1/4
|
||||
return m_numerator < 0;
|
||||
}
|
||||
inline bool right() const
|
||||
{
|
||||
// e.g. 5/4
|
||||
return m_numerator > m_denominator;
|
||||
}
|
||||
|
||||
inline bool near_end() const
|
||||
{
|
||||
if (left() || right())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static fp_type const small_part_of_scale = scale() / 100;
|
||||
return m_approximation < small_part_of_scale
|
||||
|| m_approximation > scale() - small_part_of_scale;
|
||||
}
|
||||
|
||||
inline bool close_to(thistype const& other) const
|
||||
{
|
||||
return geometry::math::abs(m_approximation - other.m_approximation) < 50;
|
||||
}
|
||||
|
||||
inline bool operator< (thistype const& other) const
|
||||
{
|
||||
return close_to(other)
|
||||
? detail::segment_ratio::less<Type>::apply(*this, other)
|
||||
: m_approximation < other.m_approximation;
|
||||
}
|
||||
|
||||
inline bool operator== (thistype const& other) const
|
||||
{
|
||||
return close_to(other)
|
||||
&& detail::segment_ratio::equal<Type>::apply(*this, other);
|
||||
}
|
||||
|
||||
static inline thistype zero()
|
||||
{
|
||||
static thistype result(0, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline thistype one()
|
||||
{
|
||||
static thistype result(1, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(BOOST_GEOMETRY_DEFINE_STREAM_OPERATOR_SEGMENT_RATIO)
|
||||
friend std::ostream& operator<<(std::ostream &os, segment_ratio const& ratio)
|
||||
{
|
||||
os << ratio.m_numerator << "/" << ratio.m_denominator
|
||||
<< " (" << (static_cast<double>(ratio.m_numerator)
|
||||
/ static_cast<double>(ratio.m_denominator))
|
||||
<< ")";
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
private :
|
||||
// NOTE: if this typedef is used then fp_type is non-fundamental type
|
||||
// if Type is non-fundamental type
|
||||
//typedef typename promote_floating_point<Type>::type fp_type;
|
||||
|
||||
typedef typename boost::mpl::if_c
|
||||
<
|
||||
boost::is_float<Type>::value, Type, double
|
||||
>::type fp_type;
|
||||
|
||||
Type m_numerator;
|
||||
Type m_denominator;
|
||||
|
||||
// Contains ratio on scale 0..1000000 (for 0..1)
|
||||
// This is an approximation for fast and rough comparisons
|
||||
// Boost.Rational is used if the approximations are close.
|
||||
// Reason: performance, Boost.Rational does a GCD by default and also the
|
||||
// comparisons contain while-loops.
|
||||
fp_type m_approximation;
|
||||
|
||||
|
||||
static inline fp_type scale()
|
||||
{
|
||||
return 1000000.0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_HPP
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2013 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2013 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2013 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_TYPE_HPP
|
||||
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_TYPE_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/not_implemented.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
// Meta-function to access segment-ratio for a policy
|
||||
template <typename Point, typename Policy>
|
||||
struct segment_ratio_type {}; // : not_implemented<> {};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_TYPE_HPP
|
||||
Reference in New Issue
Block a user