update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -5,10 +5,11 @@
// 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.
// This file was modified by Oracle on 2015-2020.
// Modifications copyright (c) 2015-2020, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// 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
@@ -19,13 +20,11 @@
#include <cstddef>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/type_traits/is_same.hpp>
#include <type_traits>
#include <boost/geometry/core/assert.hpp>
#include <boost/geometry/core/config.hpp>
#include <boost/geometry/core/coordinate_promotion.hpp>
#include <boost/geometry/core/tag_cast.hpp>
#include <boost/geometry/algorithms/envelope.hpp>
@@ -33,15 +32,19 @@
#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/core/static_assert.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/policies/robustness/robust_type.hpp>
#include <boost/geometry/util/type_traits.hpp>
// TEMP
#include <boost/geometry/strategies/envelope/cartesian.hpp>
#include <boost/geometry/strategies/envelope/geographic.hpp>
#include <boost/geometry/strategies/envelope/spherical.hpp>
#include <boost/geometry/util/promote_floating_point.hpp>
namespace boost { namespace geometry
{
@@ -91,29 +94,45 @@ inline void scale_box_to_integer_range(Box const& box,
assign_values(min_robust_point, min_coordinate, min_coordinate);
}
template <typename Point, typename RobustPoint, typename Geometry, typename Factor>
template
<
typename Point, typename RobustPoint, typename Geometry,
typename Factor, typename Strategy
>
static inline void init_rescale_policy(Geometry const& geometry,
Point& min_point,
RobustPoint& min_robust_point,
Factor& factor)
Factor& factor,
Strategy const& strategy)
{
if (geometry::is_empty(geometry))
{
return;
}
// Get bounding boxes
model::box<Point> env = geometry::return_envelope<model::box<Point> >(geometry);
// Get bounding box
model::box<Point> env = geometry::return_envelope
<
model::box<Point>
>(geometry, strategy);
scale_box_to_integer_range(env, min_point, min_robust_point, factor);
}
template <typename Point, typename RobustPoint, typename Geometry1, typename Geometry2, typename Factor>
// NOTE: Actually it should take 2 separate strategies, one for each geometry
// in case one of them was e.g. a Box
template
<
typename Point, typename RobustPoint, typename Geometry1, typename Geometry2,
typename Factor, typename Strategy1, typename Strategy2
>
static inline void init_rescale_policy(Geometry1 const& geometry1,
Geometry2 const& geometry2,
Point& min_point,
RobustPoint& min_robust_point,
Factor& factor)
Factor& factor,
Strategy1 const& strategy1,
Strategy2 const& strategy2)
{
// Get bounding boxes (when at least one of the geometries is not empty)
bool const is_empty1 = geometry::is_empty(geometry1);
@@ -126,11 +145,11 @@ static inline void init_rescale_policy(Geometry1 const& geometry1,
model::box<Point> env;
if (is_empty1)
{
geometry::envelope(geometry2, env);
geometry::envelope(geometry2, env, strategy2);
}
else if (is_empty2)
{
geometry::envelope(geometry1, env);
geometry::envelope(geometry1, env, strategy1);
}
else
{
@@ -138,12 +157,12 @@ static inline void init_rescale_policy(Geometry1 const& geometry1,
// 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);
geometry::envelope(geometry1, env, strategy1);
model::box<Point> env2 = geometry::return_envelope
<
model::box<Point>
>(geometry2);
geometry::expand(env, env2);
>(geometry2, strategy2);
geometry::expand(env, env2, strategy1);
}
scale_box_to_integer_range(env, min_point, min_robust_point, factor);
@@ -181,8 +200,9 @@ struct rescale_policy_type<Point, true>
template <typename Policy>
struct get_rescale_policy
{
template <typename Geometry>
static inline Policy apply(Geometry const& geometry)
template <typename Geometry, typename Strategy>
static inline Policy apply(Geometry const& geometry,
Strategy const& strategy)
{
typedef typename point_type<Geometry>::type point_type;
typedef typename geometry::coordinate_type<Geometry>::type coordinate_type;
@@ -197,13 +217,16 @@ struct get_rescale_policy
point_type min_point;
robust_point_type min_robust_point;
factor_type factor;
init_rescale_policy(geometry, min_point, min_robust_point, factor);
init_rescale_policy(geometry, min_point, min_robust_point,
factor, strategy);
return Policy(min_point, min_robust_point, factor);
}
template <typename Geometry1, typename Geometry2>
static inline Policy apply(Geometry1 const& geometry1, Geometry2 const& geometry2)
template <typename Geometry1, typename Geometry2, typename Strategy1, typename Strategy2>
static inline Policy apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
Strategy1 const& strategy1,
Strategy2 const& strategy2)
{
typedef typename point_type<Geometry1>::type point_type;
typedef typename geometry::coordinate_type<Geometry1>::type coordinate_type;
@@ -218,7 +241,8 @@ struct get_rescale_policy
point_type min_point;
robust_point_type min_robust_point;
factor_type factor;
init_rescale_policy(geometry1, geometry2, min_point, min_robust_point, factor);
init_rescale_policy(geometry1, geometry2, min_point, min_robust_point,
factor, strategy1, strategy2);
return Policy(min_point, min_robust_point, factor);
}
@@ -228,14 +252,15 @@ struct get_rescale_policy
template <>
struct get_rescale_policy<no_rescale_policy>
{
template <typename Geometry>
static inline no_rescale_policy apply(Geometry const& )
template <typename Geometry, typename EnvelopeStrategy>
static inline no_rescale_policy apply(Geometry const& , EnvelopeStrategy const&)
{
return no_rescale_policy();
}
template <typename Geometry1, typename Geometry2>
static inline no_rescale_policy apply(Geometry1 const& , Geometry2 const& )
template <typename Geometry1, typename Geometry2, typename EnvelopeStrategy1, typename EnvelopeStrategy2>
static inline no_rescale_policy apply(Geometry1 const& , Geometry2 const& ,
EnvelopeStrategy1 const& , EnvelopeStrategy2 const& )
{
return no_rescale_policy();
}
@@ -245,37 +270,35 @@ struct get_rescale_policy<no_rescale_policy>
}} // namespace detail::get_rescale_policy
#endif // DOXYGEN_NO_DETAIL
template<typename Point>
template
<
typename Point,
typename CSTag = typename geometry::cs_tag<Point>::type
>
struct rescale_policy_type
: public detail::get_rescale_policy::rescale_policy_type
<
Point,
#if defined(BOOST_GEOMETRY_USE_RESCALING)
boost::is_floating_point
std::is_floating_point
<
typename geometry::coordinate_type<Point>::type
>::type::value
&&
boost::is_same
std::is_same
<
typename geometry::coordinate_system<Point>::type,
geometry::cs::cartesian
CSTag,
geometry::cartesian_tag
>::value
#else
false
#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));
BOOST_GEOMETRY_STATIC_ASSERT(
(util::is_point<Point>::value),
"Point type expected.",
Point);
};
@@ -283,6 +306,7 @@ template
<
typename Geometry1,
typename Geometry2,
typename CSTag = typename geometry::cs_tag<Geometry1>::type,
typename Tag1 = typename tag_cast
<
typename tag<Geometry1>::type,
@@ -313,12 +337,14 @@ struct rescale_overlay_policy_type
template
<
typename Geometry1,
typename Geometry2
typename Geometry2,
typename CSTag
>
struct rescale_overlay_policy_type<Geometry1, Geometry2, areal_tag, areal_tag>
struct rescale_overlay_policy_type<Geometry1, Geometry2, CSTag, areal_tag, areal_tag>
: public rescale_policy_type
<
typename geometry::point_type<Geometry1>::type
typename geometry::point_type<Geometry1>::type,
CSTag
>
{};
@@ -326,13 +352,60 @@ struct rescale_overlay_policy_type<Geometry1, Geometry2, areal_tag, areal_tag>
template <typename Policy, typename Geometry>
inline Policy get_rescale_policy(Geometry const& geometry)
{
return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry);
typename geometry::strategies::envelope::services::default_strategy
<
Geometry,
model::box<typename point_type<Geometry>::type>
>::type strategy;
return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry, strategy);
}
template <typename Policy, typename Geometry1, typename Geometry2>
template
<
typename Policy, typename Geometry, typename Strategy,
std::enable_if_t<std::is_void<typename geometry::tag<Strategy>::type>::value, int> = 0
>
inline Policy get_rescale_policy(Geometry const& geometry, Strategy const& strategy)
{
return detail::get_rescale_policy::get_rescale_policy
<
Policy
>::apply(geometry, strategy);
}
template
<
typename Policy, typename Geometry1, typename Geometry2,
std::enable_if_t<! std::is_void<typename geometry::tag<Geometry2>::type>::value, int> = 0
>
inline Policy get_rescale_policy(Geometry1 const& geometry1, Geometry2 const& geometry2)
{
return detail::get_rescale_policy::get_rescale_policy<Policy>::apply(geometry1, geometry2);
typename geometry::strategies::envelope::services::default_strategy
<
Geometry1,
model::box<typename point_type<Geometry1>::type>
>::type strategy1;
typename geometry::strategies::envelope::services::default_strategy
<
Geometry2,
model::box<typename point_type<Geometry2>::type>
>::type strategy2;
return detail::get_rescale_policy::get_rescale_policy
<
Policy
>::apply(geometry1, geometry2, strategy1, strategy2);
}
template <typename Policy, typename Geometry1, typename Geometry2, typename Strategy>
inline Policy get_rescale_policy(Geometry1 const& geometry1, Geometry2 const& geometry2,
Strategy const& strategy)
{
return detail::get_rescale_policy::get_rescale_policy
<
Policy
>::apply(geometry1, geometry2, strategy, strategy);
}

View File

@@ -17,7 +17,6 @@
#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
{
@@ -26,7 +25,7 @@ namespace boost { namespace geometry
namespace detail
{
// Probably this will be moved out of namespace detail
// Redudant later.
struct no_rescale_policy
{
static bool const enabled = false;
@@ -51,16 +50,6 @@ struct robust_point_type<Point, detail::no_rescale_policy>
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

View File

@@ -22,7 +22,6 @@
#include <boost/geometry/core/coordinate_type.hpp>
#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>
@@ -77,13 +76,6 @@ struct robust_point_type<Point, detail::robust_policy<FpPoint, IntPoint, Calcula
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

View File

@@ -0,0 +1,43 @@
// Boost.Geometry
// Copyright (c) 2019-2019 Barend Gehrels, Amsterdam, the Netherlands.
// 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_TYPE_HPP
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_TYPE_HPP
#include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
struct no_rescale_policy_tag {};
struct rescale_policy_tag {};
template <typename RobustPolicy>
struct rescale_policy_type
{
typedef rescale_policy_tag type;
};
// Specialization
template <>
struct rescale_policy_type<no_rescale_policy>
{
typedef no_rescale_policy_tag type;
};
} // namespace detail
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_RESCALE_POLICY_TYPE_HPP

View File

@@ -5,6 +5,10 @@
// Copyright (c) 2014 Mateusz Loskot, London, UK.
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2020.
// Modifications copyright (c) 2020, 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)
@@ -13,8 +17,9 @@
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_ROBUST_TYPE_HPP
#include <type_traits>
#include <boost/config.hpp>
#include <boost/type_traits/is_floating_point.hpp>
namespace boost { namespace geometry
@@ -31,13 +36,13 @@ struct robust_type
};
template <typename CoordinateType>
struct robust_type<CoordinateType, boost::false_type>
struct robust_type<CoordinateType, std::false_type>
{
typedef CoordinateType type;
};
template <typename CoordinateType>
struct robust_type<CoordinateType, boost::true_type>
struct robust_type<CoordinateType, std::true_type>
{
typedef boost::long_long_type type;
};
@@ -53,7 +58,7 @@ struct robust_type
typedef typename detail_dispatch::robust_type
<
CoordinateType,
typename boost::is_floating_point<CoordinateType>::type
typename std::is_floating_point<CoordinateType>::type
>::type type;
};

View File

@@ -2,8 +2,8 @@
// 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.
// This file was modified by Oracle on 2016-2021.
// Modifications copyright (c) 2016-2021 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,
@@ -13,12 +13,14 @@
#ifndef BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_HPP
#define BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_HPP
#include <type_traits>
#include <boost/config.hpp>
#include <boost/rational.hpp>
#include <boost/geometry/core/assert.hpp>
#include <boost/geometry/core/coordinate_promotion.hpp>
#include <boost/geometry/util/math.hpp>
#include <boost/geometry/util/promote_floating_point.hpp>
namespace boost { namespace geometry
{
@@ -30,7 +32,7 @@ namespace detail { namespace segment_ratio
template
<
typename Type,
bool IsIntegral = boost::is_integral<Type>::type::value
bool IsIntegral = std::is_integral<Type>::type::value
>
struct less {};
@@ -51,17 +53,19 @@ 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();
BOOST_GEOMETRY_ASSERT(lhs.denominator() != Type(0));
BOOST_GEOMETRY_ASSERT(rhs.denominator() != Type(0));
Type const a = lhs.numerator() / lhs.denominator();
Type const b = rhs.numerator() / rhs.denominator();
return ! geometry::math::equals(a, b)
&& a < b;
}
};
template
<
typename Type,
bool IsIntegral = boost::is_integral<Type>::type::value
bool IsIntegral = std::is_integral<Type>::type::value
>
struct equal {};
@@ -82,13 +86,41 @@ 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()
);
BOOST_GEOMETRY_ASSERT(lhs.denominator() != Type(0));
BOOST_GEOMETRY_ASSERT(rhs.denominator() != Type(0));
Type const a = lhs.numerator() / lhs.denominator();
Type const b = rhs.numerator() / rhs.denominator();
return geometry::math::equals(a, b);
}
};
template
<
typename Type,
bool IsFloatingPoint = std::is_floating_point<Type>::type::value
>
struct possibly_collinear {};
template <typename Type>
struct possibly_collinear<Type, true>
{
template <typename Ratio, typename Threshold>
static inline bool apply(Ratio const& ratio, Threshold threshold)
{
return std::abs(ratio.denominator()) < threshold;
}
};
// Any ratio based on non-floating point (or user defined floating point)
// is collinear if the denominator is exactly zero
template <typename Type>
struct possibly_collinear<Type, false>
{
template <typename Ratio, typename Threshold>
static inline bool apply(Ratio const& ratio, Threshold)
{
static Type const zero = 0;
return ratio.denominator() == zero;
}
};
@@ -104,11 +136,16 @@ struct equal<Type, false>
template <typename Type>
class segment_ratio
{
public :
typedef Type numeric_type;
// Type used for the approximation (a helper value)
// and for the edge value (0..1) (a helper function).
using floating_point_type =
typename detail::promoted_to_floating_point<Type>::type;
// Type-alias for the type itself
typedef segment_ratio<Type> thistype;
using thistype = segment_ratio<Type>;
public:
using int_type = Type;
inline segment_ratio()
: m_numerator(0)
@@ -116,19 +153,63 @@ public :
, m_approximation(0)
{}
inline segment_ratio(const Type& nominator, const Type& denominator)
: m_numerator(nominator)
inline segment_ratio(const Type& numerator, const Type& denominator)
: m_numerator(numerator)
, m_denominator(denominator)
{
initialize();
}
segment_ratio(segment_ratio const&) = default;
segment_ratio& operator=(segment_ratio const&) = default;
segment_ratio(segment_ratio&&) = default;
segment_ratio& operator=(segment_ratio&&) = default;
// These are needed because in intersection strategies ratios are assigned
// in fractions and if a user passes CalculationType then ratio Type in
// turns is taken from geometry coordinate_type and the one used in
// a strategy uses Type selected using CalculationType.
// See: detail::overlay::intersection_info_base
// and policies::relate::segments_intersection_points
// in particular segments_collinear() where ratios are assigned.
template<typename T> friend class segment_ratio;
template <typename T>
segment_ratio(segment_ratio<T> const& r)
: m_numerator(r.m_numerator)
, m_denominator(r.m_denominator)
{
initialize();
}
template <typename T>
segment_ratio& operator=(segment_ratio<T> const& r)
{
m_numerator = r.m_numerator;
m_denominator = r.m_denominator;
initialize();
return *this;
}
template <typename T>
segment_ratio(segment_ratio<T> && r)
: m_numerator(std::move(r.m_numerator))
, m_denominator(std::move(r.m_denominator))
{
initialize();
}
template <typename T>
segment_ratio& operator=(segment_ratio<T> && r)
{
m_numerator = std::move(r.m_numerator);
m_denominator = std::move(r.m_denominator);
initialize();
return *this;
}
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)
inline void assign(const Type& numerator, const Type& denominator)
{
m_numerator = nominator;
m_numerator = numerator;
m_denominator = denominator;
initialize();
}
@@ -137,31 +218,31 @@ public :
{
// Minimal normalization
// 1/-4 => -1/4, -1/-4 => 1/4
if (m_denominator < 0)
if (m_denominator < zero_instance())
{
m_numerator = -m_numerator;
m_denominator = -m_denominator;
}
m_approximation =
m_denominator == 0 ? 0
m_denominator == zero_instance() ? floating_point_type{0}
: (
boost::numeric_cast<fp_type>(m_numerator) * scale()
/ boost::numeric_cast<fp_type>(m_denominator)
boost::numeric_cast<floating_point_type>(m_numerator) * scale()
/ boost::numeric_cast<floating_point_type>(m_denominator)
);
}
inline bool is_zero() const { return math::equals(m_numerator, 0); }
inline bool is_zero() const { return math::equals(m_numerator, Type(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;
return m_numerator >= zero_instance() && m_numerator <= m_denominator;
}
inline bool in_segment() const
{
// e.g. 1/4
return m_numerator > 0 && m_numerator < m_denominator;
return m_numerator > zero_instance() && m_numerator < m_denominator;
}
inline bool on_end() const
{
@@ -171,7 +252,7 @@ public :
inline bool left() const
{
// e.g. -1/4
return m_numerator < 0;
return m_numerator < zero_instance();
}
inline bool right() const
{
@@ -179,21 +260,22 @@ public :
return m_numerator > m_denominator;
}
inline bool near_end() const
//! Returns a value between 0.0 and 1.0
//! 0.0 means: exactly in the middle
//! 1.0 means: exactly on one of the edges (or even over it)
inline floating_point_type edge_value() 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;
using fp = floating_point_type;
fp const one{1.0};
floating_point_type const result
= fp(2) * geometry::math::abs(fp(0.5) - m_approximation / scale());
return result > one ? one : result;
}
inline bool close_to(thistype const& other) const
template <typename Threshold>
inline bool possibly_collinear(Threshold threshold) const
{
return geometry::math::abs(m_approximation - other.m_approximation) < 50;
return detail::segment_ratio::possibly_collinear<Type>::apply(*this, threshold);
}
inline bool operator< (thistype const& other) const
@@ -232,17 +314,7 @@ public :
}
#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;
@@ -252,12 +324,24 @@ private :
// 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;
floating_point_type m_approximation;
static inline fp_type scale()
inline bool close_to(thistype const& other) const
{
return 1000000.0;
static floating_point_type const threshold{50.0};
return geometry::math::abs(m_approximation - other.m_approximation)
< threshold;
}
static inline floating_point_type scale()
{
static floating_point_type const fp_scale{1000000.0};
return fp_scale;
}
static inline Type zero_instance()
{
return 0;
}
};

View File

@@ -5,6 +5,10 @@
// Copyright (c) 2013 Mateusz Loskot, London, UK.
// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2020.
// Modifications copyright (c) 2020 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)
@@ -12,17 +16,39 @@
#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>
#include <type_traits>
namespace boost { namespace geometry
#include <boost/config.hpp>
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/policies/robustness/rescale_policy_tags.hpp>
namespace boost { namespace geometry { namespace detail
{
// Meta-function to access segment-ratio for a policy
// Temporary meta-function to access segment-ratio for a policy
template <typename Point, typename Policy>
struct segment_ratio_type {}; // : not_implemented<> {};
struct segment_ratio_type
{
// Type in segment ratio is either the coordinate type, or for
// deprecated robust point types it is a long_long type
typedef std::conditional_t
<
std::is_same
<
typename rescale_policy_type<Policy>::type,
no_rescale_policy_tag
>::value,
typename geometry::coordinate_type<Point>::type,
boost::long_long_type
> coordinate_type;
// Define segment ratio based on the coordinate type
typedef geometry::segment_ratio<coordinate_type> type;
};
}} // namespace boost::geometry
}}} // namespace boost::geometry::deatil
#endif // BOOST_GEOMETRY_POLICIES_ROBUSTNESS_SEGMENT_RATIO_TYPE_HPP