add boost on mac
This commit is contained in:
195
macx64/include/boost/geometry/strategies/spherical/area.hpp
Normal file
195
macx64/include/boost/geometry/strategies/spherical/area.hpp
Normal file
@@ -0,0 +1,195 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Copyright (c) 2016-2018 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/formulas/area_formulas.hpp>
|
||||
#include <boost/geometry/srs/sphere.hpp>
|
||||
#include <boost/geometry/strategies/area.hpp>
|
||||
#include <boost/geometry/strategies/spherical/get_radius.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace area
|
||||
{
|
||||
|
||||
|
||||
/*!
|
||||
\brief Spherical area calculation
|
||||
\ingroup strategies
|
||||
\details Calculates area on the surface of a sphere using the trapezoidal rule
|
||||
\tparam RadiusTypeOrSphere \tparam_radius_or_sphere
|
||||
\tparam CalculationType \tparam_calculation
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename RadiusTypeOrSphere = double,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical
|
||||
{
|
||||
// Enables special handling of long segments
|
||||
static const bool LongSegment = false;
|
||||
|
||||
public:
|
||||
template <typename Geometry>
|
||||
struct result_type
|
||||
: strategy::area::detail::result_type
|
||||
<
|
||||
Geometry,
|
||||
CalculationType
|
||||
>
|
||||
{};
|
||||
|
||||
template <typename Geometry>
|
||||
class state
|
||||
{
|
||||
friend class spherical;
|
||||
|
||||
typedef typename result_type<Geometry>::type return_type;
|
||||
|
||||
public:
|
||||
inline state()
|
||||
: m_sum(0)
|
||||
, m_crosses_prime_meridian(0)
|
||||
{}
|
||||
|
||||
private:
|
||||
template <typename RadiusType>
|
||||
inline return_type area(RadiusType const& r) const
|
||||
{
|
||||
return_type result;
|
||||
return_type radius = r;
|
||||
|
||||
// Encircles pole
|
||||
if(m_crosses_prime_meridian % 2 == 1)
|
||||
{
|
||||
size_t times_crosses_prime_meridian
|
||||
= 1 + (m_crosses_prime_meridian / 2);
|
||||
|
||||
result = return_type(2)
|
||||
* geometry::math::pi<return_type>()
|
||||
* times_crosses_prime_meridian
|
||||
- geometry::math::abs(m_sum);
|
||||
|
||||
if(geometry::math::sign<return_type>(m_sum) == 1)
|
||||
{
|
||||
result = - result;
|
||||
}
|
||||
|
||||
} else {
|
||||
result = m_sum;
|
||||
}
|
||||
|
||||
result *= radius * radius;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return_type m_sum;
|
||||
|
||||
// Keep track if encircles some pole
|
||||
size_t m_crosses_prime_meridian;
|
||||
};
|
||||
|
||||
public :
|
||||
|
||||
// For backward compatibility reasons the radius is set to 1
|
||||
inline spherical()
|
||||
: m_radius(1.0)
|
||||
{}
|
||||
|
||||
template <typename RadiusOrSphere>
|
||||
explicit inline spherical(RadiusOrSphere const& radius_or_sphere)
|
||||
: m_radius(strategy_detail::get_radius
|
||||
<
|
||||
RadiusOrSphere
|
||||
>::apply(radius_or_sphere))
|
||||
{}
|
||||
|
||||
template <typename PointOfSegment, typename Geometry>
|
||||
inline void apply(PointOfSegment const& p1,
|
||||
PointOfSegment const& p2,
|
||||
state<Geometry>& st) const
|
||||
{
|
||||
if (! geometry::math::equals(get<0>(p1), get<0>(p2)))
|
||||
{
|
||||
typedef geometry::formula::area_formulas
|
||||
<
|
||||
typename result_type<Geometry>::type
|
||||
> area_formulas;
|
||||
|
||||
st.m_sum += area_formulas::template spherical<LongSegment>(p1, p2);
|
||||
|
||||
// Keep track whenever a segment crosses the prime meridian
|
||||
if (area_formulas::crosses_prime_meridian(p1, p2))
|
||||
{
|
||||
st.m_crosses_prime_meridian++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Geometry>
|
||||
inline typename result_type<Geometry>::type
|
||||
result(state<Geometry> const& st) const
|
||||
{
|
||||
return st.area(m_radius);
|
||||
}
|
||||
|
||||
private :
|
||||
typename strategy_detail::get_radius
|
||||
<
|
||||
RadiusTypeOrSphere
|
||||
>::type m_radius;
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
|
||||
template <>
|
||||
struct default_strategy<spherical_equatorial_tag>
|
||||
{
|
||||
typedef strategy::area::spherical<> type;
|
||||
};
|
||||
|
||||
// Note: spherical polar coordinate system requires "get_as_radian_equatorial"
|
||||
template <>
|
||||
struct default_strategy<spherical_polar_tag>
|
||||
{
|
||||
typedef strategy::area::spherical<> type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::area
|
||||
|
||||
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP
|
||||
130
macx64/include/boost/geometry/strategies/spherical/azimuth.hpp
Normal file
130
macx64/include/boost/geometry/strategies/spherical/azimuth.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2016-2017 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AZIMUTH_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AZIMUTH_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/strategies/azimuth.hpp>
|
||||
#include <boost/geometry/formulas/spherical.hpp>
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace azimuth
|
||||
{
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical
|
||||
{
|
||||
public :
|
||||
|
||||
inline spherical()
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
inline void apply(T const& lon1_rad, T const& lat1_rad,
|
||||
T const& lon2_rad, T const& lat2_rad,
|
||||
T& a1, T& a2) const
|
||||
{
|
||||
compute<true, true>(lon1_rad, lat1_rad,
|
||||
lon2_rad, lat2_rad,
|
||||
a1, a2);
|
||||
}
|
||||
template <typename T>
|
||||
inline void apply(T const& lon1_rad, T const& lat1_rad,
|
||||
T const& lon2_rad, T const& lat2_rad,
|
||||
T& a1) const
|
||||
{
|
||||
compute<true, false>(lon1_rad, lat1_rad,
|
||||
lon2_rad, lat2_rad,
|
||||
a1, a1);
|
||||
}
|
||||
template <typename T>
|
||||
inline void apply_reverse(T const& lon1_rad, T const& lat1_rad,
|
||||
T const& lon2_rad, T const& lat2_rad,
|
||||
T& a2) const
|
||||
{
|
||||
compute<false, true>(lon1_rad, lat1_rad,
|
||||
lon2_rad, lat2_rad,
|
||||
a2, a2);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
template
|
||||
<
|
||||
bool EnableAzimuth,
|
||||
bool EnableReverseAzimuth,
|
||||
typename T
|
||||
>
|
||||
inline void compute(T const& lon1_rad, T const& lat1_rad,
|
||||
T const& lon2_rad, T const& lat2_rad,
|
||||
T& a1, T& a2) const
|
||||
{
|
||||
typedef typename boost::mpl::if_
|
||||
<
|
||||
boost::is_void<CalculationType>, T, CalculationType
|
||||
>::type calc_t;
|
||||
|
||||
geometry::formula::result_spherical<calc_t>
|
||||
result = geometry::formula::spherical_azimuth
|
||||
<
|
||||
calc_t,
|
||||
EnableReverseAzimuth
|
||||
>(calc_t(lon1_rad), calc_t(lat1_rad),
|
||||
calc_t(lon2_rad), calc_t(lat2_rad));
|
||||
|
||||
if (EnableAzimuth)
|
||||
{
|
||||
a1 = result.azimuth;
|
||||
}
|
||||
if (EnableReverseAzimuth)
|
||||
{
|
||||
a2 = result.reverse_azimuth;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::azimuth::spherical<CalculationType> type;
|
||||
};
|
||||
|
||||
/*
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::azimuth::spherical<CalculationType> type;
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
}} // namespace strategy::azimuth
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AZIMUTH_HPP
|
||||
322
macx64/include/boost/geometry/strategies/spherical/compare.hpp
Normal file
322
macx64/include/boost/geometry/strategies/spherical/compare.hpp
Normal file
@@ -0,0 +1,322 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2017, 2018.
|
||||
// Modifications copyright (c) 2017-2018, 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_STRATEGIES_SPHERICAL_COMPARE_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_COMPARE_HPP
|
||||
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/min.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/compare.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace strategy { namespace compare
|
||||
{
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <std::size_t I, typename P>
|
||||
static inline typename geometry::coordinate_type<P>::type
|
||||
get(P const& p, boost::true_type /*same units*/)
|
||||
{
|
||||
return geometry::get<I>(p);
|
||||
}
|
||||
|
||||
template <std::size_t I, typename P>
|
||||
static inline typename geometry::coordinate_type<P>::type
|
||||
get(P const& p, boost::false_type /*different units*/)
|
||||
{
|
||||
return geometry::get_as_radian<I>(p);
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename ComparePolicy,
|
||||
typename Point1,
|
||||
typename Point2,
|
||||
std::size_t DimensionCount
|
||||
>
|
||||
struct spherical_latitude
|
||||
{
|
||||
typedef typename geometry::coordinate_type<Point1>::type coordinate1_type;
|
||||
typedef typename geometry::coordinate_system<Point1>::type::units units1_type;
|
||||
typedef typename geometry::coordinate_type<Point2>::type coordinate2_type;
|
||||
typedef typename geometry::coordinate_system<Point2>::type::units units2_type;
|
||||
typedef typename boost::is_same<units1_type, units2_type>::type same_units_type;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
static inline bool apply(Point1 const& left, Point2 const& right,
|
||||
T1 const& l1, T2 const& r1)
|
||||
{
|
||||
// latitudes equal
|
||||
if (math::equals(l1, r1))
|
||||
{
|
||||
return compare::detail::compare_loop
|
||||
<
|
||||
ComparePolicy, 2, DimensionCount
|
||||
>::apply(left, right);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ComparePolicy::apply(l1, r1);
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
coordinate1_type const& l1 = compare::detail::get<1>(left, same_units_type());
|
||||
coordinate2_type const& r1 = compare::detail::get<1>(right, same_units_type());
|
||||
|
||||
return apply(left, right, l1, r1);
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename ComparePolicy,
|
||||
typename Point1,
|
||||
typename Point2
|
||||
>
|
||||
struct spherical_latitude<ComparePolicy, Point1, Point2, 1>
|
||||
{
|
||||
template <typename T1, typename T2>
|
||||
static inline bool apply(Point1 const& left, Point2 const& right,
|
||||
T1 const& , T2 const& )
|
||||
{
|
||||
return apply(left, right);
|
||||
}
|
||||
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
return compare::detail::compare_loop
|
||||
<
|
||||
ComparePolicy, 1, 1
|
||||
>::apply(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename ComparePolicy,
|
||||
typename Point1,
|
||||
typename Point2,
|
||||
std::size_t DimensionCount
|
||||
>
|
||||
struct spherical_longitude
|
||||
{
|
||||
typedef typename geometry::coordinate_type<Point1>::type coordinate1_type;
|
||||
typedef typename geometry::coordinate_system<Point1>::type::units units1_type;
|
||||
typedef typename geometry::coordinate_type<Point2>::type coordinate2_type;
|
||||
typedef typename geometry::coordinate_system<Point2>::type::units units2_type;
|
||||
typedef typename boost::is_same<units1_type, units2_type>::type same_units_type;
|
||||
typedef typename boost::mpl::if_<same_units_type, units1_type, geometry::radian>::type units_type;
|
||||
|
||||
static const bool is_equatorial = ! boost::is_same
|
||||
<
|
||||
typename geometry::cs_tag<Point1>::type,
|
||||
geometry::spherical_polar_tag
|
||||
>::value;
|
||||
|
||||
static inline bool are_both_at_antimeridian(coordinate1_type const& l0,
|
||||
coordinate2_type const& r0,
|
||||
bool & is_left_at,
|
||||
bool & is_right_at)
|
||||
{
|
||||
is_left_at = math::is_longitude_antimeridian<units_type>(l0);
|
||||
is_right_at = math::is_longitude_antimeridian<units_type>(r0);
|
||||
return is_left_at && is_right_at;
|
||||
}
|
||||
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
// if units are different the coordinates are in radians
|
||||
coordinate1_type const& l0 = compare::detail::get<0>(left, same_units_type());
|
||||
coordinate2_type const& r0 = compare::detail::get<0>(right, same_units_type());
|
||||
coordinate1_type const& l1 = compare::detail::get<1>(left, same_units_type());
|
||||
coordinate2_type const& r1 = compare::detail::get<1>(right, same_units_type());
|
||||
|
||||
bool is_left_at_antimeridian = false;
|
||||
bool is_right_at_antimeridian = false;
|
||||
|
||||
// longitudes equal
|
||||
if (math::equals(l0, r0)
|
||||
// both at antimeridian
|
||||
|| are_both_at_antimeridian(l0, r0, is_left_at_antimeridian, is_right_at_antimeridian)
|
||||
// both at pole
|
||||
|| (math::equals(l1, r1)
|
||||
&& math::is_latitude_pole<units_type, is_equatorial>(l1)))
|
||||
{
|
||||
return spherical_latitude
|
||||
<
|
||||
ComparePolicy, Point1, Point2, DimensionCount
|
||||
>::apply(left, right, l1, r1);
|
||||
}
|
||||
// if left is at antimeridian and right is not at antimeridian
|
||||
// then left is greater than right
|
||||
else if (is_left_at_antimeridian)
|
||||
{
|
||||
// less/equal_to -> false, greater -> true
|
||||
return ComparePolicy::apply(1, 0);
|
||||
}
|
||||
// if right is at antimeridian and left is not at antimeridian
|
||||
// then left is lesser than right
|
||||
else if (is_right_at_antimeridian)
|
||||
{
|
||||
// less -> true, equal_to/greater -> false
|
||||
return ComparePolicy::apply(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ComparePolicy::apply(l0, r0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
/*!
|
||||
\brief Compare strategy for spherical coordinates
|
||||
\ingroup strategies
|
||||
\tparam Point point-type
|
||||
\tparam Dimension dimension
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename ComparePolicy,
|
||||
int Dimension = -1
|
||||
>
|
||||
struct spherical
|
||||
: cartesian<ComparePolicy, Dimension>
|
||||
{};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
// all dimensions starting from longitude
|
||||
template <typename ComparePolicy>
|
||||
struct spherical<ComparePolicy, -1>
|
||||
{
|
||||
template <typename Point1, typename Point2>
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
return compare::detail::spherical_longitude
|
||||
<
|
||||
ComparePolicy,
|
||||
Point1,
|
||||
Point2,
|
||||
boost::mpl::min
|
||||
<
|
||||
geometry::dimension<Point1>,
|
||||
geometry::dimension<Point2>
|
||||
>::type::value
|
||||
>::apply(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
// only longitudes (and latitudes to check poles)
|
||||
template <typename ComparePolicy>
|
||||
struct spherical<ComparePolicy, 0>
|
||||
{
|
||||
template <typename Point1, typename Point2>
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
return compare::detail::spherical_longitude
|
||||
<
|
||||
ComparePolicy, Point1, Point2, 1
|
||||
>::apply(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
// only latitudes
|
||||
template <typename ComparePolicy>
|
||||
struct spherical<ComparePolicy, 1>
|
||||
{
|
||||
template <typename Point1, typename Point2>
|
||||
static inline bool apply(Point1 const& left, Point2 const& right)
|
||||
{
|
||||
return compare::detail::spherical_latitude
|
||||
<
|
||||
ComparePolicy, Point1, Point2, 2
|
||||
>::apply(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
|
||||
template <typename ComparePolicy, typename Point1, typename Point2, int Dimension>
|
||||
struct default_strategy
|
||||
<
|
||||
ComparePolicy, Point1, Point2, Dimension,
|
||||
spherical_polar_tag, spherical_polar_tag
|
||||
>
|
||||
{
|
||||
typedef compare::spherical<ComparePolicy, Dimension> type;
|
||||
};
|
||||
|
||||
template <typename ComparePolicy, typename Point1, typename Point2, int Dimension>
|
||||
struct default_strategy
|
||||
<
|
||||
ComparePolicy, Point1, Point2, Dimension,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>
|
||||
{
|
||||
typedef compare::spherical<ComparePolicy, Dimension> type;
|
||||
};
|
||||
|
||||
template <typename ComparePolicy, typename Point1, typename Point2, int Dimension>
|
||||
struct default_strategy
|
||||
<
|
||||
ComparePolicy, Point1, Point2, Dimension,
|
||||
geographic_tag, geographic_tag
|
||||
>
|
||||
{
|
||||
typedef compare::spherical<ComparePolicy, Dimension> type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
|
||||
|
||||
}} // namespace strategy::compare
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_COMPARE_HPP
|
||||
144
macx64/include/boost/geometry/strategies/spherical/densify.hpp
Normal file
144
macx64/include/boost/geometry/strategies/spherical/densify.hpp
Normal file
@@ -0,0 +1,144 @@
|
||||
// Boost.Geometry
|
||||
|
||||
// Copyright (c) 2017-2019, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Licensed under the Boost Software License version 1.0.
|
||||
// http://www.boost.org/users/license.html
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DENSIFY_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DENSIFY_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
|
||||
#include <boost/geometry/algorithms/detail/signed_size_type.hpp>
|
||||
#include <boost/geometry/arithmetic/arithmetic.hpp>
|
||||
#include <boost/geometry/arithmetic/cross_product.hpp>
|
||||
#include <boost/geometry/arithmetic/dot_product.hpp>
|
||||
#include <boost/geometry/arithmetic/normalize.hpp>
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/formulas/spherical.hpp>
|
||||
#include <boost/geometry/formulas/interpolate_point_spherical.hpp>
|
||||
#include <boost/geometry/geometries/point.hpp>
|
||||
#include <boost/geometry/srs/sphere.hpp>
|
||||
#include <boost/geometry/strategies/densify.hpp>
|
||||
#include <boost/geometry/strategies/spherical/get_radius.hpp>
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_most_precise.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace densify
|
||||
{
|
||||
|
||||
|
||||
/*!
|
||||
\brief Densification of spherical segment.
|
||||
\ingroup strategies
|
||||
\tparam RadiusTypeOrSphere \tparam_radius_or_sphere
|
||||
\tparam CalculationType \tparam_calculation
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.densify.densify_4_with_strategy densify (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename RadiusTypeOrSphere = double,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical
|
||||
{
|
||||
public:
|
||||
// For consistency with area strategy the radius is set to 1
|
||||
inline spherical()
|
||||
: m_radius(1.0)
|
||||
{}
|
||||
|
||||
template <typename RadiusOrSphere>
|
||||
explicit inline spherical(RadiusOrSphere const& radius_or_sphere)
|
||||
: m_radius(strategy_detail::get_radius
|
||||
<
|
||||
RadiusOrSphere
|
||||
>::apply(radius_or_sphere))
|
||||
{}
|
||||
|
||||
template <typename Point, typename AssignPolicy, typename T>
|
||||
inline void apply(Point const& p0, Point const& p1, AssignPolicy & policy, T const& length_threshold) const
|
||||
{
|
||||
typedef typename AssignPolicy::point_type out_point_t;
|
||||
typedef typename select_most_precise
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
typename coordinate_type<out_point_t>::type,
|
||||
CalculationType
|
||||
>::type calc_t;
|
||||
|
||||
calc_t angle01;
|
||||
|
||||
formula::interpolate_point_spherical<calc_t> formula;
|
||||
formula.compute_angle(p0, p1, angle01);
|
||||
|
||||
BOOST_GEOMETRY_ASSERT(length_threshold > T(0));
|
||||
|
||||
signed_size_type n = signed_size_type(angle01 * m_radius / length_threshold);
|
||||
if (n <= 0)
|
||||
return;
|
||||
|
||||
formula.compute_axis(p0, angle01);
|
||||
|
||||
calc_t step = angle01 / (n + 1);
|
||||
|
||||
calc_t a = step;
|
||||
for (signed_size_type i = 0 ; i < n ; ++i, a += step)
|
||||
{
|
||||
out_point_t p;
|
||||
formula.compute_point(a, p);
|
||||
|
||||
geometry::detail::conversion::point_to_point
|
||||
<
|
||||
Point, out_point_t,
|
||||
2, dimension<out_point_t>::value
|
||||
>::apply(p0, p);
|
||||
|
||||
policy.apply(p);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typename strategy_detail::get_radius
|
||||
<
|
||||
RadiusTypeOrSphere
|
||||
>::type m_radius;
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <>
|
||||
struct default_strategy<spherical_equatorial_tag>
|
||||
{
|
||||
typedef strategy::densify::spherical<> type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::densify
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_ALGORITHMS_DENSIFY_HPP
|
||||
@@ -0,0 +1,134 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// This file was modified by Oracle on 2013-2018.
|
||||
// Modifications copyright (c) 2013-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
// 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.
|
||||
|
||||
// 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_STRATEGIES_SPHERICAL_DISJOINT_BOX_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISJOINT_BOX_BOX_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/disjoint_box_box.hpp>
|
||||
#include <boost/geometry/strategies/disjoint.hpp>
|
||||
|
||||
#include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
|
||||
#include <boost/geometry/util/select_most_precise.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry { namespace strategy { namespace disjoint
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct box_box_on_spheroid
|
||||
{
|
||||
template <typename Box1, typename Box2>
|
||||
static inline bool apply(Box1 const& box1, Box2 const& box2)
|
||||
{
|
||||
typedef typename geometry::select_most_precise
|
||||
<
|
||||
typename coordinate_type<Box1>::type,
|
||||
typename coordinate_type<Box2>::type
|
||||
>::type calc_t;
|
||||
typedef typename geometry::detail::cs_angular_units<Box1>::type units_t;
|
||||
typedef math::detail::constants_on_spheroid<calc_t, units_t> constants;
|
||||
|
||||
calc_t const b1_min = get<min_corner, 0>(box1);
|
||||
calc_t const b1_max = get<max_corner, 0>(box1);
|
||||
calc_t const b2_min = get<min_corner, 0>(box2);
|
||||
calc_t const b2_max = get<max_corner, 0>(box2);
|
||||
|
||||
// min <= max <=> diff >= 0
|
||||
calc_t const diff1 = b1_max - b1_min;
|
||||
calc_t const diff2 = b2_max - b2_min;
|
||||
|
||||
// check the intersection if neither box cover the whole globe
|
||||
if (diff1 < constants::period() && diff2 < constants::period())
|
||||
{
|
||||
// calculate positive longitude translation with b1_min as origin
|
||||
calc_t const diff_min = math::longitude_distance_unsigned<units_t>(b1_min, b2_min);
|
||||
calc_t const b2_min_transl = b1_min + diff_min; // always right of b1_min
|
||||
calc_t b2_max_transl = b2_min_transl - constants::period() + diff2;
|
||||
|
||||
// if the translation is too close then use the original point
|
||||
// note that math::abs(b2_max_transl - b2_max) takes values very
|
||||
// close to k*2*constants::period() for k=0,1,2,...
|
||||
if (math::abs(b2_max_transl - b2_max) < constants::period() / 2)
|
||||
{
|
||||
b2_max_transl = b2_max;
|
||||
}
|
||||
|
||||
if (b2_min_transl > b1_max // b2_min right of b1_max
|
||||
&& b2_max_transl < b1_min) // b2_max left of b1_min
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return box_box
|
||||
<
|
||||
Box1, Box2, 1
|
||||
>::apply(box1, box2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
struct spherical_box_box
|
||||
{
|
||||
template <typename Box1, typename Box2>
|
||||
static inline bool apply(Box1 const& box1, Box2 const& box2)
|
||||
{
|
||||
return detail::box_box_on_spheroid::apply(box1, box2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename Box1, typename Box2, int TopDim1, int TopDim2>
|
||||
struct default_strategy<Box1, Box2, box_tag, box_tag, TopDim1, TopDim2, spherical_equatorial_tag, spherical_equatorial_tag>
|
||||
{
|
||||
typedef disjoint::spherical_box_box type;
|
||||
};
|
||||
|
||||
template <typename Box1, typename Box2, int TopDim1, int TopDim2>
|
||||
struct default_strategy<Box1, Box2, box_tag, box_tag, TopDim1, TopDim2, spherical_polar_tag, spherical_polar_tag>
|
||||
{
|
||||
typedef disjoint::spherical_box_box type;
|
||||
};
|
||||
|
||||
template <typename Box1, typename Box2, int TopDim1, int TopDim2>
|
||||
struct default_strategy<Box1, Box2, box_tag, box_tag, TopDim1, TopDim2, geographic_tag, geographic_tag>
|
||||
{
|
||||
typedef disjoint::spherical_box_box type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
}}}} // namespace boost::geometry::strategy::disjoint
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISJOINT_BOX_BOX_HPP
|
||||
@@ -0,0 +1,116 @@
|
||||
// Boost.Geometry
|
||||
|
||||
// Copyright (c) 2017-2018 Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISJOINT_SEGMENT_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISJOINT_SEGMENT_BOX_HPP
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/calculation_type.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/point_type.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
|
||||
#include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
|
||||
|
||||
// TODO: spherical_point_box currently defined in the same file as cartesian
|
||||
#include <boost/geometry/strategies/cartesian/point_in_box.hpp>
|
||||
#include <boost/geometry/strategies/disjoint.hpp>
|
||||
#include <boost/geometry/strategies/normalize.hpp>
|
||||
#include <boost/geometry/strategies/spherical/azimuth.hpp>
|
||||
#include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry { namespace strategy { namespace disjoint
|
||||
{
|
||||
|
||||
// NOTE: This may be temporary place for this or corresponding strategy
|
||||
// It seems to be more appropriate to implement the opposite of it
|
||||
// e.g. intersection::segment_box because in disjoint() algorithm
|
||||
// other strategies that are used are intersection and covered_by strategies.
|
||||
struct segment_box_spherical
|
||||
{
|
||||
template <typename Segment, typename Box>
|
||||
struct point_in_geometry_strategy
|
||||
: services::default_strategy
|
||||
<
|
||||
typename point_type<Segment>::type,
|
||||
Box
|
||||
>
|
||||
{};
|
||||
|
||||
template <typename Segment, typename Box>
|
||||
static inline typename point_in_geometry_strategy<Segment, Box>::type
|
||||
get_point_in_geometry_strategy()
|
||||
{
|
||||
typedef typename point_in_geometry_strategy<Segment, Box>::type strategy_type;
|
||||
|
||||
return strategy_type();
|
||||
}
|
||||
|
||||
template <typename Segment, typename Box>
|
||||
static inline bool apply(Segment const& segment, Box const& box)
|
||||
{
|
||||
typedef typename point_type<Segment>::type segment_point_type;
|
||||
typedef typename coordinate_type<segment_point_type>::type CT;
|
||||
geometry::strategy::azimuth::spherical<CT> azimuth_strategy;
|
||||
|
||||
return geometry::detail::disjoint::disjoint_segment_box_sphere_or_spheroid
|
||||
<
|
||||
spherical_equatorial_tag
|
||||
>::apply(segment, box,
|
||||
azimuth_strategy,
|
||||
strategy::normalize::spherical_point(),
|
||||
strategy::covered_by::spherical_point_box(),
|
||||
strategy::disjoint::spherical_box_box());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename Linear, typename Box, typename LinearTag>
|
||||
struct default_strategy<Linear, Box, LinearTag, box_tag, 1, 2,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag>
|
||||
{
|
||||
typedef segment_box_spherical type;
|
||||
};
|
||||
|
||||
template <typename Box, typename Linear, typename LinearTag>
|
||||
struct default_strategy<Box, Linear, box_tag, LinearTag, 2, 1,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag>
|
||||
{
|
||||
typedef segment_box_spherical type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}}}} // namespace boost::geometry::strategy::disjoint
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISJOINT_SEGMENT_BOX_HPP
|
||||
|
||||
@@ -0,0 +1,810 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2014-2018.
|
||||
// Modifications copyright (c) 2014-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/formulas/spherical.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
#include <boost/geometry/strategies/concepts/distance_concept.hpp>
|
||||
#include <boost/geometry/strategies/spherical/distance_haversine.hpp>
|
||||
#include <boost/geometry/strategies/spherical/point_in_point.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK
|
||||
# include <boost/geometry/io/dsv/write.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace distance
|
||||
{
|
||||
|
||||
|
||||
namespace comparable
|
||||
{
|
||||
|
||||
/*
|
||||
Given a spherical segment AB and a point D, we are interested in
|
||||
computing the distance of D from AB. This is usually known as the
|
||||
cross track distance.
|
||||
|
||||
If the projection (along great circles) of the point D lies inside
|
||||
the segment AB, then the distance (cross track error) XTD is given
|
||||
by the formula (see http://williams.best.vwh.net/avform.htm#XTE):
|
||||
|
||||
XTD = asin( sin(dist_AD) * sin(crs_AD-crs_AB) )
|
||||
|
||||
where dist_AD is the great circle distance between the points A and
|
||||
B, and crs_AD, crs_AB is the course (bearing) between the points A,
|
||||
D and A, B, respectively.
|
||||
|
||||
If the point D does not project inside the arc AB, then the distance
|
||||
of D from AB is the minimum of the two distances dist_AD and dist_BD.
|
||||
|
||||
Our reference implementation for this procedure is listed below
|
||||
(this was the old Boost.Geometry implementation of the cross track distance),
|
||||
where:
|
||||
* The member variable m_strategy is the underlying haversine strategy.
|
||||
* p stands for the point D.
|
||||
* sp1 stands for the segment endpoint A.
|
||||
* sp2 stands for the segment endpoint B.
|
||||
|
||||
================= reference implementation -- start =================
|
||||
|
||||
return_type d1 = m_strategy.apply(sp1, p);
|
||||
return_type d3 = m_strategy.apply(sp1, sp2);
|
||||
|
||||
if (geometry::math::equals(d3, 0.0))
|
||||
{
|
||||
// "Degenerate" segment, return either d1 or d2
|
||||
return d1;
|
||||
}
|
||||
|
||||
return_type d2 = m_strategy.apply(sp2, p);
|
||||
|
||||
return_type crs_AD = geometry::detail::course<return_type>(sp1, p);
|
||||
return_type crs_AB = geometry::detail::course<return_type>(sp1, sp2);
|
||||
return_type crs_BA = crs_AB - geometry::math::pi<return_type>();
|
||||
return_type crs_BD = geometry::detail::course<return_type>(sp2, p);
|
||||
return_type d_crs1 = crs_AD - crs_AB;
|
||||
return_type d_crs2 = crs_BD - crs_BA;
|
||||
|
||||
// d1, d2, d3 are in principle not needed, only the sign matters
|
||||
return_type projection1 = cos( d_crs1 ) * d1 / d3;
|
||||
return_type projection2 = cos( d_crs2 ) * d2 / d3;
|
||||
|
||||
if (projection1 > 0.0 && projection2 > 0.0)
|
||||
{
|
||||
return_type XTD
|
||||
= radius() * math::abs( asin( sin( d1 / radius() ) * sin( d_crs1 ) ));
|
||||
|
||||
// Return shortest distance, projected point on segment sp1-sp2
|
||||
return return_type(XTD);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return shortest distance, project either on point sp1 or sp2
|
||||
return return_type( (std::min)( d1 , d2 ) );
|
||||
}
|
||||
|
||||
================= reference implementation -- end =================
|
||||
|
||||
|
||||
Motivation
|
||||
----------
|
||||
In what follows we develop a comparable version of the cross track
|
||||
distance strategy, that meets the following goals:
|
||||
* It is more efficient than the original cross track strategy (less
|
||||
operations and less calls to mathematical functions).
|
||||
* Distances using the comparable cross track strategy can not only
|
||||
be compared with other distances using the same strategy, but also with
|
||||
distances computed with the comparable version of the haversine strategy.
|
||||
* It can serve as the basis for the computation of the cross track distance,
|
||||
as it is more efficient to compute its comparable version and
|
||||
transform that to the actual cross track distance, rather than
|
||||
follow/use the reference implementation listed above.
|
||||
|
||||
Major idea
|
||||
----------
|
||||
The idea here is to use the comparable haversine strategy to compute
|
||||
the distances d1, d2 and d3 in the above listing. Once we have done
|
||||
that we need also to make sure that instead of returning XTD (as
|
||||
computed above) that we return a distance CXTD that is compatible
|
||||
with the comparable haversine distance. To achieve this CXTD must satisfy
|
||||
the relation:
|
||||
XTD = 2 * R * asin( sqrt(XTD) )
|
||||
where R is the sphere's radius.
|
||||
|
||||
Below we perform the mathematical analysis that show how to compute CXTD.
|
||||
|
||||
|
||||
Mathematical analysis
|
||||
---------------------
|
||||
Below we use the following trigonometric identities:
|
||||
sin(2 * x) = 2 * sin(x) * cos(x)
|
||||
cos(asin(x)) = sqrt(1 - x^2)
|
||||
|
||||
Observation:
|
||||
The distance d1 needed when the projection of the point D is within the
|
||||
segment must be the true distance. However, comparable::haversine<>
|
||||
returns a comparable distance instead of the one needed.
|
||||
To remedy this, we implicitly compute what is needed.
|
||||
More precisely, we need to compute sin(true_d1):
|
||||
|
||||
sin(true_d1) = sin(2 * asin(sqrt(d1)))
|
||||
= 2 * sin(asin(sqrt(d1)) * cos(asin(sqrt(d1)))
|
||||
= 2 * sqrt(d1) * sqrt(1-(sqrt(d1))^2)
|
||||
= 2 * sqrt(d1 - d1 * d1)
|
||||
This relation is used below.
|
||||
|
||||
As we mentioned above the goal is to find CXTD (named "a" below for
|
||||
brevity) such that ("b" below stands for "d1", and "c" for "d_crs1"):
|
||||
|
||||
2 * R * asin(sqrt(a)) == R * asin(2 * sqrt(b-b^2) * sin(c))
|
||||
|
||||
Analysis:
|
||||
2 * R * asin(sqrt(a)) == R * asin(2 * sqrt(b-b^2) * sin(c))
|
||||
<=> 2 * asin(sqrt(a)) == asin(sqrt(b-b^2) * sin(c))
|
||||
<=> sin(2 * asin(sqrt(a))) == 2 * sqrt(b-b^2) * sin(c)
|
||||
<=> 2 * sin(asin(sqrt(a))) * cos(asin(sqrt(a))) == 2 * sqrt(b-b^2) * sin(c)
|
||||
<=> 2 * sqrt(a) * sqrt(1-a) == 2 * sqrt(b-b^2) * sin(c)
|
||||
<=> sqrt(a) * sqrt(1-a) == sqrt(b-b^2) * sin(c)
|
||||
<=> sqrt(a-a^2) == sqrt(b-b^2) * sin(c)
|
||||
<=> a-a^2 == (b-b^2) * (sin(c))^2
|
||||
|
||||
Consider the quadratic equation: x^2-x+p^2 == 0,
|
||||
where p = sqrt(b-b^2) * sin(c); its discriminant is:
|
||||
d = 1 - 4 * p^2 = 1 - 4 * (b-b^2) * (sin(c))^2
|
||||
|
||||
The two solutions are:
|
||||
a_1 = (1 - sqrt(d)) / 2
|
||||
a_2 = (1 + sqrt(d)) / 2
|
||||
|
||||
Which one to choose?
|
||||
"a" refers to the distance (on the unit sphere) of D from the
|
||||
supporting great circle Circ(A,B) of the segment AB.
|
||||
The two different values for "a" correspond to the lengths of the two
|
||||
arcs delimited D and the points of intersection of Circ(A,B) and the
|
||||
great circle perperdicular to Circ(A,B) passing through D.
|
||||
Clearly, the value we want is the smallest among these two distances,
|
||||
hence the root we must choose is the smallest root among the two.
|
||||
|
||||
So the answer is:
|
||||
CXTD = ( 1 - sqrt(1 - 4 * (b-b^2) * (sin(c))^2) ) / 2
|
||||
|
||||
Therefore, in order to implement the comparable version of the cross
|
||||
track strategy we need to:
|
||||
(1) Use the comparable version of the haversine strategy instead of
|
||||
the non-comparable one.
|
||||
(2) Instead of return XTD when D projects inside the segment AB, we
|
||||
need to return CXTD, given by the following formula:
|
||||
CXTD = ( 1 - sqrt(1 - 4 * (d1-d1^2) * (sin(d_crs1))^2) ) / 2;
|
||||
|
||||
|
||||
Complexity Analysis
|
||||
-------------------
|
||||
In the analysis that follows we refer to the actual implementation below.
|
||||
In particular, instead of computing CXTD as above, we use the more
|
||||
efficient (operation-wise) computation of CXTD shown here:
|
||||
|
||||
return_type sin_d_crs1 = sin(d_crs1);
|
||||
return_type d1_x_sin = d1 * sin_d_crs1;
|
||||
return_type d = d1_x_sin * (sin_d_crs1 - d1_x_sin);
|
||||
return d / (0.5 + math::sqrt(0.25 - d));
|
||||
|
||||
Notice that instead of computing:
|
||||
0.5 - 0.5 * sqrt(1 - 4 * d) = 0.5 - sqrt(0.25 - d)
|
||||
we use the following formula instead:
|
||||
d / (0.5 + sqrt(0.25 - d)).
|
||||
This is done for numerical robustness. The expression 0.5 - sqrt(0.25 - x)
|
||||
has large numerical errors for values of x close to 0 (if using doubles
|
||||
the error start to become large even when d is as large as 0.001).
|
||||
To remedy that, we re-write 0.5 - sqrt(0.25 - x) as:
|
||||
0.5 - sqrt(0.25 - d)
|
||||
= (0.5 - sqrt(0.25 - d) * (0.5 - sqrt(0.25 - d)) / (0.5 + sqrt(0.25 - d)).
|
||||
The numerator is the difference of two squares:
|
||||
(0.5 - sqrt(0.25 - d) * (0.5 - sqrt(0.25 - d))
|
||||
= 0.5^2 - (sqrt(0.25 - d))^ = 0.25 - (0.25 - d) = d,
|
||||
which gives the expression we use.
|
||||
|
||||
For the complexity analysis, we distinguish between two cases:
|
||||
(A) The distance is realized between the point D and an
|
||||
endpoint of the segment AB
|
||||
|
||||
Gains:
|
||||
Since we are using comparable::haversine<> which is called
|
||||
3 times, we gain:
|
||||
-> 3 calls to sqrt
|
||||
-> 3 calls to asin
|
||||
-> 6 multiplications
|
||||
|
||||
Loses: None
|
||||
|
||||
So the net gain is:
|
||||
-> 6 function calls (sqrt/asin)
|
||||
-> 6 arithmetic operations
|
||||
|
||||
If we use comparable::cross_track<> to compute
|
||||
cross_track<> we need to account for a call to sqrt, a call
|
||||
to asin and 2 multiplications. In this case the net gain is:
|
||||
-> 4 function calls (sqrt/asin)
|
||||
-> 4 arithmetic operations
|
||||
|
||||
|
||||
(B) The distance is realized between the point D and an
|
||||
interior point of the segment AB
|
||||
|
||||
Gains:
|
||||
Since we are using comparable::haversine<> which is called
|
||||
3 times, we gain:
|
||||
-> 3 calls to sqrt
|
||||
-> 3 calls to asin
|
||||
-> 6 multiplications
|
||||
Also we gain the operations used to compute XTD:
|
||||
-> 2 calls to sin
|
||||
-> 1 call to asin
|
||||
-> 1 call to abs
|
||||
-> 2 multiplications
|
||||
-> 1 division
|
||||
So the total gains are:
|
||||
-> 9 calls to sqrt/sin/asin
|
||||
-> 1 call to abs
|
||||
-> 8 multiplications
|
||||
-> 1 division
|
||||
|
||||
Loses:
|
||||
To compute a distance compatible with comparable::haversine<>
|
||||
we need to perform a few more operations, namely:
|
||||
-> 1 call to sin
|
||||
-> 1 call to sqrt
|
||||
-> 2 multiplications
|
||||
-> 1 division
|
||||
-> 1 addition
|
||||
-> 2 subtractions
|
||||
|
||||
So roughly speaking the net gain is:
|
||||
-> 8 fewer function calls and 3 fewer arithmetic operations
|
||||
|
||||
If we were to implement cross_track directly from the
|
||||
comparable version (much like what haversine<> does using
|
||||
comparable::haversine<>) we need additionally
|
||||
-> 2 function calls (asin/sqrt)
|
||||
-> 2 multiplications
|
||||
|
||||
So it pays off to re-implement cross_track<> to use
|
||||
comparable::cross_track<>; in this case the net gain would be:
|
||||
-> 6 function calls
|
||||
-> 1 arithmetic operation
|
||||
|
||||
Summary/Conclusion
|
||||
------------------
|
||||
Following the mathematical and complexity analysis above, the
|
||||
comparable cross track strategy (as implemented below) satisfies
|
||||
all the goal mentioned in the beginning:
|
||||
* It is more efficient than its non-comparable counter-part.
|
||||
* Comparable distances using this new strategy can also be compared
|
||||
with comparable distances computed with the comparable haversine
|
||||
strategy.
|
||||
* It turns out to be more efficient to compute the actual cross
|
||||
track distance XTD by first computing CXTD, and then computing
|
||||
XTD by means of the formula:
|
||||
XTD = 2 * R * asin( sqrt(CXTD) )
|
||||
*/
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename Strategy = comparable::haversine<double, CalculationType>
|
||||
>
|
||||
class cross_track
|
||||
{
|
||||
public :
|
||||
typedef within::spherical_point_point equals_point_point_strategy_type;
|
||||
|
||||
template <typename Point, typename PointOfSegment>
|
||||
struct return_type
|
||||
: promote_floating_point
|
||||
<
|
||||
typename select_calculation_type
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
CalculationType
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
typedef typename Strategy::radius_type radius_type;
|
||||
|
||||
inline cross_track()
|
||||
{}
|
||||
|
||||
explicit inline cross_track(typename Strategy::radius_type const& r)
|
||||
: m_strategy(r)
|
||||
{}
|
||||
|
||||
inline cross_track(Strategy const& s)
|
||||
: m_strategy(s)
|
||||
{}
|
||||
|
||||
// It might be useful in the future
|
||||
// to overload constructor with strategy info.
|
||||
// crosstrack(...) {}
|
||||
|
||||
|
||||
template <typename Point, typename PointOfSegment>
|
||||
inline typename return_type<Point, PointOfSegment>::type
|
||||
apply(Point const& p, PointOfSegment const& sp1, PointOfSegment const& sp2) const
|
||||
{
|
||||
|
||||
#if !defined(BOOST_MSVC)
|
||||
BOOST_CONCEPT_ASSERT
|
||||
(
|
||||
(concepts::PointDistanceStrategy<Strategy, Point, PointOfSegment>)
|
||||
);
|
||||
#endif
|
||||
|
||||
typedef typename return_type<Point, PointOfSegment>::type return_type;
|
||||
|
||||
// http://williams.best.vwh.net/avform.htm#XTE
|
||||
return_type d1 = m_strategy.apply(sp1, p);
|
||||
return_type d3 = m_strategy.apply(sp1, sp2);
|
||||
|
||||
if (geometry::math::equals(d3, 0.0))
|
||||
{
|
||||
// "Degenerate" segment, return either d1 or d2
|
||||
return d1;
|
||||
}
|
||||
|
||||
return_type d2 = m_strategy.apply(sp2, p);
|
||||
|
||||
return_type lon1 = geometry::get_as_radian<0>(sp1);
|
||||
return_type lat1 = geometry::get_as_radian<1>(sp1);
|
||||
return_type lon2 = geometry::get_as_radian<0>(sp2);
|
||||
return_type lat2 = geometry::get_as_radian<1>(sp2);
|
||||
return_type lon = geometry::get_as_radian<0>(p);
|
||||
return_type lat = geometry::get_as_radian<1>(p);
|
||||
|
||||
return_type crs_AD = geometry::formula::spherical_azimuth<return_type, false>
|
||||
(lon1, lat1, lon, lat).azimuth;
|
||||
|
||||
geometry::formula::result_spherical<return_type> result =
|
||||
geometry::formula::spherical_azimuth<return_type, true>
|
||||
(lon1, lat1, lon2, lat2);
|
||||
return_type crs_AB = result.azimuth;
|
||||
return_type crs_BA = result.reverse_azimuth - geometry::math::pi<return_type>();
|
||||
|
||||
return_type crs_BD = geometry::formula::spherical_azimuth<return_type, false>
|
||||
(lon2, lat2, lon, lat).azimuth;
|
||||
|
||||
return_type d_crs1 = crs_AD - crs_AB;
|
||||
return_type d_crs2 = crs_BD - crs_BA;
|
||||
|
||||
// d1, d2, d3 are in principle not needed, only the sign matters
|
||||
return_type projection1 = cos( d_crs1 ) * d1 / d3;
|
||||
return_type projection2 = cos( d_crs2 ) * d2 / d3;
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK
|
||||
std::cout << "Course " << dsv(sp1) << " to " << dsv(p) << " "
|
||||
<< crs_AD * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << "Course " << dsv(sp1) << " to " << dsv(sp2) << " "
|
||||
<< crs_AB * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << "Course " << dsv(sp2) << " to " << dsv(sp1) << " "
|
||||
<< crs_BA * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << "Course " << dsv(sp2) << " to " << dsv(p) << " "
|
||||
<< crs_BD * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << "Projection AD-AB " << projection1 << " : "
|
||||
<< d_crs1 * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << "Projection BD-BA " << projection2 << " : "
|
||||
<< d_crs2 * geometry::math::r2d<return_type>() << std::endl;
|
||||
std::cout << " d1: " << (d1 )
|
||||
<< " d2: " << (d2 )
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
if (projection1 > 0.0 && projection2 > 0.0)
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK
|
||||
return_type XTD = radius() * geometry::math::abs( asin( sin( d1 ) * sin( d_crs1 ) ));
|
||||
|
||||
std::cout << "Projection ON the segment" << std::endl;
|
||||
std::cout << "XTD: " << XTD
|
||||
<< " d1: " << (d1 * radius())
|
||||
<< " d2: " << (d2 * radius())
|
||||
<< std::endl;
|
||||
#endif
|
||||
return_type const half(0.5);
|
||||
return_type const quarter(0.25);
|
||||
|
||||
return_type sin_d_crs1 = sin(d_crs1);
|
||||
/*
|
||||
This is the straightforward obvious way to continue:
|
||||
|
||||
return_type discriminant
|
||||
= 1.0 - 4.0 * (d1 - d1 * d1) * sin_d_crs1 * sin_d_crs1;
|
||||
return 0.5 - 0.5 * math::sqrt(discriminant);
|
||||
|
||||
Below we optimize the number of arithmetic operations
|
||||
and account for numerical robustness:
|
||||
*/
|
||||
return_type d1_x_sin = d1 * sin_d_crs1;
|
||||
return_type d = d1_x_sin * (sin_d_crs1 - d1_x_sin);
|
||||
return d / (half + math::sqrt(quarter - d));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK
|
||||
std::cout << "Projection OUTSIDE the segment" << std::endl;
|
||||
#endif
|
||||
|
||||
// Return shortest distance, project either on point sp1 or sp2
|
||||
return return_type( (std::min)( d1 , d2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline radius_type vertical_or_meridian(T1 lat1, T2 lat2) const
|
||||
{
|
||||
return m_strategy.radius() * (lat1 - lat2);
|
||||
}
|
||||
|
||||
inline typename Strategy::radius_type radius() const
|
||||
{ return m_strategy.radius(); }
|
||||
|
||||
private :
|
||||
Strategy m_strategy;
|
||||
};
|
||||
|
||||
} // namespace comparable
|
||||
|
||||
|
||||
/*!
|
||||
\brief Strategy functor for distance point to segment calculation
|
||||
\ingroup strategies
|
||||
\details Class which calculates the distance of a point to a segment, for points on a sphere or globe
|
||||
\see http://williams.best.vwh.net/avform.htm
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\tparam Strategy underlying point-point distance strategy, defaults to haversine
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)]
|
||||
}
|
||||
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename Strategy = haversine<double, CalculationType>
|
||||
>
|
||||
class cross_track
|
||||
{
|
||||
public :
|
||||
typedef within::spherical_point_point equals_point_point_strategy_type;
|
||||
|
||||
template <typename Point, typename PointOfSegment>
|
||||
struct return_type
|
||||
: promote_floating_point
|
||||
<
|
||||
typename select_calculation_type
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
CalculationType
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
typedef typename Strategy::radius_type radius_type;
|
||||
|
||||
inline cross_track()
|
||||
{}
|
||||
|
||||
explicit inline cross_track(typename Strategy::radius_type const& r)
|
||||
: m_strategy(r)
|
||||
{}
|
||||
|
||||
inline cross_track(Strategy const& s)
|
||||
: m_strategy(s)
|
||||
{}
|
||||
|
||||
// It might be useful in the future
|
||||
// to overload constructor with strategy info.
|
||||
// crosstrack(...) {}
|
||||
|
||||
|
||||
template <typename Point, typename PointOfSegment>
|
||||
inline typename return_type<Point, PointOfSegment>::type
|
||||
apply(Point const& p, PointOfSegment const& sp1, PointOfSegment const& sp2) const
|
||||
{
|
||||
|
||||
#if !defined(BOOST_MSVC)
|
||||
BOOST_CONCEPT_ASSERT
|
||||
(
|
||||
(concepts::PointDistanceStrategy<Strategy, Point, PointOfSegment>)
|
||||
);
|
||||
#endif
|
||||
typedef typename return_type<Point, PointOfSegment>::type return_type;
|
||||
typedef cross_track<CalculationType, Strategy> this_type;
|
||||
|
||||
typedef typename services::comparable_type
|
||||
<
|
||||
this_type
|
||||
>::type comparable_type;
|
||||
|
||||
comparable_type cstrategy
|
||||
= services::get_comparable<this_type>::apply(m_strategy);
|
||||
|
||||
return_type const a = cstrategy.apply(p, sp1, sp2);
|
||||
return_type const c = return_type(2.0) * asin(math::sqrt(a));
|
||||
return c * radius();
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline radius_type vertical_or_meridian(T1 lat1, T2 lat2) const
|
||||
{
|
||||
return m_strategy.radius() * (lat1 - lat2);
|
||||
}
|
||||
|
||||
inline typename Strategy::radius_type radius() const
|
||||
{ return m_strategy.radius(); }
|
||||
|
||||
private :
|
||||
|
||||
Strategy m_strategy;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct tag<cross_track<CalculationType, Strategy> >
|
||||
{
|
||||
typedef strategy_tag_distance_point_segment type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename P, typename PS>
|
||||
struct return_type<cross_track<CalculationType, Strategy>, P, PS>
|
||||
: cross_track<CalculationType, Strategy>::template return_type<P, PS>
|
||||
{};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct comparable_type<cross_track<CalculationType, Strategy> >
|
||||
{
|
||||
typedef comparable::cross_track
|
||||
<
|
||||
CalculationType, typename comparable_type<Strategy>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType,
|
||||
typename Strategy
|
||||
>
|
||||
struct get_comparable<cross_track<CalculationType, Strategy> >
|
||||
{
|
||||
typedef typename comparable_type
|
||||
<
|
||||
cross_track<CalculationType, Strategy>
|
||||
>::type comparable_type;
|
||||
public :
|
||||
static inline comparable_type
|
||||
apply(cross_track<CalculationType, Strategy> const& strategy)
|
||||
{
|
||||
return comparable_type(strategy.radius());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType,
|
||||
typename Strategy,
|
||||
typename P,
|
||||
typename PS
|
||||
>
|
||||
struct result_from_distance<cross_track<CalculationType, Strategy>, P, PS>
|
||||
{
|
||||
private :
|
||||
typedef typename cross_track
|
||||
<
|
||||
CalculationType, Strategy
|
||||
>::template return_type<P, PS>::type return_type;
|
||||
public :
|
||||
template <typename T>
|
||||
static inline return_type
|
||||
apply(cross_track<CalculationType, Strategy> const& , T const& distance)
|
||||
{
|
||||
return distance;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Specializations for comparable::cross_track
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct tag<comparable::cross_track<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef strategy_tag_distance_point_segment type;
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename RadiusType,
|
||||
typename CalculationType,
|
||||
typename P,
|
||||
typename PS
|
||||
>
|
||||
struct return_type<comparable::cross_track<RadiusType, CalculationType>, P, PS>
|
||||
: comparable::cross_track
|
||||
<
|
||||
RadiusType, CalculationType
|
||||
>::template return_type<P, PS>
|
||||
{};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct comparable_type<comparable::cross_track<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef comparable::cross_track<RadiusType, CalculationType> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct get_comparable<comparable::cross_track<RadiusType, CalculationType> >
|
||||
{
|
||||
private :
|
||||
typedef comparable::cross_track<RadiusType, CalculationType> this_type;
|
||||
public :
|
||||
static inline this_type apply(this_type const& input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename RadiusType,
|
||||
typename CalculationType,
|
||||
typename P,
|
||||
typename PS
|
||||
>
|
||||
struct result_from_distance
|
||||
<
|
||||
comparable::cross_track<RadiusType, CalculationType>, P, PS
|
||||
>
|
||||
{
|
||||
private :
|
||||
typedef comparable::cross_track<RadiusType, CalculationType> strategy_type;
|
||||
typedef typename return_type<strategy_type, P, PS>::type return_type;
|
||||
public :
|
||||
template <typename T>
|
||||
static inline return_type apply(strategy_type const& strategy,
|
||||
T const& distance)
|
||||
{
|
||||
return_type const s
|
||||
= sin( (distance / strategy.radius()) / return_type(2.0) );
|
||||
return s * s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
TODO: spherical polar coordinate system requires "get_as_radian_equatorial<>"
|
||||
|
||||
template <typename Point, typename PointOfSegment, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
segment_tag, Point, PointOfSegment,
|
||||
spherical_polar_tag, spherical_polar_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef cross_track
|
||||
<
|
||||
void,
|
||||
typename boost::mpl::if_
|
||||
<
|
||||
boost::is_void<Strategy>,
|
||||
typename default_strategy
|
||||
<
|
||||
point_tag, Point, PointOfSegment,
|
||||
spherical_polar_tag, spherical_polar_tag
|
||||
>::type,
|
||||
Strategy
|
||||
>::type
|
||||
> type;
|
||||
};
|
||||
*/
|
||||
|
||||
template <typename Point, typename PointOfSegment, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
point_tag, segment_tag, Point, PointOfSegment,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef cross_track
|
||||
<
|
||||
void,
|
||||
typename boost::mpl::if_
|
||||
<
|
||||
boost::is_void<Strategy>,
|
||||
typename default_strategy
|
||||
<
|
||||
point_tag, point_tag, Point, PointOfSegment,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>::type,
|
||||
Strategy
|
||||
>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename PointOfSegment, typename Point, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
segment_tag, point_tag, PointOfSegment, Point,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef typename default_strategy
|
||||
<
|
||||
point_tag, segment_tag, Point, PointOfSegment,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>::type type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
}} // namespace strategy::distance
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_HPP
|
||||
@@ -0,0 +1,474 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2016-2018 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_BOX_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_BOX_BOX_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/point_type.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
#include <boost/geometry/strategies/concepts/distance_concept.hpp>
|
||||
#include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace distance
|
||||
{
|
||||
|
||||
namespace details
|
||||
{
|
||||
|
||||
template <typename ReturnType>
|
||||
class cross_track_box_box_generic
|
||||
{
|
||||
public :
|
||||
|
||||
template <typename Point, typename PPStrategy, typename PSStrategy>
|
||||
ReturnType static inline diagonal_case(Point topA,
|
||||
Point topB,
|
||||
Point bottomA,
|
||||
Point bottomB,
|
||||
bool north_shortest,
|
||||
bool non_overlap,
|
||||
PPStrategy pp_strategy,
|
||||
PSStrategy ps_strategy)
|
||||
{
|
||||
if (north_shortest && non_overlap)
|
||||
{
|
||||
return pp_strategy.apply(topA, bottomB);
|
||||
}
|
||||
if (north_shortest && !non_overlap)
|
||||
{
|
||||
return ps_strategy.apply(topA, topB, bottomB);
|
||||
}
|
||||
if (!north_shortest && non_overlap)
|
||||
{
|
||||
return pp_strategy.apply(bottomA, topB);
|
||||
}
|
||||
return ps_strategy.apply(bottomA, topB, bottomB);
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Box1,
|
||||
typename Box2,
|
||||
typename PPStrategy,
|
||||
typename PSStrategy
|
||||
>
|
||||
ReturnType static inline apply (Box1 const& box1,
|
||||
Box2 const& box2,
|
||||
PPStrategy pp_strategy,
|
||||
PSStrategy ps_strategy)
|
||||
{
|
||||
|
||||
// this method assumes that the coordinates of the point and
|
||||
// the box are normalized
|
||||
|
||||
typedef typename point_type<Box1>::type box_point_type1;
|
||||
typedef typename point_type<Box2>::type box_point_type2;
|
||||
|
||||
box_point_type1 bottom_left1, bottom_right1, top_left1, top_right1;
|
||||
geometry::detail::assign_box_corners(box1,
|
||||
bottom_left1, bottom_right1,
|
||||
top_left1, top_right1);
|
||||
|
||||
box_point_type2 bottom_left2, bottom_right2, top_left2, top_right2;
|
||||
geometry::detail::assign_box_corners(box2,
|
||||
bottom_left2, bottom_right2,
|
||||
top_left2, top_right2);
|
||||
|
||||
ReturnType lon_min1 = geometry::get_as_radian<0>(bottom_left1);
|
||||
ReturnType const lat_min1 = geometry::get_as_radian<1>(bottom_left1);
|
||||
ReturnType lon_max1 = geometry::get_as_radian<0>(top_right1);
|
||||
ReturnType const lat_max1 = geometry::get_as_radian<1>(top_right1);
|
||||
|
||||
ReturnType lon_min2 = geometry::get_as_radian<0>(bottom_left2);
|
||||
ReturnType const lat_min2 = geometry::get_as_radian<1>(bottom_left2);
|
||||
ReturnType lon_max2 = geometry::get_as_radian<0>(top_right2);
|
||||
ReturnType const lat_max2 = geometry::get_as_radian<1>(top_right2);
|
||||
|
||||
ReturnType const two_pi = math::two_pi<ReturnType>();
|
||||
|
||||
// Test which sides of the boxes are closer and if boxes cross
|
||||
// antimeridian
|
||||
bool right_wrap;
|
||||
|
||||
if (lon_min2 > 0 && lon_max2 < 0) // box2 crosses antimeridian
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(box2 crosses antimeridian)";
|
||||
#endif
|
||||
right_wrap = lon_min2 - lon_max1 < lon_min1 - lon_max2;
|
||||
lon_max2 += two_pi;
|
||||
if (lon_min1 > 0 && lon_max1 < 0) // both boxes crosses antimeridian
|
||||
{
|
||||
lon_max1 += two_pi;
|
||||
}
|
||||
}
|
||||
else if (lon_min1 > 0 && lon_max1 < 0) // only box1 crosses antimeridian
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(box1 crosses antimeridian)";
|
||||
#endif
|
||||
return apply(box2, box1, pp_strategy, ps_strategy);
|
||||
}
|
||||
else
|
||||
{
|
||||
right_wrap = lon_max1 <= lon_min2
|
||||
? lon_min2 - lon_max1 < two_pi - (lon_max2 - lon_min1)
|
||||
: lon_min1 - lon_max2 > two_pi - (lon_max1 - lon_min2);
|
||||
|
||||
}
|
||||
|
||||
// Check1: if box2 crosses the band defined by the
|
||||
// minimum and maximum longitude of box1; if yes, determine
|
||||
// if the box2 is above, below or intersects/is inside box1 and compute
|
||||
// the distance (easy in this case)
|
||||
|
||||
bool lon_min12 = lon_min1 <= lon_min2;
|
||||
bool right = lon_max1 <= lon_min2;
|
||||
bool left = lon_min1 >= lon_max2;
|
||||
bool lon_max12 = lon_max1 <= lon_max2;
|
||||
|
||||
if ((lon_min12 && !right)
|
||||
|| (!left && !lon_max12)
|
||||
|| (!lon_min12 && lon_max12))
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(up-down)\n";
|
||||
#endif
|
||||
if (lat_min1 > lat_max2)
|
||||
{
|
||||
return geometry::strategy::distance::services::result_from_distance
|
||||
<
|
||||
PSStrategy, box_point_type1, box_point_type2
|
||||
>::apply(ps_strategy, ps_strategy
|
||||
.vertical_or_meridian(lat_min1, lat_max2));
|
||||
}
|
||||
else if (lat_max1 < lat_min2)
|
||||
{
|
||||
return geometry::strategy::distance::services::result_from_distance
|
||||
<
|
||||
PSStrategy, box_point_type1, box_point_type2
|
||||
>::apply(ps_strategy, ps_strategy
|
||||
.vertical_or_meridian(lat_min2, lat_max1));
|
||||
}
|
||||
else
|
||||
{
|
||||
//BOOST_GEOMETRY_ASSERT(plat >= lat_min && plat <= lat_max);
|
||||
return ReturnType(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Check2: if box2 is right/left of box1
|
||||
// the max lat of box2 should be less than the max lat of box1
|
||||
bool bottom_max;
|
||||
|
||||
ReturnType top_common = (std::min)(lat_max1, lat_max2);
|
||||
ReturnType bottom_common = (std::max)(lat_min1, lat_min2);
|
||||
|
||||
// true if the closest points are on northern hemisphere
|
||||
bool north_shortest = top_common + bottom_common > 0;
|
||||
// true if box bands do not overlap
|
||||
bool non_overlap = top_common < bottom_common;
|
||||
|
||||
if (north_shortest)
|
||||
{
|
||||
bottom_max = lat_max1 >= lat_max2;
|
||||
}
|
||||
else
|
||||
{
|
||||
bottom_max = lat_min1 <= lat_min2;
|
||||
}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(diagonal)";
|
||||
#endif
|
||||
if (bottom_max && !right_wrap)
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(bottom left)";
|
||||
#endif
|
||||
return diagonal_case(top_right2, top_left1,
|
||||
bottom_right2, bottom_left1,
|
||||
north_shortest, non_overlap,
|
||||
pp_strategy, ps_strategy);
|
||||
}
|
||||
if (bottom_max && right_wrap)
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(bottom right)";
|
||||
#endif
|
||||
return diagonal_case(top_left2, top_right1,
|
||||
bottom_left2, bottom_right1,
|
||||
north_shortest, non_overlap,
|
||||
pp_strategy, ps_strategy);
|
||||
}
|
||||
if (!bottom_max && !right_wrap)
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(top left)";
|
||||
#endif
|
||||
return diagonal_case(top_left1, top_right2,
|
||||
bottom_left1, bottom_right2,
|
||||
north_shortest, non_overlap,
|
||||
pp_strategy, ps_strategy);
|
||||
}
|
||||
if (!bottom_max && right_wrap)
|
||||
{
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_CROSS_TRACK_BOX_BOX
|
||||
std::cout << "(top right)";
|
||||
#endif
|
||||
return diagonal_case(top_right1, top_left2,
|
||||
bottom_right1, bottom_left2,
|
||||
north_shortest, non_overlap,
|
||||
pp_strategy, ps_strategy);
|
||||
}
|
||||
return ReturnType(0);
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace details
|
||||
|
||||
/*!
|
||||
\brief Strategy functor for distance box to box calculation
|
||||
\ingroup strategies
|
||||
\details Class which calculates the distance of a box to a box, for
|
||||
boxes on a sphere or globe
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\tparam Strategy underlying point-segment distance strategy, defaults
|
||||
to cross track
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename Strategy = haversine<double, CalculationType>
|
||||
>
|
||||
class cross_track_box_box
|
||||
{
|
||||
public:
|
||||
template <typename Box1, typename Box2>
|
||||
struct return_type
|
||||
: services::return_type<Strategy,
|
||||
typename point_type<Box1>::type,
|
||||
typename point_type<Box2>::type>
|
||||
{};
|
||||
|
||||
typedef typename Strategy::radius_type radius_type;
|
||||
|
||||
// strategy getters
|
||||
|
||||
// point-segment strategy getters
|
||||
struct distance_ps_strategy
|
||||
{
|
||||
typedef cross_track<CalculationType, Strategy> type;
|
||||
};
|
||||
|
||||
typedef typename strategy::distance::services::comparable_type
|
||||
<
|
||||
Strategy
|
||||
>::type pp_comparable_strategy;
|
||||
|
||||
typedef typename boost::mpl::if_
|
||||
<
|
||||
boost::is_same
|
||||
<
|
||||
pp_comparable_strategy,
|
||||
Strategy
|
||||
>,
|
||||
typename strategy::distance::services::comparable_type
|
||||
<
|
||||
typename distance_ps_strategy::type
|
||||
>::type,
|
||||
typename distance_ps_strategy::type
|
||||
>::type ps_strategy_type;
|
||||
|
||||
// constructors
|
||||
|
||||
inline cross_track_box_box()
|
||||
{}
|
||||
|
||||
explicit inline cross_track_box_box(typename Strategy::radius_type const& r)
|
||||
: m_strategy(r)
|
||||
{}
|
||||
|
||||
inline cross_track_box_box(Strategy const& s)
|
||||
: m_strategy(s)
|
||||
{}
|
||||
|
||||
|
||||
// It might be useful in the future
|
||||
// to overload constructor with strategy info.
|
||||
// crosstrack(...) {}
|
||||
|
||||
template <typename Box1, typename Box2>
|
||||
inline typename return_type<Box1, Box2>::type
|
||||
apply(Box1 const& box1, Box2 const& box2) const
|
||||
{
|
||||
#if !defined(BOOST_MSVC)
|
||||
BOOST_CONCEPT_ASSERT
|
||||
(
|
||||
(concepts::PointDistanceStrategy
|
||||
<
|
||||
Strategy,
|
||||
typename point_type<Box1>::type,
|
||||
typename point_type<Box2>::type
|
||||
>)
|
||||
);
|
||||
#endif
|
||||
typedef typename return_type<Box1, Box2>::type return_type;
|
||||
return details::cross_track_box_box_generic
|
||||
<return_type>::apply(box1, box2,
|
||||
m_strategy,
|
||||
ps_strategy_type(m_strategy));
|
||||
}
|
||||
|
||||
inline typename Strategy::radius_type radius() const
|
||||
{
|
||||
return m_strategy.radius();
|
||||
}
|
||||
|
||||
private:
|
||||
Strategy m_strategy;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct tag<cross_track_box_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef strategy_tag_distance_box_box type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename Box1, typename Box2>
|
||||
struct return_type<cross_track_box_box<CalculationType, Strategy>, Box1, Box2>
|
||||
: cross_track_box_box
|
||||
<
|
||||
CalculationType, Strategy
|
||||
>::template return_type<Box1, Box2>
|
||||
{};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct comparable_type<cross_track_box_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef cross_track_box_box
|
||||
<
|
||||
CalculationType, typename comparable_type<Strategy>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct get_comparable<cross_track_box_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef cross_track_box_box<CalculationType, Strategy> this_strategy;
|
||||
typedef typename comparable_type<this_strategy>::type comparable_type;
|
||||
|
||||
public:
|
||||
static inline comparable_type apply(this_strategy const& strategy)
|
||||
{
|
||||
return comparable_type(strategy.radius());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename Box1, typename Box2>
|
||||
struct result_from_distance
|
||||
<
|
||||
cross_track_box_box<CalculationType, Strategy>, Box1, Box2
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef cross_track_box_box<CalculationType, Strategy> this_strategy;
|
||||
|
||||
typedef typename this_strategy::template return_type
|
||||
<
|
||||
Box1, Box2
|
||||
>::type return_type;
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
static inline return_type apply(this_strategy const& strategy,
|
||||
T const& distance)
|
||||
{
|
||||
Strategy s(strategy.radius());
|
||||
|
||||
return result_from_distance
|
||||
<
|
||||
Strategy,
|
||||
typename point_type<Box1>::type,
|
||||
typename point_type<Box2>::type
|
||||
>::apply(s, distance);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// define cross_track_box_box<default_point_segment_strategy> as
|
||||
// default box-box strategy for the spherical equatorial coordinate system
|
||||
template <typename Box1, typename Box2, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
box_tag, box_tag, Box1, Box2,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef cross_track_box_box
|
||||
<
|
||||
void,
|
||||
typename boost::mpl::if_
|
||||
<
|
||||
boost::is_void<Strategy>,
|
||||
typename default_strategy
|
||||
<
|
||||
point_tag, point_tag,
|
||||
typename point_type<Box1>::type, typename point_type<Box2>::type,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>::type,
|
||||
Strategy
|
||||
>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::distance
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_BOX_BOX_HPP
|
||||
@@ -0,0 +1,417 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2014-2017.
|
||||
// Modifications copyright (c) 2014-2017, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_POINT_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_POINT_BOX_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/point_type.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
#include <boost/geometry/strategies/concepts/distance_concept.hpp>
|
||||
#include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace distance
|
||||
{
|
||||
|
||||
namespace details
|
||||
{
|
||||
|
||||
template <typename ReturnType>
|
||||
class cross_track_point_box_generic
|
||||
{
|
||||
public :
|
||||
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename Box,
|
||||
typename Strategy
|
||||
>
|
||||
ReturnType static inline apply (Point const& point,
|
||||
Box const& box,
|
||||
Strategy ps_strategy)
|
||||
{
|
||||
// this method assumes that the coordinates of the point and
|
||||
// the box are normalized
|
||||
|
||||
typedef typename point_type<Box>::type box_point_type;
|
||||
|
||||
box_point_type bottom_left, bottom_right, top_left, top_right;
|
||||
geometry::detail::assign_box_corners(box,
|
||||
bottom_left, bottom_right,
|
||||
top_left, top_right);
|
||||
|
||||
ReturnType const plon = geometry::get_as_radian<0>(point);
|
||||
ReturnType const plat = geometry::get_as_radian<1>(point);
|
||||
|
||||
ReturnType const lon_min = geometry::get_as_radian<0>(bottom_left);
|
||||
ReturnType const lat_min = geometry::get_as_radian<1>(bottom_left);
|
||||
ReturnType const lon_max = geometry::get_as_radian<0>(top_right);
|
||||
ReturnType const lat_max = geometry::get_as_radian<1>(top_right);
|
||||
|
||||
ReturnType const pi = math::pi<ReturnType>();
|
||||
ReturnType const two_pi = math::two_pi<ReturnType>();
|
||||
|
||||
typedef typename point_type<Box>::type box_point_type;
|
||||
|
||||
// First check if the point is within the band defined by the
|
||||
// minimum and maximum longitude of the box; if yes, determine
|
||||
// if the point is above, below or inside the box and compute
|
||||
// the distance (easy in this case)
|
||||
//
|
||||
// Notice that the point may not be inside the longitude range
|
||||
// of the box, but the shifted point may be inside the
|
||||
// longitude range of the box; in this case the point is still
|
||||
// considered as inside the longitude range band of the box
|
||||
if ((plon >= lon_min && plon <= lon_max) || plon + two_pi <= lon_max)
|
||||
{
|
||||
if (plat > lat_max)
|
||||
{
|
||||
return geometry::strategy::distance::services::result_from_distance
|
||||
<
|
||||
Strategy, Point, box_point_type
|
||||
>::apply(ps_strategy, ps_strategy
|
||||
.vertical_or_meridian(plat, lat_max));
|
||||
}
|
||||
else if (plat < lat_min)
|
||||
{
|
||||
return geometry::strategy::distance::services::result_from_distance
|
||||
<
|
||||
Strategy, Point, box_point_type
|
||||
>::apply(ps_strategy, ps_strategy
|
||||
.vertical_or_meridian(lat_min, plat));
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_GEOMETRY_ASSERT(plat >= lat_min && plat <= lat_max);
|
||||
return ReturnType(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise determine which among the two medirian segments of the
|
||||
// box the point is closest to, and compute the distance of
|
||||
// the point to this closest segment
|
||||
|
||||
// Below lon_midway is the longitude of the meridian that:
|
||||
// (1) is midway between the meridians of the left and right
|
||||
// meridians of the box, and
|
||||
// (2) does not intersect the box
|
||||
ReturnType const two = 2.0;
|
||||
bool use_left_segment;
|
||||
if (lon_max > pi)
|
||||
{
|
||||
// the box crosses the antimeridian
|
||||
|
||||
// midway longitude = lon_min - (lon_min + (lon_max - 2 * pi)) / 2;
|
||||
ReturnType const lon_midway = (lon_min - lon_max) / two + pi;
|
||||
BOOST_GEOMETRY_ASSERT(lon_midway >= -pi && lon_midway <= pi);
|
||||
|
||||
use_left_segment = plon > lon_midway;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the box does not cross the antimeridian
|
||||
|
||||
ReturnType const lon_sum = lon_min + lon_max;
|
||||
if (math::equals(lon_sum, ReturnType(0)))
|
||||
{
|
||||
// special case: the box is symmetric with respect to
|
||||
// the prime meridian; the midway meridian is the antimeridian
|
||||
|
||||
use_left_segment = plon < lon_min;
|
||||
}
|
||||
else
|
||||
{
|
||||
// midway long. = lon_min - (2 * pi - (lon_max - lon_min)) / 2;
|
||||
ReturnType lon_midway = (lon_min + lon_max) / two - pi;
|
||||
|
||||
// normalize the midway longitude
|
||||
if (lon_midway > pi)
|
||||
{
|
||||
lon_midway -= two_pi;
|
||||
}
|
||||
else if (lon_midway < -pi)
|
||||
{
|
||||
lon_midway += two_pi;
|
||||
}
|
||||
BOOST_GEOMETRY_ASSERT(lon_midway >= -pi && lon_midway <= pi);
|
||||
|
||||
// if lon_sum is positive the midway meridian is left
|
||||
// of the box, or right of the box otherwise
|
||||
use_left_segment = lon_sum > 0
|
||||
? (plon < lon_min && plon >= lon_midway)
|
||||
: (plon <= lon_max || plon > lon_midway);
|
||||
}
|
||||
}
|
||||
|
||||
return use_left_segment
|
||||
? ps_strategy.apply(point, bottom_left, top_left)
|
||||
: ps_strategy.apply(point, bottom_right, top_right);
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace details
|
||||
|
||||
/*!
|
||||
\brief Strategy functor for distance point to box calculation
|
||||
\ingroup strategies
|
||||
\details Class which calculates the distance of a point to a box, for
|
||||
points and boxes on a sphere or globe
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\tparam Strategy underlying point-point distance strategy
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename Strategy = haversine<double, CalculationType>
|
||||
>
|
||||
class cross_track_point_box
|
||||
{
|
||||
public:
|
||||
template <typename Point, typename Box>
|
||||
struct return_type
|
||||
: services::return_type<Strategy, Point, typename point_type<Box>::type>
|
||||
{};
|
||||
|
||||
typedef typename Strategy::radius_type radius_type;
|
||||
|
||||
// strategy getters
|
||||
|
||||
// point-segment strategy getters
|
||||
struct distance_ps_strategy
|
||||
{
|
||||
typedef cross_track<CalculationType, Strategy> type;
|
||||
};
|
||||
|
||||
typedef typename strategy::distance::services::comparable_type
|
||||
<
|
||||
Strategy
|
||||
>::type pp_comparable_strategy;
|
||||
|
||||
typedef typename boost::mpl::if_
|
||||
<
|
||||
boost::is_same
|
||||
<
|
||||
pp_comparable_strategy,
|
||||
Strategy
|
||||
>,
|
||||
typename strategy::distance::services::comparable_type
|
||||
<
|
||||
typename distance_ps_strategy::type
|
||||
>::type,
|
||||
typename distance_ps_strategy::type
|
||||
>::type ps_strategy_type;
|
||||
|
||||
// constructors
|
||||
|
||||
inline cross_track_point_box()
|
||||
{}
|
||||
|
||||
explicit inline cross_track_point_box(typename Strategy::radius_type const& r)
|
||||
: m_strategy(r)
|
||||
{}
|
||||
|
||||
inline cross_track_point_box(Strategy const& s)
|
||||
: m_strategy(s)
|
||||
{}
|
||||
|
||||
|
||||
// methods
|
||||
|
||||
// It might be useful in the future
|
||||
// to overload constructor with strategy info.
|
||||
// crosstrack(...) {}
|
||||
|
||||
template <typename Point, typename Box>
|
||||
inline typename return_type<Point, Box>::type
|
||||
apply(Point const& point, Box const& box) const
|
||||
{
|
||||
#if !defined(BOOST_MSVC)
|
||||
BOOST_CONCEPT_ASSERT
|
||||
(
|
||||
(concepts::PointDistanceStrategy
|
||||
<
|
||||
Strategy, Point, typename point_type<Box>::type
|
||||
>)
|
||||
);
|
||||
#endif
|
||||
typedef typename return_type<Point, Box>::type return_type;
|
||||
return details::cross_track_point_box_generic
|
||||
<return_type>::apply(point, box,
|
||||
ps_strategy_type(m_strategy));
|
||||
}
|
||||
|
||||
inline typename Strategy::radius_type radius() const
|
||||
{
|
||||
return m_strategy.radius();
|
||||
}
|
||||
|
||||
private:
|
||||
Strategy m_strategy;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct tag<cross_track_point_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef strategy_tag_distance_point_box type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename P, typename Box>
|
||||
struct return_type<cross_track_point_box<CalculationType, Strategy>, P, Box>
|
||||
: cross_track_point_box
|
||||
<
|
||||
CalculationType, Strategy
|
||||
>::template return_type<P, Box>
|
||||
{};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct comparable_type<cross_track_point_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef cross_track_point_box
|
||||
<
|
||||
CalculationType, typename comparable_type<Strategy>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct get_comparable<cross_track_point_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef cross_track_point_box<CalculationType, Strategy> this_strategy;
|
||||
typedef typename comparable_type<this_strategy>::type comparable_type;
|
||||
|
||||
public:
|
||||
static inline comparable_type apply(this_strategy const& strategy)
|
||||
{
|
||||
return comparable_type(strategy.radius());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename P, typename Box>
|
||||
struct result_from_distance
|
||||
<
|
||||
cross_track_point_box<CalculationType, Strategy>, P, Box
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef cross_track_point_box<CalculationType, Strategy> this_strategy;
|
||||
|
||||
typedef typename this_strategy::template return_type
|
||||
<
|
||||
P, Box
|
||||
>::type return_type;
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
static inline return_type apply(this_strategy const& strategy,
|
||||
T const& distance)
|
||||
{
|
||||
Strategy s(strategy.radius());
|
||||
|
||||
return result_from_distance
|
||||
<
|
||||
Strategy, P, typename point_type<Box>::type
|
||||
>::apply(s, distance);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// define cross_track_point_box<default_point_segment_strategy> as
|
||||
// default point-box strategy for the spherical equatorial coordinate system
|
||||
template <typename Point, typename Box, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
point_tag, box_tag, Point, Box,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef cross_track_point_box
|
||||
<
|
||||
void,
|
||||
typename boost::mpl::if_
|
||||
<
|
||||
boost::is_void<Strategy>,
|
||||
typename default_strategy
|
||||
<
|
||||
point_tag, point_tag,
|
||||
Point, typename point_type<Box>::type,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>::type,
|
||||
Strategy
|
||||
>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename Box, typename Point, typename Strategy>
|
||||
struct default_strategy
|
||||
<
|
||||
box_tag, point_tag, Box, Point,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>
|
||||
{
|
||||
typedef typename default_strategy
|
||||
<
|
||||
point_tag, box_tag, Point, Box,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag,
|
||||
Strategy
|
||||
>::type type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::distance
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_CROSS_TRACK_POINT_BOX_HPP
|
||||
@@ -0,0 +1,335 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2017, 2018.
|
||||
// Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_HAVERSINE_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_HAVERSINE_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
|
||||
#include <boost/geometry/srs/sphere.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
#include <boost/geometry/strategies/spherical/get_radius.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace strategy { namespace distance
|
||||
{
|
||||
|
||||
|
||||
namespace comparable
|
||||
{
|
||||
|
||||
// Comparable haversine.
|
||||
// To compare distances, we can avoid:
|
||||
// - multiplication with radius and 2.0
|
||||
// - applying sqrt
|
||||
// - applying asin (which is strictly (monotone) increasing)
|
||||
template
|
||||
<
|
||||
typename RadiusTypeOrSphere = double,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class haversine
|
||||
{
|
||||
public :
|
||||
template <typename Point1, typename Point2>
|
||||
struct calculation_type
|
||||
: promote_floating_point
|
||||
<
|
||||
typename select_calculation_type
|
||||
<
|
||||
Point1,
|
||||
Point2,
|
||||
CalculationType
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
typedef typename strategy_detail::get_radius
|
||||
<
|
||||
RadiusTypeOrSphere
|
||||
>::type radius_type;
|
||||
|
||||
inline haversine()
|
||||
: m_radius(1.0)
|
||||
{}
|
||||
|
||||
template <typename RadiusOrSphere>
|
||||
explicit inline haversine(RadiusOrSphere const& radius_or_sphere)
|
||||
: m_radius(strategy_detail::get_radius
|
||||
<
|
||||
RadiusOrSphere
|
||||
>::apply(radius_or_sphere))
|
||||
{}
|
||||
|
||||
template <typename Point1, typename Point2>
|
||||
static inline typename calculation_type<Point1, Point2>::type
|
||||
apply(Point1 const& p1, Point2 const& p2)
|
||||
{
|
||||
return calculate<typename calculation_type<Point1, Point2>::type>(
|
||||
get_as_radian<0>(p1), get_as_radian<1>(p1),
|
||||
get_as_radian<0>(p2), get_as_radian<1>(p2)
|
||||
);
|
||||
}
|
||||
|
||||
inline radius_type radius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
template <typename R, typename T1, typename T2>
|
||||
static inline R calculate(T1 const& lon1, T1 const& lat1,
|
||||
T2 const& lon2, T2 const& lat2)
|
||||
{
|
||||
return math::hav(lat2 - lat1)
|
||||
+ cos(lat1) * cos(lat2) * math::hav(lon2 - lon1);
|
||||
}
|
||||
|
||||
radius_type m_radius;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace comparable
|
||||
|
||||
/*!
|
||||
\brief Distance calculation for spherical coordinates
|
||||
on a perfect sphere using haversine
|
||||
\ingroup strategies
|
||||
\tparam RadiusTypeOrSphere \tparam_radius_or_sphere
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\author Adapted from: http://williams.best.vwh.net/avform.htm
|
||||
\see http://en.wikipedia.org/wiki/Great-circle_distance
|
||||
\note (from Wiki:) The great circle distance d between two
|
||||
points with coordinates {lat1,lon1} and {lat2,lon2} is given by:
|
||||
d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
|
||||
A mathematically equivalent formula, which is less subject
|
||||
to rounding error for short distances is:
|
||||
d=2*asin(sqrt((sin((lat1-lat2) / 2))^2
|
||||
+ cos(lat1)*cos(lat2)*(sin((lon1-lon2) / 2))^2))
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename RadiusTypeOrSphere = double,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class haversine
|
||||
{
|
||||
typedef comparable::haversine<RadiusTypeOrSphere, CalculationType> comparable_type;
|
||||
|
||||
public :
|
||||
template <typename Point1, typename Point2>
|
||||
struct calculation_type
|
||||
: services::return_type<comparable_type, Point1, Point2>
|
||||
{};
|
||||
|
||||
typedef typename strategy_detail::get_radius
|
||||
<
|
||||
RadiusTypeOrSphere
|
||||
>::type radius_type;
|
||||
|
||||
/*!
|
||||
\brief Default constructor, radius set to 1.0 for the unit sphere
|
||||
*/
|
||||
inline haversine()
|
||||
: m_radius(1.0)
|
||||
{}
|
||||
|
||||
/*!
|
||||
\brief Constructor
|
||||
\param radius_or_sphere radius of the sphere or sphere model
|
||||
*/
|
||||
template <typename RadiusOrSphere>
|
||||
explicit inline haversine(RadiusOrSphere const& radius_or_sphere)
|
||||
: m_radius(strategy_detail::get_radius
|
||||
<
|
||||
RadiusOrSphere
|
||||
>::apply(radius_or_sphere))
|
||||
{}
|
||||
|
||||
/*!
|
||||
\brief applies the distance calculation
|
||||
\return the calculated distance (including multiplying with radius)
|
||||
\param p1 first point
|
||||
\param p2 second point
|
||||
*/
|
||||
template <typename Point1, typename Point2>
|
||||
inline typename calculation_type<Point1, Point2>::type
|
||||
apply(Point1 const& p1, Point2 const& p2) const
|
||||
{
|
||||
typedef typename calculation_type<Point1, Point2>::type calculation_type;
|
||||
calculation_type const a = comparable_type::apply(p1, p2);
|
||||
calculation_type const c = calculation_type(2.0) * asin(math::sqrt(a));
|
||||
return calculation_type(m_radius) * c;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief access to radius value
|
||||
\return the radius
|
||||
*/
|
||||
inline radius_type radius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
private :
|
||||
radius_type m_radius;
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct tag<haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef strategy_tag_distance_point_point type;
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType, typename P1, typename P2>
|
||||
struct return_type<haversine<RadiusType, CalculationType>, P1, P2>
|
||||
: haversine<RadiusType, CalculationType>::template calculation_type<P1, P2>
|
||||
{};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct comparable_type<haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef comparable::haversine<RadiusType, CalculationType> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct get_comparable<haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
private :
|
||||
typedef haversine<RadiusType, CalculationType> this_type;
|
||||
typedef comparable::haversine<RadiusType, CalculationType> comparable_type;
|
||||
public :
|
||||
static inline comparable_type apply(this_type const& input)
|
||||
{
|
||||
return comparable_type(input.radius());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename RadiusType, typename CalculationType, typename P1, typename P2>
|
||||
struct result_from_distance<haversine<RadiusType, CalculationType>, P1, P2>
|
||||
{
|
||||
private :
|
||||
typedef haversine<RadiusType, CalculationType> this_type;
|
||||
typedef typename return_type<this_type, P1, P2>::type return_type;
|
||||
public :
|
||||
template <typename T>
|
||||
static inline return_type apply(this_type const& , T const& value)
|
||||
{
|
||||
return return_type(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Specializations for comparable::haversine
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct tag<comparable::haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef strategy_tag_distance_point_point type;
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType, typename P1, typename P2>
|
||||
struct return_type<comparable::haversine<RadiusType, CalculationType>, P1, P2>
|
||||
: comparable::haversine<RadiusType, CalculationType>::template calculation_type<P1, P2>
|
||||
{};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct comparable_type<comparable::haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
typedef comparable::haversine<RadiusType, CalculationType> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType>
|
||||
struct get_comparable<comparable::haversine<RadiusType, CalculationType> >
|
||||
{
|
||||
private :
|
||||
typedef comparable::haversine<RadiusType, CalculationType> this_type;
|
||||
public :
|
||||
static inline this_type apply(this_type const& input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename RadiusType, typename CalculationType, typename P1, typename P2>
|
||||
struct result_from_distance<comparable::haversine<RadiusType, CalculationType>, P1, P2>
|
||||
{
|
||||
private :
|
||||
typedef comparable::haversine<RadiusType, CalculationType> strategy_type;
|
||||
typedef typename return_type<strategy_type, P1, P2>::type return_type;
|
||||
public :
|
||||
template <typename T>
|
||||
static inline return_type apply(strategy_type const& strategy, T const& distance)
|
||||
{
|
||||
return_type const s = sin((distance / strategy.radius()) / return_type(2));
|
||||
return s * s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Register it as the default for point-types
|
||||
// in a spherical equatorial coordinate system
|
||||
template <typename Point1, typename Point2>
|
||||
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;
|
||||
};
|
||||
|
||||
// Note: spherical polar coordinate system requires "get_as_radian_equatorial"
|
||||
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::distance
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_HAVERSINE_HPP
|
||||
@@ -0,0 +1,371 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2018-2019 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_SEGMENT_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_SEGMENT_BOX_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/detail/distance/segment_to_box.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
#include <boost/geometry/strategies/normalize.hpp>
|
||||
#include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
|
||||
#include <boost/geometry/strategies/spherical/point_in_point.hpp>
|
||||
#include <boost/geometry/strategies/cartesian/point_in_box.hpp> // spherical
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace strategy { namespace distance
|
||||
{
|
||||
|
||||
struct generic_segment_box
|
||||
{
|
||||
template
|
||||
<
|
||||
typename LessEqual,
|
||||
typename ReturnType,
|
||||
typename SegmentPoint,
|
||||
typename BoxPoint,
|
||||
typename SegmentBoxStrategy,
|
||||
typename AzimuthStrategy,
|
||||
typename EnvelopeSegmentStrategy,
|
||||
typename NormalizePointStrategy,
|
||||
typename DisjointPointBoxStrategy,
|
||||
typename DisjointBoxBoxStrategy
|
||||
>
|
||||
static inline ReturnType segment_below_of_box(
|
||||
SegmentPoint const& p0,
|
||||
SegmentPoint const& p1,
|
||||
BoxPoint const&,
|
||||
BoxPoint const& top_right,
|
||||
BoxPoint const& bottom_left,
|
||||
BoxPoint const& bottom_right,
|
||||
SegmentBoxStrategy const& sb_strategy,
|
||||
AzimuthStrategy const& az_strategy,
|
||||
EnvelopeSegmentStrategy const& es_strategy,
|
||||
NormalizePointStrategy const& np_strategy,
|
||||
DisjointPointBoxStrategy const& dpb_strategy,
|
||||
DisjointBoxBoxStrategy const& dbb_strategy)
|
||||
{
|
||||
ReturnType result;
|
||||
typename LessEqual::other less_equal;
|
||||
typedef geometry::model::segment<SegmentPoint> Segment;
|
||||
typedef typename cs_tag<Segment>::type segment_cs_type;
|
||||
typedef geometry::detail::disjoint::
|
||||
disjoint_segment_box_sphere_or_spheroid<segment_cs_type>
|
||||
disjoint_sb;
|
||||
typedef typename disjoint_sb::disjoint_info disjoint_info_type;
|
||||
|
||||
Segment seg(p0, p1);
|
||||
|
||||
geometry::model::box<BoxPoint> input_box;
|
||||
geometry::set_from_radian<geometry::min_corner, 0>
|
||||
(input_box, geometry::get_as_radian<0>(bottom_left));
|
||||
geometry::set_from_radian<geometry::min_corner, 1>
|
||||
(input_box, geometry::get_as_radian<1>(bottom_left));
|
||||
geometry::set_from_radian<geometry::max_corner, 0>
|
||||
(input_box, geometry::get_as_radian<0>(top_right));
|
||||
geometry::set_from_radian<geometry::max_corner, 1>
|
||||
(input_box, geometry::get_as_radian<1>(top_right));
|
||||
|
||||
SegmentPoint p_max;
|
||||
|
||||
disjoint_info_type disjoint_result = disjoint_sb::
|
||||
apply(seg, input_box, p_max,
|
||||
az_strategy, np_strategy, dpb_strategy, dbb_strategy);
|
||||
|
||||
if (disjoint_result == disjoint_info_type::intersect) //intersect
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// disjoint but vertex not computed
|
||||
if (disjoint_result == disjoint_info_type::disjoint_no_vertex)
|
||||
{
|
||||
typedef typename coordinate_type<SegmentPoint>::type CT;
|
||||
|
||||
geometry::model::box<SegmentPoint> mbr;
|
||||
geometry::envelope(seg, mbr, es_strategy);
|
||||
|
||||
CT lon1 = geometry::get_as_radian<0>(p0);
|
||||
CT lat1 = geometry::get_as_radian<1>(p0);
|
||||
CT lon2 = geometry::get_as_radian<0>(p1);
|
||||
CT lat2 = geometry::get_as_radian<1>(p1);
|
||||
|
||||
if (lon1 > lon2)
|
||||
{
|
||||
std::swap(lon1, lon2);
|
||||
std::swap(lat1, lat2);
|
||||
}
|
||||
|
||||
CT vertex_lat;
|
||||
CT lat_sum = lat1 + lat2;
|
||||
if (lat_sum > CT(0))
|
||||
{
|
||||
vertex_lat = geometry::get_as_radian<geometry::max_corner, 1>(mbr);
|
||||
} else {
|
||||
vertex_lat = geometry::get_as_radian<geometry::min_corner, 1>(mbr);
|
||||
}
|
||||
|
||||
CT alp1;
|
||||
az_strategy.apply(lon1, lat1, lon2, lat2, alp1);
|
||||
CT vertex_lon = geometry::formula::vertex_longitude
|
||||
<
|
||||
CT,
|
||||
segment_cs_type
|
||||
>::apply(lon1, lat1, lon2, lat2,
|
||||
vertex_lat, alp1, az_strategy);
|
||||
|
||||
geometry::set_from_radian<0>(p_max, vertex_lon);
|
||||
geometry::set_from_radian<1>(p_max, vertex_lat);
|
||||
}
|
||||
//otherwise disjoint and vertex computed inside disjoint
|
||||
|
||||
if (less_equal(geometry::get_as_radian<0>(bottom_left),
|
||||
geometry::get_as_radian<0>(p_max)))
|
||||
{
|
||||
result = boost::numeric_cast<ReturnType>(typename
|
||||
SegmentBoxStrategy::distance_ps_strategy::type().apply(bottom_left, p0, p1));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = geometry::detail::distance::segment_to_box_2D
|
||||
<
|
||||
ReturnType,
|
||||
SegmentPoint,
|
||||
BoxPoint,
|
||||
SegmentBoxStrategy
|
||||
>::template call_above_of_box
|
||||
<
|
||||
typename LessEqual::other
|
||||
>(p1, p0, p_max, bottom_right, sb_strategy);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename SPoint, typename BPoint>
|
||||
static void mirror(SPoint& p0,
|
||||
SPoint& p1,
|
||||
BPoint& bottom_left,
|
||||
BPoint& bottom_right,
|
||||
BPoint& top_left,
|
||||
BPoint& top_right)
|
||||
{
|
||||
//if segment's vertex is the southest point then mirror geometries
|
||||
if (geometry::get<1>(p0) + geometry::get<1>(p1) < 0)
|
||||
{
|
||||
BPoint bl = bottom_left;
|
||||
BPoint br = bottom_right;
|
||||
geometry::set<1>(p0, geometry::get<1>(p0) * -1);
|
||||
geometry::set<1>(p1, geometry::get<1>(p1) * -1);
|
||||
geometry::set<1>(bottom_left, geometry::get<1>(top_left) * -1);
|
||||
geometry::set<1>(top_left, geometry::get<1>(bl) * -1);
|
||||
geometry::set<1>(bottom_right, geometry::get<1>(top_right) * -1);
|
||||
geometry::set<1>(top_right, geometry::get<1>(br) * -1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename Strategy = haversine<double, CalculationType>
|
||||
>
|
||||
struct spherical_segment_box
|
||||
{
|
||||
template <typename PointOfSegment, typename PointOfBox>
|
||||
struct calculation_type
|
||||
: promote_floating_point
|
||||
<
|
||||
typename strategy::distance::services::return_type
|
||||
<
|
||||
Strategy,
|
||||
PointOfSegment,
|
||||
PointOfBox
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
// strategy getters
|
||||
|
||||
// point-point strategy getters
|
||||
struct distance_pp_strategy
|
||||
{
|
||||
typedef Strategy type;
|
||||
};
|
||||
|
||||
inline typename distance_pp_strategy::type get_distance_pp_strategy() const
|
||||
{
|
||||
return typename distance_pp_strategy::type();
|
||||
}
|
||||
// point-segment strategy getters
|
||||
struct distance_ps_strategy
|
||||
{
|
||||
typedef cross_track<CalculationType, Strategy> type;
|
||||
};
|
||||
|
||||
inline typename distance_ps_strategy::type get_distance_ps_strategy() const
|
||||
{
|
||||
return typename distance_ps_strategy::type();
|
||||
}
|
||||
|
||||
typedef within::spherical_point_point equals_point_point_strategy_type;
|
||||
|
||||
static inline equals_point_point_strategy_type get_equals_point_point_strategy()
|
||||
{
|
||||
return equals_point_point_strategy_type();
|
||||
}
|
||||
|
||||
// methods
|
||||
|
||||
template <typename LessEqual, typename ReturnType,
|
||||
typename SegmentPoint, typename BoxPoint>
|
||||
inline ReturnType segment_below_of_box(SegmentPoint const& p0,
|
||||
SegmentPoint const& p1,
|
||||
BoxPoint const& top_left,
|
||||
BoxPoint const& top_right,
|
||||
BoxPoint const& bottom_left,
|
||||
BoxPoint const& bottom_right) const
|
||||
{
|
||||
typedef typename azimuth::spherical<CalculationType> azimuth_strategy_type;
|
||||
azimuth_strategy_type az_strategy;
|
||||
|
||||
typedef typename envelope::spherical_segment<CalculationType>
|
||||
envelope_segment_strategy_type;
|
||||
envelope_segment_strategy_type es_strategy;
|
||||
|
||||
return generic_segment_box::segment_below_of_box
|
||||
<
|
||||
LessEqual,
|
||||
ReturnType
|
||||
>(p0,p1,top_left,top_right,bottom_left,bottom_right,
|
||||
spherical_segment_box<CalculationType>(),
|
||||
az_strategy, es_strategy,
|
||||
normalize::spherical_point(),
|
||||
covered_by::spherical_point_box(),
|
||||
disjoint::spherical_box_box());
|
||||
}
|
||||
|
||||
template <typename SPoint, typename BPoint>
|
||||
static void mirror(SPoint& p0,
|
||||
SPoint& p1,
|
||||
BPoint& bottom_left,
|
||||
BPoint& bottom_right,
|
||||
BPoint& top_left,
|
||||
BPoint& top_right)
|
||||
{
|
||||
|
||||
generic_segment_box::mirror(p0, p1,
|
||||
bottom_left, bottom_right,
|
||||
top_left, top_right);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct tag<spherical_segment_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef strategy_tag_distance_segment_box type;
|
||||
};
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename PS, typename PB>
|
||||
struct return_type<spherical_segment_box<CalculationType, Strategy>, PS, PB>
|
||||
: spherical_segment_box<CalculationType, Strategy>::template calculation_type<PS, PB>
|
||||
{};
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct comparable_type<spherical_segment_box<CalculationType, Strategy> >
|
||||
{
|
||||
// Define a cartesian_segment_box strategy with its underlying point-segment
|
||||
// strategy being comparable
|
||||
typedef spherical_segment_box
|
||||
<
|
||||
CalculationType,
|
||||
typename comparable_type<Strategy>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType, typename Strategy>
|
||||
struct get_comparable<spherical_segment_box<CalculationType, Strategy> >
|
||||
{
|
||||
typedef typename comparable_type
|
||||
<
|
||||
spherical_segment_box<CalculationType, Strategy>
|
||||
>::type comparable_type;
|
||||
public :
|
||||
static inline comparable_type apply(spherical_segment_box<CalculationType, Strategy> const& )
|
||||
{
|
||||
return comparable_type();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CalculationType, typename Strategy, typename PS, typename PB>
|
||||
struct result_from_distance<spherical_segment_box<CalculationType, Strategy>, PS, PB>
|
||||
{
|
||||
private :
|
||||
typedef typename return_type<
|
||||
spherical_segment_box
|
||||
<
|
||||
CalculationType,
|
||||
Strategy
|
||||
>,
|
||||
PS,
|
||||
PB
|
||||
>::type return_type;
|
||||
public :
|
||||
template <typename T>
|
||||
static inline return_type apply(spherical_segment_box<CalculationType,
|
||||
Strategy> const& ,
|
||||
T const& value)
|
||||
{
|
||||
Strategy s;
|
||||
return result_from_distance<Strategy, PS, PB>::apply(s, value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Segment, typename Box>
|
||||
struct default_strategy
|
||||
<
|
||||
segment_tag, box_tag, Segment, Box,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>
|
||||
{
|
||||
typedef spherical_segment_box<> type;
|
||||
};
|
||||
|
||||
template <typename Box, typename Segment>
|
||||
struct default_strategy
|
||||
<
|
||||
box_tag, segment_tag, Box, Segment,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>
|
||||
{
|
||||
typedef typename default_strategy
|
||||
<
|
||||
segment_tag, box_tag, Segment, Box,
|
||||
spherical_equatorial_tag, spherical_equatorial_tag
|
||||
>::type type;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
}} // namespace strategy::distance
|
||||
|
||||
}} // namespace boost::geometry
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_DISTANCE_SEGMENT_BOX_HPP
|
||||
146
macx64/include/boost/geometry/strategies/spherical/envelope.hpp
Normal file
146
macx64/include/boost/geometry/strategies/spherical/envelope.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2015, 2016, 2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, 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.
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_ENVELOPE_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
|
||||
|
||||
#include <boost/geometry/iterators/segment_iterator.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/spherical/envelope_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope_segment.hpp>
|
||||
#include <boost/geometry/strategies/spherical/expand_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/expand_segment.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace envelope
|
||||
{
|
||||
|
||||
template <typename CalculationType = void>
|
||||
class spherical
|
||||
{
|
||||
public:
|
||||
typedef spherical_segment<CalculationType> element_envelope_strategy_type;
|
||||
static inline element_envelope_strategy_type get_element_envelope_strategy()
|
||||
{
|
||||
return element_envelope_strategy_type();
|
||||
}
|
||||
|
||||
typedef expand::spherical_segment<CalculationType> element_expand_strategy_type;
|
||||
static inline element_expand_strategy_type get_element_expand_strategy()
|
||||
{
|
||||
return element_expand_strategy_type();
|
||||
}
|
||||
|
||||
typedef strategy::expand::spherical_box box_expand_strategy_type;
|
||||
static inline box_expand_strategy_type get_box_expand_strategy()
|
||||
{
|
||||
return box_expand_strategy_type();
|
||||
}
|
||||
|
||||
// Linestring, Ring, Polygon
|
||||
|
||||
template <typename Range>
|
||||
static inline geometry::segment_iterator<Range const> begin(Range const& range)
|
||||
{
|
||||
return geometry::segments_begin(range);
|
||||
}
|
||||
|
||||
template <typename Range>
|
||||
static inline geometry::segment_iterator<Range const> end(Range const& range)
|
||||
{
|
||||
return geometry::segments_end(range);
|
||||
}
|
||||
|
||||
// MultiLinestring, MultiPolygon
|
||||
|
||||
template <typename Box>
|
||||
struct multi_state
|
||||
{
|
||||
void apply(Box const& single_box)
|
||||
{
|
||||
m_boxes.push_back(single_box);
|
||||
}
|
||||
|
||||
void result(Box & box)
|
||||
{
|
||||
if (!m_boxes.empty())
|
||||
{
|
||||
geometry::detail::envelope::envelope_range_of_boxes::apply(m_boxes, box);
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry::detail::envelope::initialize<Box, 0, dimension<Box>::value>::apply(box);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Box> m_boxes;
|
||||
};
|
||||
|
||||
// Segment
|
||||
|
||||
template <typename Point1, typename Point2, typename Box>
|
||||
static inline void apply(Point1 const& point1, Point2 const& point2,
|
||||
Box& box)
|
||||
{
|
||||
spherical_segment<CalculationType>::apply(point1, point2, box);
|
||||
}
|
||||
|
||||
// Box
|
||||
|
||||
template <typename BoxIn, typename Box>
|
||||
static inline void apply(BoxIn const& box_in, Box& box)
|
||||
{
|
||||
spherical_box::apply(box_in, box);
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename Tag, typename CalculationType>
|
||||
struct default_strategy<Tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical<CalculationType> type;
|
||||
};
|
||||
|
||||
template <typename Tag, typename CalculationType>
|
||||
struct default_strategy<Tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical<CalculationType> type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::envelope
|
||||
|
||||
}} //namepsace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_HPP
|
||||
@@ -0,0 +1,145 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2015-2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_ENVELOPE_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_BOX_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/views/detail/indexed_point_view.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
|
||||
#include <boost/geometry/algorithms/detail/normalize.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/dispatch/envelope.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/envelope.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace envelope
|
||||
{
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
std::size_t Index,
|
||||
std::size_t DimensionCount
|
||||
>
|
||||
struct envelope_indexed_box_on_spheroid
|
||||
{
|
||||
template <typename BoxIn, typename BoxOut>
|
||||
static inline void apply(BoxIn const& box_in, BoxOut& mbr)
|
||||
{
|
||||
// transform() does not work with boxes of dimension higher
|
||||
// than 2; to account for such boxes we transform the min/max
|
||||
// points of the boxes using the indexed_point_view
|
||||
detail::indexed_point_view<BoxIn const, Index> box_in_corner(box_in);
|
||||
detail::indexed_point_view<BoxOut, Index> mbr_corner(mbr);
|
||||
|
||||
// first transform the units
|
||||
transform_units(box_in_corner, mbr_corner);
|
||||
|
||||
// now transform the remaining coordinates
|
||||
detail::conversion::point_to_point
|
||||
<
|
||||
detail::indexed_point_view<BoxIn const, Index>,
|
||||
detail::indexed_point_view<BoxOut, Index>,
|
||||
2,
|
||||
DimensionCount
|
||||
>::apply(box_in_corner, mbr_corner);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace detail::envelope
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
namespace strategy { namespace envelope
|
||||
{
|
||||
|
||||
|
||||
struct spherical_box
|
||||
{
|
||||
template <typename BoxIn, typename BoxOut>
|
||||
static inline void apply(BoxIn const& box_in, BoxOut& mbr)
|
||||
{
|
||||
BoxIn box_in_normalized = box_in;
|
||||
|
||||
if (!is_inverse_spheroidal_coordinates(box_in))
|
||||
{
|
||||
strategy::normalize::spherical_box::apply(box_in, box_in_normalized);
|
||||
}
|
||||
|
||||
geometry::detail::envelope::envelope_indexed_box_on_spheroid
|
||||
<
|
||||
min_corner, dimension<BoxIn>::value
|
||||
>::apply(box_in_normalized, mbr);
|
||||
|
||||
geometry::detail::envelope::envelope_indexed_box_on_spheroid
|
||||
<
|
||||
max_corner, dimension<BoxIn>::value
|
||||
>::apply(box_in_normalized, mbr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_box type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_box type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, geographic_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_box type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::envelope
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_BOX_HPP
|
||||
@@ -0,0 +1,379 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_ENVELOPE_MULTIPOINT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_MULTIPOINT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/minmax_element.hpp>
|
||||
#include <boost/range.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/range.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/helper_geometry.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/box.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/range.hpp>
|
||||
#include <boost/geometry/algorithms/detail/expand/point.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/envelope_point.hpp>
|
||||
#include <boost/geometry/strategies/normalize.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope_point.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace envelope
|
||||
{
|
||||
|
||||
class spherical_multipoint
|
||||
{
|
||||
private:
|
||||
template <std::size_t Dim>
|
||||
struct coordinate_less
|
||||
{
|
||||
template <typename Point>
|
||||
inline bool operator()(Point const& point1, Point const& point2) const
|
||||
{
|
||||
return math::smaller(geometry::get<Dim>(point1),
|
||||
geometry::get<Dim>(point2));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Constants, typename MultiPoint, typename OutputIterator>
|
||||
static inline void analyze_point_coordinates(MultiPoint const& multipoint,
|
||||
bool& has_south_pole,
|
||||
bool& has_north_pole,
|
||||
OutputIterator oit)
|
||||
{
|
||||
typedef typename boost::range_value<MultiPoint>::type point_type;
|
||||
typedef typename boost::range_iterator
|
||||
<
|
||||
MultiPoint const
|
||||
>::type iterator_type;
|
||||
|
||||
// analyze point coordinates:
|
||||
// (1) normalize point coordinates
|
||||
// (2) check if any point is the north or the south pole
|
||||
// (3) put all non-pole points in a container
|
||||
//
|
||||
// notice that at this point in the algorithm, we have at
|
||||
// least two points on the spheroid
|
||||
has_south_pole = false;
|
||||
has_north_pole = false;
|
||||
|
||||
for (iterator_type it = boost::begin(multipoint);
|
||||
it != boost::end(multipoint);
|
||||
++it)
|
||||
{
|
||||
point_type point;
|
||||
normalize::spherical_point::apply(*it, point);
|
||||
|
||||
if (math::equals(geometry::get<1>(point),
|
||||
Constants::min_latitude()))
|
||||
{
|
||||
has_south_pole = true;
|
||||
}
|
||||
else if (math::equals(geometry::get<1>(point),
|
||||
Constants::max_latitude()))
|
||||
{
|
||||
has_north_pole = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*oit++ = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SortedRange, typename Value>
|
||||
static inline Value maximum_gap(SortedRange const& sorted_range,
|
||||
Value& max_gap_left,
|
||||
Value& max_gap_right)
|
||||
{
|
||||
typedef typename boost::range_iterator
|
||||
<
|
||||
SortedRange const
|
||||
>::type iterator_type;
|
||||
|
||||
iterator_type it1 = boost::begin(sorted_range), it2 = it1;
|
||||
++it2;
|
||||
max_gap_left = geometry::get<0>(*it1);
|
||||
max_gap_right = geometry::get<0>(*it2);
|
||||
|
||||
Value max_gap = max_gap_right - max_gap_left;
|
||||
for (++it1, ++it2; it2 != boost::end(sorted_range); ++it1, ++it2)
|
||||
{
|
||||
Value gap = geometry::get<0>(*it2) - geometry::get<0>(*it1);
|
||||
if (math::larger(gap, max_gap))
|
||||
{
|
||||
max_gap_left = geometry::get<0>(*it1);
|
||||
max_gap_right = geometry::get<0>(*it2);
|
||||
max_gap = gap;
|
||||
}
|
||||
}
|
||||
|
||||
return max_gap;
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename Constants,
|
||||
typename PointRange,
|
||||
typename LongitudeLess,
|
||||
typename CoordinateType
|
||||
>
|
||||
static inline void get_min_max_longitudes(PointRange& range,
|
||||
LongitudeLess const& lon_less,
|
||||
CoordinateType& lon_min,
|
||||
CoordinateType& lon_max)
|
||||
{
|
||||
typedef typename boost::range_iterator
|
||||
<
|
||||
PointRange const
|
||||
>::type iterator_type;
|
||||
|
||||
// compute min and max longitude values
|
||||
std::pair<iterator_type, iterator_type> min_max_longitudes
|
||||
= boost::minmax_element(boost::begin(range),
|
||||
boost::end(range),
|
||||
lon_less);
|
||||
|
||||
lon_min = geometry::get<0>(*min_max_longitudes.first);
|
||||
lon_max = geometry::get<0>(*min_max_longitudes.second);
|
||||
|
||||
// if the longitude span is "large" compute the true maximum gap
|
||||
if (math::larger(lon_max - lon_min, Constants::half_period()))
|
||||
{
|
||||
std::sort(boost::begin(range), boost::end(range), lon_less);
|
||||
|
||||
CoordinateType max_gap_left = 0, max_gap_right = 0;
|
||||
CoordinateType max_gap
|
||||
= maximum_gap(range, max_gap_left, max_gap_right);
|
||||
|
||||
CoordinateType complement_gap
|
||||
= Constants::period() + lon_min - lon_max;
|
||||
|
||||
if (math::larger(max_gap, complement_gap))
|
||||
{
|
||||
lon_min = max_gap_right;
|
||||
lon_max = max_gap_left + Constants::period();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename Constants,
|
||||
typename Iterator,
|
||||
typename LatitudeLess,
|
||||
typename CoordinateType
|
||||
>
|
||||
static inline void get_min_max_latitudes(Iterator const first,
|
||||
Iterator const last,
|
||||
LatitudeLess const& lat_less,
|
||||
bool has_south_pole,
|
||||
bool has_north_pole,
|
||||
CoordinateType& lat_min,
|
||||
CoordinateType& lat_max)
|
||||
{
|
||||
if (has_south_pole && has_north_pole)
|
||||
{
|
||||
lat_min = Constants::min_latitude();
|
||||
lat_max = Constants::max_latitude();
|
||||
}
|
||||
else if (has_south_pole)
|
||||
{
|
||||
lat_min = Constants::min_latitude();
|
||||
lat_max
|
||||
= geometry::get<1>(*std::max_element(first, last, lat_less));
|
||||
}
|
||||
else if (has_north_pole)
|
||||
{
|
||||
lat_min
|
||||
= geometry::get<1>(*std::min_element(first, last, lat_less));
|
||||
lat_max = Constants::max_latitude();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<Iterator, Iterator> min_max_latitudes
|
||||
= boost::minmax_element(first, last, lat_less);
|
||||
|
||||
lat_min = geometry::get<1>(*min_max_latitudes.first);
|
||||
lat_max = geometry::get<1>(*min_max_latitudes.second);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename MultiPoint, typename Box>
|
||||
static inline void apply(MultiPoint const& multipoint, Box& mbr)
|
||||
{
|
||||
typedef typename point_type<MultiPoint>::type point_type;
|
||||
typedef typename coordinate_type<MultiPoint>::type coordinate_type;
|
||||
typedef typename boost::range_iterator
|
||||
<
|
||||
MultiPoint const
|
||||
>::type iterator_type;
|
||||
|
||||
typedef math::detail::constants_on_spheroid
|
||||
<
|
||||
coordinate_type,
|
||||
typename geometry::detail::cs_angular_units<MultiPoint>::type
|
||||
> constants;
|
||||
|
||||
if (boost::empty(multipoint))
|
||||
{
|
||||
geometry::detail::envelope::initialize<Box, 0, dimension<Box>::value>::apply(mbr);
|
||||
return;
|
||||
}
|
||||
|
||||
geometry::detail::envelope::initialize<Box, 0, 2>::apply(mbr);
|
||||
|
||||
if (boost::size(multipoint) == 1)
|
||||
{
|
||||
return dispatch::envelope
|
||||
<
|
||||
typename boost::range_value<MultiPoint>::type
|
||||
>::apply(range::front(multipoint), mbr, strategy::envelope::spherical_point());
|
||||
}
|
||||
|
||||
// analyze the points and put the non-pole ones in the
|
||||
// points vector
|
||||
std::vector<point_type> points;
|
||||
bool has_north_pole = false, has_south_pole = false;
|
||||
|
||||
analyze_point_coordinates<constants>(multipoint,
|
||||
has_south_pole, has_north_pole,
|
||||
std::back_inserter(points));
|
||||
|
||||
coordinate_type lon_min, lat_min, lon_max, lat_max;
|
||||
if (points.size() == 1)
|
||||
{
|
||||
// we have one non-pole point and at least one pole point
|
||||
lon_min = geometry::get<0>(range::front(points));
|
||||
lon_max = geometry::get<0>(range::front(points));
|
||||
lat_min = has_south_pole
|
||||
? constants::min_latitude()
|
||||
: constants::max_latitude();
|
||||
lat_max = has_north_pole
|
||||
? constants::max_latitude()
|
||||
: constants::min_latitude();
|
||||
}
|
||||
else if (points.empty())
|
||||
{
|
||||
// all points are pole points
|
||||
BOOST_GEOMETRY_ASSERT(has_south_pole || has_north_pole);
|
||||
lon_min = coordinate_type(0);
|
||||
lon_max = coordinate_type(0);
|
||||
lat_min = has_south_pole
|
||||
? constants::min_latitude()
|
||||
: constants::max_latitude();
|
||||
lat_max = (has_north_pole)
|
||||
? constants::max_latitude()
|
||||
: constants::min_latitude();
|
||||
}
|
||||
else
|
||||
{
|
||||
get_min_max_longitudes<constants>(points,
|
||||
coordinate_less<0>(),
|
||||
lon_min,
|
||||
lon_max);
|
||||
|
||||
get_min_max_latitudes<constants>(points.begin(),
|
||||
points.end(),
|
||||
coordinate_less<1>(),
|
||||
has_south_pole,
|
||||
has_north_pole,
|
||||
lat_min,
|
||||
lat_max);
|
||||
}
|
||||
|
||||
typedef typename helper_geometry
|
||||
<
|
||||
Box,
|
||||
coordinate_type,
|
||||
typename geometry::detail::cs_angular_units<MultiPoint>::type
|
||||
>::type helper_box_type;
|
||||
|
||||
helper_box_type helper_mbr;
|
||||
|
||||
geometry::set<min_corner, 0>(helper_mbr, lon_min);
|
||||
geometry::set<min_corner, 1>(helper_mbr, lat_min);
|
||||
geometry::set<max_corner, 0>(helper_mbr, lon_max);
|
||||
geometry::set<max_corner, 1>(helper_mbr, lat_max);
|
||||
|
||||
// now transform to output MBR (per index)
|
||||
geometry::detail::envelope::envelope_indexed_box_on_spheroid<min_corner, 2>::apply(helper_mbr, mbr);
|
||||
geometry::detail::envelope::envelope_indexed_box_on_spheroid<max_corner, 2>::apply(helper_mbr, mbr);
|
||||
|
||||
// compute envelope for higher coordinates
|
||||
iterator_type it = boost::begin(multipoint);
|
||||
geometry::detail::envelope::envelope_one_point<2, dimension<Box>::value>::apply(*it, mbr);
|
||||
|
||||
for (++it; it != boost::end(multipoint); ++it)
|
||||
{
|
||||
strategy::expand::detail::point_loop
|
||||
<
|
||||
2, dimension<Box>::value
|
||||
>::apply(mbr, *it);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<multi_point_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_multipoint type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<multi_point_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_multipoint type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<multi_point_tag, geographic_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_multipoint type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::envelope
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_MULTIPOINT_HPP
|
||||
@@ -0,0 +1,111 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2015, 2016, 2017, 2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_ENVELOPE_POINT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_POINT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/views/detail/indexed_point_view.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
|
||||
#include <boost/geometry/algorithms/detail/normalize.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/envelope_point.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/envelope.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace envelope
|
||||
{
|
||||
|
||||
struct spherical_point
|
||||
{
|
||||
template<typename Point, typename Box>
|
||||
static inline void apply(Point const& point, Box& mbr)
|
||||
{
|
||||
Point normalized_point;
|
||||
strategy::normalize::spherical_point::apply(point, normalized_point);
|
||||
|
||||
typename point_type<Box>::type box_point;
|
||||
|
||||
// transform units of input point to units of a box point
|
||||
geometry::detail::envelope::transform_units(normalized_point, box_point);
|
||||
|
||||
geometry::set<min_corner, 0>(mbr, geometry::get<0>(box_point));
|
||||
geometry::set<min_corner, 1>(mbr, geometry::get<1>(box_point));
|
||||
|
||||
geometry::set<max_corner, 0>(mbr, geometry::get<0>(box_point));
|
||||
geometry::set<max_corner, 1>(mbr, geometry::get<1>(box_point));
|
||||
|
||||
typedef geometry::detail::envelope::envelope_one_point
|
||||
<
|
||||
2, dimension<Point>::value
|
||||
> per_corner;
|
||||
per_corner::template apply<min_corner>(normalized_point, mbr);
|
||||
per_corner::template apply<max_corner>(normalized_point, mbr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_point type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_point type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, geographic_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_point type;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::envelope
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_POINT_HPP
|
||||
@@ -0,0 +1,445 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2017-2018 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_SEGMENT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_SEGMENT_HPP
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
|
||||
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/point_type.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/formulas/meridian_segment.hpp>
|
||||
#include <boost/geometry/formulas/vertex_latitude.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/helper_geometry.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/envelope_segment.hpp>
|
||||
#include <boost/geometry/strategies/envelope.hpp>
|
||||
#include <boost/geometry/strategies/normalize.hpp>
|
||||
#include <boost/geometry/strategies/spherical/azimuth.hpp>
|
||||
#include <boost/geometry/strategies/spherical/expand_box.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace strategy { namespace envelope
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename CalculationType, typename CS_Tag>
|
||||
struct envelope_segment_call_vertex_latitude
|
||||
{
|
||||
template <typename T1, typename T2, typename Strategy>
|
||||
static inline CalculationType apply(T1 const& lat1,
|
||||
T2 const& alp1,
|
||||
Strategy const& )
|
||||
{
|
||||
return geometry::formula::vertex_latitude<CalculationType, CS_Tag>
|
||||
::apply(lat1, alp1);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct envelope_segment_call_vertex_latitude<CalculationType, geographic_tag>
|
||||
{
|
||||
template <typename T1, typename T2, typename Strategy>
|
||||
static inline CalculationType apply(T1 const& lat1,
|
||||
T2 const& alp1,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
return geometry::formula::vertex_latitude<CalculationType, geographic_tag>
|
||||
::apply(lat1, alp1, strategy.model());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Units, typename CS_Tag>
|
||||
struct envelope_segment_convert_polar
|
||||
{
|
||||
template <typename T>
|
||||
static inline void pre(T & , T & ) {}
|
||||
|
||||
template <typename T>
|
||||
static inline void post(T & , T & ) {}
|
||||
};
|
||||
|
||||
template <typename Units>
|
||||
struct envelope_segment_convert_polar<Units, spherical_polar_tag>
|
||||
{
|
||||
template <typename T>
|
||||
static inline void pre(T & lat1, T & lat2)
|
||||
{
|
||||
lat1 = math::latitude_convert_ep<Units>(lat1);
|
||||
lat2 = math::latitude_convert_ep<Units>(lat2);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline void post(T & lat1, T & lat2)
|
||||
{
|
||||
lat1 = math::latitude_convert_ep<Units>(lat1);
|
||||
lat2 = math::latitude_convert_ep<Units>(lat2);
|
||||
std::swap(lat1, lat2);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CS_Tag>
|
||||
class envelope_segment_impl
|
||||
{
|
||||
private:
|
||||
|
||||
// degrees or radians
|
||||
template <typename CalculationType>
|
||||
static inline void swap(CalculationType& lon1,
|
||||
CalculationType& lat1,
|
||||
CalculationType& lon2,
|
||||
CalculationType& lat2)
|
||||
{
|
||||
std::swap(lon1, lon2);
|
||||
std::swap(lat1, lat2);
|
||||
}
|
||||
|
||||
// radians
|
||||
template <typename CalculationType>
|
||||
static inline bool contains_pi_half(CalculationType const& a1,
|
||||
CalculationType const& a2)
|
||||
{
|
||||
// azimuths a1 and a2 are assumed to be in radians
|
||||
BOOST_GEOMETRY_ASSERT(! math::equals(a1, a2));
|
||||
|
||||
static CalculationType const pi_half = math::half_pi<CalculationType>();
|
||||
|
||||
return (a1 < a2)
|
||||
? (a1 < pi_half && pi_half < a2)
|
||||
: (a1 > pi_half && pi_half > a2);
|
||||
}
|
||||
|
||||
// radians or degrees
|
||||
template <typename Units, typename CoordinateType>
|
||||
static inline bool crosses_antimeridian(CoordinateType const& lon1,
|
||||
CoordinateType const& lon2)
|
||||
{
|
||||
typedef math::detail::constants_on_spheroid
|
||||
<
|
||||
CoordinateType, Units
|
||||
> constants;
|
||||
|
||||
return math::abs(lon1 - lon2) > constants::half_period(); // > pi
|
||||
}
|
||||
|
||||
// degrees or radians
|
||||
template <typename Units, typename CalculationType, typename Strategy>
|
||||
static inline void compute_box_corners(CalculationType& lon1,
|
||||
CalculationType& lat1,
|
||||
CalculationType& lon2,
|
||||
CalculationType& lat2,
|
||||
CalculationType a1,
|
||||
CalculationType a2,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
// coordinates are assumed to be in radians
|
||||
BOOST_GEOMETRY_ASSERT(lon1 <= lon2);
|
||||
boost::ignore_unused(lon1, lon2);
|
||||
|
||||
CalculationType lat1_rad = math::as_radian<Units>(lat1);
|
||||
CalculationType lat2_rad = math::as_radian<Units>(lat2);
|
||||
|
||||
if (math::equals(a1, a2))
|
||||
{
|
||||
// the segment must lie on the equator or is very short or is meridian
|
||||
return;
|
||||
}
|
||||
|
||||
if (lat1 > lat2)
|
||||
{
|
||||
std::swap(lat1, lat2);
|
||||
std::swap(lat1_rad, lat2_rad);
|
||||
std::swap(a1, a2);
|
||||
}
|
||||
|
||||
if (contains_pi_half(a1, a2))
|
||||
{
|
||||
CalculationType p_max = envelope_segment_call_vertex_latitude
|
||||
<CalculationType, CS_Tag>::apply(lat1_rad, a1, strategy);
|
||||
|
||||
CalculationType const mid_lat = lat1 + lat2;
|
||||
if (mid_lat < 0)
|
||||
{
|
||||
// update using min latitude
|
||||
CalculationType const lat_min_rad = -p_max;
|
||||
CalculationType const lat_min
|
||||
= math::from_radian<Units>(lat_min_rad);
|
||||
|
||||
if (lat1 > lat_min)
|
||||
{
|
||||
lat1 = lat_min;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// update using max latitude
|
||||
CalculationType const lat_max_rad = p_max;
|
||||
CalculationType const lat_max
|
||||
= math::from_radian<Units>(lat_max_rad);
|
||||
|
||||
if (lat2 < lat_max)
|
||||
{
|
||||
lat2 = lat_max;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Units, typename CalculationType>
|
||||
static inline void special_cases(CalculationType& lon1,
|
||||
CalculationType& lat1,
|
||||
CalculationType& lon2,
|
||||
CalculationType& lat2)
|
||||
{
|
||||
typedef math::detail::constants_on_spheroid
|
||||
<
|
||||
CalculationType, Units
|
||||
> constants;
|
||||
|
||||
bool is_pole1 = math::equals(math::abs(lat1), constants::max_latitude());
|
||||
bool is_pole2 = math::equals(math::abs(lat2), constants::max_latitude());
|
||||
|
||||
if (is_pole1 && is_pole2)
|
||||
{
|
||||
// both points are poles; nothing more to do:
|
||||
// longitudes are already normalized to 0
|
||||
// but just in case
|
||||
lon1 = 0;
|
||||
lon2 = 0;
|
||||
}
|
||||
else if (is_pole1 && !is_pole2)
|
||||
{
|
||||
// first point is a pole, second point is not:
|
||||
// make the longitude of the first point the same as that
|
||||
// of the second point
|
||||
lon1 = lon2;
|
||||
}
|
||||
else if (!is_pole1 && is_pole2)
|
||||
{
|
||||
// second point is a pole, first point is not:
|
||||
// make the longitude of the second point the same as that
|
||||
// of the first point
|
||||
lon2 = lon1;
|
||||
}
|
||||
|
||||
if (lon1 == lon2)
|
||||
{
|
||||
// segment lies on a meridian
|
||||
if (lat1 > lat2)
|
||||
{
|
||||
std::swap(lat1, lat2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BOOST_GEOMETRY_ASSERT(!is_pole1 && !is_pole2);
|
||||
|
||||
if (lon1 > lon2)
|
||||
{
|
||||
swap(lon1, lat1, lon2, lat2);
|
||||
}
|
||||
|
||||
if (crosses_antimeridian<Units>(lon1, lon2))
|
||||
{
|
||||
lon1 += constants::period();
|
||||
swap(lon1, lat1, lon2, lat2);
|
||||
}
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename Units,
|
||||
typename CalculationType,
|
||||
typename Box
|
||||
>
|
||||
static inline void create_box(CalculationType lon1,
|
||||
CalculationType lat1,
|
||||
CalculationType lon2,
|
||||
CalculationType lat2,
|
||||
Box& mbr)
|
||||
{
|
||||
typedef typename coordinate_type<Box>::type box_coordinate_type;
|
||||
|
||||
typedef typename helper_geometry
|
||||
<
|
||||
Box, box_coordinate_type, Units
|
||||
>::type helper_box_type;
|
||||
|
||||
helper_box_type helper_mbr;
|
||||
|
||||
geometry::set
|
||||
<
|
||||
min_corner, 0
|
||||
>(helper_mbr, boost::numeric_cast<box_coordinate_type>(lon1));
|
||||
|
||||
geometry::set
|
||||
<
|
||||
min_corner, 1
|
||||
>(helper_mbr, boost::numeric_cast<box_coordinate_type>(lat1));
|
||||
|
||||
geometry::set
|
||||
<
|
||||
max_corner, 0
|
||||
>(helper_mbr, boost::numeric_cast<box_coordinate_type>(lon2));
|
||||
|
||||
geometry::set
|
||||
<
|
||||
max_corner, 1
|
||||
>(helper_mbr, boost::numeric_cast<box_coordinate_type>(lat2));
|
||||
|
||||
geometry::detail::envelope::transform_units(helper_mbr, mbr);
|
||||
}
|
||||
|
||||
|
||||
template <typename Units, typename CalculationType, typename Strategy>
|
||||
static inline void apply(CalculationType& lon1,
|
||||
CalculationType& lat1,
|
||||
CalculationType& lon2,
|
||||
CalculationType& lat2,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
special_cases<Units>(lon1, lat1, lon2, lat2);
|
||||
|
||||
CalculationType lon1_rad = math::as_radian<Units>(lon1);
|
||||
CalculationType lat1_rad = math::as_radian<Units>(lat1);
|
||||
CalculationType lon2_rad = math::as_radian<Units>(lon2);
|
||||
CalculationType lat2_rad = math::as_radian<Units>(lat2);
|
||||
CalculationType alp1, alp2;
|
||||
strategy.apply(lon1_rad, lat1_rad, lon2_rad, lat2_rad, alp1, alp2);
|
||||
|
||||
compute_box_corners<Units>(lon1, lat1, lon2, lat2, alp1, alp2, strategy);
|
||||
}
|
||||
|
||||
public:
|
||||
template
|
||||
<
|
||||
typename Units,
|
||||
typename CalculationType,
|
||||
typename Box,
|
||||
typename Strategy
|
||||
>
|
||||
static inline void apply(CalculationType lon1,
|
||||
CalculationType lat1,
|
||||
CalculationType lon2,
|
||||
CalculationType lat2,
|
||||
Box& mbr,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
typedef envelope_segment_convert_polar<Units, typename cs_tag<Box>::type> convert_polar;
|
||||
|
||||
convert_polar::pre(lat1, lat2);
|
||||
|
||||
apply<Units>(lon1, lat1, lon2, lat2, strategy);
|
||||
|
||||
convert_polar::post(lat1, lat2);
|
||||
|
||||
create_box<Units>(lon1, lat1, lon2, lat2, mbr);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical_segment
|
||||
{
|
||||
public:
|
||||
typedef strategy::expand::spherical_box box_expand_strategy_type;
|
||||
static inline box_expand_strategy_type get_box_expand_strategy()
|
||||
{
|
||||
return box_expand_strategy_type();
|
||||
}
|
||||
|
||||
template <typename Point, typename Box>
|
||||
static inline void apply(Point const& point1, Point const& point2,
|
||||
Box& box)
|
||||
{
|
||||
Point p1_normalized, p2_normalized;
|
||||
strategy::normalize::spherical_point::apply(point1, p1_normalized);
|
||||
strategy::normalize::spherical_point::apply(point2, p2_normalized);
|
||||
|
||||
geometry::strategy::azimuth::spherical<CalculationType> azimuth_spherical;
|
||||
|
||||
typedef typename geometry::detail::cs_angular_units<Point>::type units_type;
|
||||
|
||||
// first compute the envelope range for the first two coordinates
|
||||
strategy::envelope::detail::envelope_segment_impl
|
||||
<
|
||||
spherical_equatorial_tag
|
||||
>::template apply<units_type>(geometry::get<0>(p1_normalized),
|
||||
geometry::get<1>(p1_normalized),
|
||||
geometry::get<0>(p2_normalized),
|
||||
geometry::get<1>(p2_normalized),
|
||||
box,
|
||||
azimuth_spherical);
|
||||
|
||||
// now compute the envelope range for coordinates of
|
||||
// dimension 2 and higher
|
||||
strategy::envelope::detail::envelope_one_segment
|
||||
<
|
||||
2, dimension<Point>::value
|
||||
>::apply(point1, point2, box);
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<segment_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_segment<CalculationType> type;
|
||||
};
|
||||
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<segment_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef strategy::envelope::spherical_segment<CalculationType> type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::envelope
|
||||
|
||||
}} //namepsace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_ENVELOPE_SEGMENT_HPP
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
|
||||
|
||||
// This file was modified by Oracle on 2015, 2016, 2017, 2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_EXPAND_BOX_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_BOX_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/box.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/expand.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope_box.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace expand
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct box_on_spheroid
|
||||
{
|
||||
template <typename BoxOut, typename BoxIn>
|
||||
static inline void apply(BoxOut& box_out, BoxIn const& box_in)
|
||||
{
|
||||
// normalize both boxes and convert box-in to be of type of box-out
|
||||
BoxOut mbrs[2];
|
||||
strategy::envelope::spherical_box::apply(box_in, mbrs[0]);
|
||||
strategy::envelope::spherical_box::apply(box_out, mbrs[1]);
|
||||
|
||||
// compute the envelope of the two boxes
|
||||
geometry::detail::envelope::envelope_range_of_boxes::apply(mbrs, box_out);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
struct spherical_box
|
||||
: detail::box_on_spheroid
|
||||
{};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_box type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_box type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<box_tag, geographic_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_box type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::expand
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_BOX_HPP
|
||||
@@ -0,0 +1,233 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
|
||||
|
||||
// This file was modified by Oracle on 2015-2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, 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.
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_EXPAND_POINT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_POINT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/util/is_inverse_spheroidal_coordinates.hpp>
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_coordinate_type.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/normalize.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/expand.hpp>
|
||||
#include <boost/geometry/strategies/cartesian/expand_point.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace expand
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// implementation for the spherical and geographic coordinate systems
|
||||
template <std::size_t DimensionCount, bool IsEquatorial>
|
||||
struct point_loop_on_spheroid
|
||||
{
|
||||
template <typename Box, typename Point>
|
||||
static inline void apply(Box& box, Point const& point)
|
||||
{
|
||||
typedef typename point_type<Box>::type box_point_type;
|
||||
typedef typename coordinate_type<Box>::type box_coordinate_type;
|
||||
typedef typename geometry::detail::cs_angular_units<Box>::type units_type;
|
||||
|
||||
typedef math::detail::constants_on_spheroid
|
||||
<
|
||||
box_coordinate_type,
|
||||
units_type
|
||||
> constants;
|
||||
|
||||
// normalize input point and input box
|
||||
Point p_normalized;
|
||||
strategy::normalize::spherical_point::apply(point, p_normalized);
|
||||
|
||||
// transform input point to be of the same type as the box point
|
||||
box_point_type box_point;
|
||||
geometry::detail::envelope::transform_units(p_normalized, box_point);
|
||||
|
||||
if (is_inverse_spheroidal_coordinates(box))
|
||||
{
|
||||
geometry::set_from_radian<min_corner, 0>(box, geometry::get_as_radian<0>(p_normalized));
|
||||
geometry::set_from_radian<min_corner, 1>(box, geometry::get_as_radian<1>(p_normalized));
|
||||
geometry::set_from_radian<max_corner, 0>(box, geometry::get_as_radian<0>(p_normalized));
|
||||
geometry::set_from_radian<max_corner, 1>(box, geometry::get_as_radian<1>(p_normalized));
|
||||
|
||||
} else {
|
||||
|
||||
strategy::normalize::spherical_box::apply(box, box);
|
||||
|
||||
box_coordinate_type p_lon = geometry::get<0>(box_point);
|
||||
box_coordinate_type p_lat = geometry::get<1>(box_point);
|
||||
|
||||
typename coordinate_type<Box>::type
|
||||
b_lon_min = geometry::get<min_corner, 0>(box),
|
||||
b_lat_min = geometry::get<min_corner, 1>(box),
|
||||
b_lon_max = geometry::get<max_corner, 0>(box),
|
||||
b_lat_max = geometry::get<max_corner, 1>(box);
|
||||
|
||||
if (math::is_latitude_pole<units_type, IsEquatorial>(p_lat))
|
||||
{
|
||||
// the point of expansion is the either the north or the
|
||||
// south pole; the only important coordinate here is the
|
||||
// pole's latitude, as the longitude can be anything;
|
||||
// we, thus, take into account the point's latitude only and return
|
||||
geometry::set<min_corner, 1>(box, (std::min)(p_lat, b_lat_min));
|
||||
geometry::set<max_corner, 1>(box, (std::max)(p_lat, b_lat_max));
|
||||
return;
|
||||
}
|
||||
|
||||
if (math::equals(b_lat_min, b_lat_max)
|
||||
&& math::is_latitude_pole<units_type, IsEquatorial>(b_lat_min))
|
||||
{
|
||||
// the box degenerates to either the north or the south pole;
|
||||
// the only important coordinate here is the pole's latitude,
|
||||
// as the longitude can be anything;
|
||||
// we thus take into account the box's latitude only and return
|
||||
geometry::set<min_corner, 0>(box, p_lon);
|
||||
geometry::set<min_corner, 1>(box, (std::min)(p_lat, b_lat_min));
|
||||
geometry::set<max_corner, 0>(box, p_lon);
|
||||
geometry::set<max_corner, 1>(box, (std::max)(p_lat, b_lat_max));
|
||||
return;
|
||||
}
|
||||
|
||||
// update latitudes
|
||||
b_lat_min = (std::min)(b_lat_min, p_lat);
|
||||
b_lat_max = (std::max)(b_lat_max, p_lat);
|
||||
|
||||
// update longitudes
|
||||
if (math::smaller(p_lon, b_lon_min))
|
||||
{
|
||||
box_coordinate_type p_lon_shifted = p_lon + constants::period();
|
||||
|
||||
if (math::larger(p_lon_shifted, b_lon_max))
|
||||
{
|
||||
// here we could check using: ! math::larger(.., ..)
|
||||
if (math::smaller(b_lon_min - p_lon, p_lon_shifted - b_lon_max))
|
||||
{
|
||||
b_lon_min = p_lon;
|
||||
}
|
||||
else
|
||||
{
|
||||
b_lon_max = p_lon_shifted;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (math::larger(p_lon, b_lon_max))
|
||||
{
|
||||
// in this case, and since p_lon is normalized in the range
|
||||
// (-180, 180], we must have that b_lon_max <= 180
|
||||
if (b_lon_min < 0
|
||||
&& math::larger(p_lon - b_lon_max,
|
||||
constants::period() - p_lon + b_lon_min))
|
||||
{
|
||||
b_lon_min = p_lon;
|
||||
b_lon_max += constants::period();
|
||||
}
|
||||
else
|
||||
{
|
||||
b_lon_max = p_lon;
|
||||
}
|
||||
}
|
||||
|
||||
geometry::set<min_corner, 0>(box, b_lon_min);
|
||||
geometry::set<min_corner, 1>(box, b_lat_min);
|
||||
geometry::set<max_corner, 0>(box, b_lon_max);
|
||||
geometry::set<max_corner, 1>(box, b_lat_max);
|
||||
}
|
||||
|
||||
point_loop
|
||||
<
|
||||
2, DimensionCount
|
||||
>::apply(box, point);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
struct spherical_point
|
||||
{
|
||||
template <typename Box, typename Point>
|
||||
static void apply(Box & box, Point const& point)
|
||||
{
|
||||
expand::detail::point_loop_on_spheroid
|
||||
<
|
||||
dimension<Point>::value,
|
||||
! boost::is_same<typename cs_tag<Point>::type, spherical_polar_tag>::value
|
||||
>::apply(box, point);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_point type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_point type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<point_tag, geographic_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_point type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::expand
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_POINT_HPP
|
||||
@@ -0,0 +1,118 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France.
|
||||
|
||||
// This file was modified by Oracle on 2015, 2016, 2017, 2018.
|
||||
// Modifications copyright (c) 2015-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
|
||||
// Distributed under 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_STRATEGIES_SPHERICAL_EXPAND_SEGMENT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_SEGMENT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/util/select_coordinate_type.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/envelope/box.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/range_of_boxes.hpp>
|
||||
#include <boost/geometry/algorithms/detail/envelope/segment.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/expand.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope_segment.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace expand
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct segment_on_spheroid
|
||||
{
|
||||
template <typename Box, typename Segment, typename EnvelopeStrategy>
|
||||
static inline void apply(Box& box, Segment const& segment, EnvelopeStrategy const& strategy)
|
||||
{
|
||||
Box mbrs[2];
|
||||
|
||||
// compute the envelope of the segment
|
||||
typename point_type<Segment>::type p[2];
|
||||
geometry::detail::assign_point_from_index<0>(segment, p[0]);
|
||||
geometry::detail::assign_point_from_index<1>(segment, p[1]);
|
||||
geometry::detail::envelope::envelope_segment
|
||||
<
|
||||
dimension<Segment>::value
|
||||
>::apply(p[0], p[1], mbrs[0], strategy);
|
||||
|
||||
// normalize the box
|
||||
strategy::envelope::spherical_box::apply(box, mbrs[1]);
|
||||
|
||||
// compute the envelope of the two boxes
|
||||
geometry::detail::envelope::envelope_range_of_boxes::apply(mbrs, box);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical_segment
|
||||
{
|
||||
public:
|
||||
template <typename Box, typename Segment>
|
||||
static inline void apply(Box& box, Segment const& segment)
|
||||
{
|
||||
detail::segment_on_spheroid::apply(box, segment,
|
||||
strategy::envelope::spherical_segment<CalculationType>());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<segment_tag, spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_segment<CalculationType> type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<segment_tag, spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_segment<CalculationType> type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::expand
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_EXPAND_SEGMENT_HPP
|
||||
@@ -0,0 +1,81 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Copyright (c) 2016-2018 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fisikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_GET_RADIUS_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_GET_RADIUS_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/radius.hpp>
|
||||
#include <boost/geometry/core/tag.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/util/select_most_precise.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace strategy_detail
|
||||
{
|
||||
|
||||
template
|
||||
<
|
||||
typename RadiusTypeOrSphere,
|
||||
typename Tag = typename tag<RadiusTypeOrSphere>::type
|
||||
>
|
||||
struct get_radius
|
||||
{
|
||||
typedef typename geometry::radius_type<RadiusTypeOrSphere>::type type;
|
||||
static type apply(RadiusTypeOrSphere const& sphere)
|
||||
{
|
||||
return geometry::get_radius<0>(sphere);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename RadiusTypeOrSphere>
|
||||
struct get_radius<RadiusTypeOrSphere, void>
|
||||
{
|
||||
typedef RadiusTypeOrSphere type;
|
||||
static type apply(RadiusTypeOrSphere const& radius)
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
};
|
||||
|
||||
// For backward compatibility
|
||||
template <typename Point>
|
||||
struct get_radius<Point, point_tag>
|
||||
{
|
||||
typedef typename select_most_precise
|
||||
<
|
||||
typename coordinate_type<Point>::type,
|
||||
double
|
||||
>::type type;
|
||||
|
||||
template <typename RadiusOrSphere>
|
||||
static typename get_radius<RadiusOrSphere>::type
|
||||
apply(RadiusOrSphere const& radius_or_sphere)
|
||||
{
|
||||
return get_radius<RadiusOrSphere>::apply(radius_or_sphere);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace strategy_detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_GET_RADIUS_HPP
|
||||
1089
macx64/include/boost/geometry/strategies/spherical/intersection.hpp
Normal file
1089
macx64/include/boost/geometry/strategies/spherical/intersection.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,123 @@
|
||||
// Boost.Geometry
|
||||
|
||||
// Copyright (c) 2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
|
||||
// Licensed under the Boost Software License version 1.0.
|
||||
// http://www.boost.org/users/license.html
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_LINE_INTERPOLATE_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_LINE_INTERPOLATE_HPP
|
||||
|
||||
#include <boost/geometry/core/assert.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/formulas/interpolate_point_spherical.hpp>
|
||||
#include <boost/geometry/srs/spheroid.hpp>
|
||||
#include <boost/geometry/strategies/line_interpolate.hpp>
|
||||
#include <boost/geometry/strategies/spherical/distance_haversine.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace line_interpolate
|
||||
{
|
||||
|
||||
|
||||
/*!
|
||||
\brief Interpolate point on a spherical segment.
|
||||
\ingroup strategies
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\tparam DistanceStrategy The underlying point-point distance strategy
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
\* [link geometry.reference.algorithms.line_interpolate.line_interpolate_4_with_strategy line_interpolate (with strategy)]
|
||||
}
|
||||
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename CalculationType = void,
|
||||
typename DistanceStrategy = distance::haversine<double, CalculationType>
|
||||
>
|
||||
class spherical
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename DistanceStrategy::radius_type radius_type;
|
||||
|
||||
inline spherical()
|
||||
{}
|
||||
|
||||
explicit inline spherical(typename DistanceStrategy::radius_type const& r)
|
||||
: m_strategy(r)
|
||||
{}
|
||||
|
||||
inline spherical(DistanceStrategy const& s)
|
||||
: m_strategy(s)
|
||||
{}
|
||||
|
||||
// point-point strategy getters
|
||||
struct distance_pp_strategy
|
||||
{
|
||||
typedef DistanceStrategy type;
|
||||
};
|
||||
|
||||
inline typename distance_pp_strategy::type get_distance_pp_strategy() const
|
||||
{
|
||||
return m_strategy;
|
||||
}
|
||||
|
||||
template <typename Point, typename Fraction, typename Distance>
|
||||
inline void apply(Point const& p0,
|
||||
Point const& p1,
|
||||
Fraction const& fraction,
|
||||
Point & p,
|
||||
Distance const&) const
|
||||
{
|
||||
typedef typename select_calculation_type_alt
|
||||
<
|
||||
CalculationType,
|
||||
Point
|
||||
>::type calc_t;
|
||||
|
||||
formula::interpolate_point_spherical<calc_t> formula;
|
||||
|
||||
calc_t angle01;
|
||||
formula.compute_angle(p0, p1, angle01);
|
||||
formula.compute_axis(p0, angle01);
|
||||
|
||||
calc_t a = angle01 * fraction;
|
||||
formula.compute_point(a, p);
|
||||
}
|
||||
private :
|
||||
DistanceStrategy m_strategy;
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <>
|
||||
struct default_strategy<spherical_equatorial_tag>
|
||||
{
|
||||
typedef strategy::line_interpolate::spherical<> type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}} // namespace strategy::line_interpolate
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_LINE_INTERPOLATE_HPP
|
||||
@@ -0,0 +1,172 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland
|
||||
|
||||
// This file was modified by Oracle on 2013, 2014, 2015, 2017, 2018.
|
||||
// Modifications copyright (c) 2013-2018, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
||||
// 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.
|
||||
|
||||
// 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_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/normalize.hpp>
|
||||
#include <boost/geometry/algorithms/dispatch/disjoint.hpp>
|
||||
#include <boost/geometry/algorithms/transform.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/helper_geometry.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/point_in_point.hpp>
|
||||
#include <boost/geometry/strategies/covered_by.hpp>
|
||||
#include <boost/geometry/strategies/strategy_transform.hpp>
|
||||
#include <boost/geometry/strategies/within.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_most_precise.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace within
|
||||
{
|
||||
|
||||
class point_point_on_spheroid
|
||||
{
|
||||
private:
|
||||
template <typename Point1, typename Point2, bool SameUnits>
|
||||
struct are_same_points
|
||||
{
|
||||
static inline bool apply(Point1 const& point1, Point2 const& point2)
|
||||
{
|
||||
typedef typename helper_geometry<Point1>::type helper_point_type1;
|
||||
typedef typename helper_geometry<Point2>::type helper_point_type2;
|
||||
|
||||
helper_point_type1 point1_normalized;
|
||||
strategy::normalize::spherical_point::apply(point1, point1_normalized);
|
||||
helper_point_type2 point2_normalized;
|
||||
strategy::normalize::spherical_point::apply(point2, point2_normalized);
|
||||
|
||||
return point_point_generic
|
||||
<
|
||||
0, dimension<Point1>::value
|
||||
>::apply(point1_normalized, point2_normalized);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Point1, typename Point2>
|
||||
struct are_same_points<Point1, Point2, false> // points have different units
|
||||
{
|
||||
static inline bool apply(Point1 const& point1, Point2 const& point2)
|
||||
{
|
||||
typedef typename geometry::select_most_precise
|
||||
<
|
||||
typename fp_coordinate_type<Point1>::type,
|
||||
typename fp_coordinate_type<Point2>::type
|
||||
>::type calculation_type;
|
||||
|
||||
typename helper_geometry
|
||||
<
|
||||
Point1, calculation_type, radian
|
||||
>::type helper_point1, helper_point2;
|
||||
|
||||
Point1 point1_normalized = return_normalized<Point1>(point1);
|
||||
Point2 point2_normalized = return_normalized<Point2>(point2);
|
||||
|
||||
geometry::transform(point1_normalized, helper_point1);
|
||||
geometry::transform(point2_normalized, helper_point2);
|
||||
|
||||
return point_point_generic
|
||||
<
|
||||
0, dimension<Point1>::value
|
||||
>::apply(helper_point1, helper_point2);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename Point1, typename Point2>
|
||||
static inline bool apply(Point1 const& point1, Point2 const& point2)
|
||||
{
|
||||
return are_same_points
|
||||
<
|
||||
Point1,
|
||||
Point2,
|
||||
boost::is_same
|
||||
<
|
||||
typename detail::cs_angular_units<Point1>::type,
|
||||
typename detail::cs_angular_units<Point2>::type
|
||||
>::value
|
||||
>::apply(point1, point2);
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace detail::within
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
namespace strategy { namespace within
|
||||
{
|
||||
|
||||
struct spherical_point_point
|
||||
: geometry::detail::within::point_point_on_spheroid
|
||||
{};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
|
||||
struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef strategy::within::spherical_point_point type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace strategy::within
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace strategy { namespace covered_by { namespace services
|
||||
{
|
||||
|
||||
template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
|
||||
struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef strategy::within::spherical_point_point type;
|
||||
};
|
||||
|
||||
}}} // namespace strategy::covered_by::services
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
|
||||
@@ -0,0 +1,596 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2013-2017 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// This file was modified by Oracle on 2013, 2014, 2016, 2017, 2018.
|
||||
// Modifications copyright (c) 2013-2018 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Adam Wulkiewicz, 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.
|
||||
|
||||
// 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_STRATEGY_SPHERICAL_POINT_IN_POLY_WINDING_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POLY_WINDING_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/coordinate_system.hpp>
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
#include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/point_in_box.hpp>
|
||||
#include <boost/geometry/strategies/covered_by.hpp>
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
#include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/ssf.hpp>
|
||||
#include <boost/geometry/strategies/within.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace within
|
||||
{
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename PointOfSegment = Point,
|
||||
typename SideStrategy = typename strategy::side::services::default_strategy
|
||||
<
|
||||
typename cs_tag<Point>::type
|
||||
>::type,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical_winding_base
|
||||
{
|
||||
typedef typename select_calculation_type
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
CalculationType
|
||||
>::type calculation_type;
|
||||
|
||||
typedef typename geometry::detail::cs_angular_units<Point>::type units_t;
|
||||
typedef math::detail::constants_on_spheroid<calculation_type, units_t> constants;
|
||||
|
||||
/*! subclass to keep state */
|
||||
class counter
|
||||
{
|
||||
int m_count;
|
||||
//int m_count_n;
|
||||
int m_count_s;
|
||||
int m_raw_count;
|
||||
int m_raw_count_anti;
|
||||
bool m_touches;
|
||||
|
||||
inline int code() const
|
||||
{
|
||||
if (m_touches)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_raw_count != 0 && m_raw_count_anti != 0)
|
||||
{
|
||||
if (m_raw_count > 0) // right, wrap around south pole
|
||||
{
|
||||
return (m_count + m_count_s) == 0 ? -1 : 1;
|
||||
}
|
||||
else // left, wrap around north pole
|
||||
{
|
||||
//return (m_count + m_count_n) == 0 ? -1 : 1;
|
||||
// m_count_n is 0
|
||||
return m_count == 0 ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return m_count == 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
public :
|
||||
friend class spherical_winding_base;
|
||||
|
||||
inline counter()
|
||||
: m_count(0)
|
||||
//, m_count_n(0)
|
||||
, m_count_s(0)
|
||||
, m_raw_count(0)
|
||||
, m_raw_count_anti(0)
|
||||
, m_touches(false)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
struct count_info
|
||||
{
|
||||
explicit count_info(int c = 0, bool ia = false)
|
||||
: count(c)
|
||||
, is_anti(ia)
|
||||
{}
|
||||
|
||||
int count;
|
||||
bool is_anti;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename SideStrategy::envelope_strategy_type envelope_strategy_type;
|
||||
|
||||
inline envelope_strategy_type get_envelope_strategy() const
|
||||
{
|
||||
return m_side_strategy.get_envelope_strategy();
|
||||
}
|
||||
|
||||
typedef typename SideStrategy::disjoint_strategy_type disjoint_strategy_type;
|
||||
|
||||
inline disjoint_strategy_type get_disjoint_strategy() const
|
||||
{
|
||||
return m_side_strategy.get_disjoint_strategy();
|
||||
}
|
||||
|
||||
typedef typename SideStrategy::equals_point_point_strategy_type equals_point_point_strategy_type;
|
||||
inline equals_point_point_strategy_type get_equals_point_point_strategy() const
|
||||
{
|
||||
return m_side_strategy.get_equals_point_point_strategy();
|
||||
}
|
||||
|
||||
typedef disjoint::spherical_box_box disjoint_box_box_strategy_type;
|
||||
static inline disjoint_box_box_strategy_type get_disjoint_box_box_strategy()
|
||||
{
|
||||
return disjoint_box_box_strategy_type();
|
||||
}
|
||||
|
||||
typedef covered_by::spherical_point_box disjoint_point_box_strategy_type;
|
||||
|
||||
spherical_winding_base()
|
||||
{}
|
||||
|
||||
template <typename Model>
|
||||
explicit spherical_winding_base(Model const& model)
|
||||
: m_side_strategy(model)
|
||||
{}
|
||||
|
||||
// Typedefs and static methods to fulfill the concept
|
||||
typedef Point point_type;
|
||||
typedef PointOfSegment segment_point_type;
|
||||
typedef counter state_type;
|
||||
|
||||
inline bool apply(Point const& point,
|
||||
PointOfSegment const& s1, PointOfSegment const& s2,
|
||||
counter& state) const
|
||||
{
|
||||
bool eq1 = false;
|
||||
bool eq2 = false;
|
||||
bool s_antipodal = false;
|
||||
|
||||
count_info ci = check_segment(point, s1, s2, state, eq1, eq2, s_antipodal);
|
||||
if (ci.count != 0)
|
||||
{
|
||||
if (! ci.is_anti)
|
||||
{
|
||||
int side = 0;
|
||||
if (ci.count == 1 || ci.count == -1)
|
||||
{
|
||||
side = side_equal(point, eq1 ? s1 : s2, ci);
|
||||
}
|
||||
else // count == 2 || count == -2
|
||||
{
|
||||
if (! s_antipodal)
|
||||
{
|
||||
// 1 left, -1 right
|
||||
side = m_side_strategy.apply(s1, s2, point);
|
||||
}
|
||||
else
|
||||
{
|
||||
calculation_type const pi = constants::half_period();
|
||||
calculation_type const s1_lat = get<1>(s1);
|
||||
calculation_type const s2_lat = get<1>(s2);
|
||||
|
||||
side = math::sign(ci.count)
|
||||
* (pi - s1_lat - s2_lat <= pi // segment goes through north pole
|
||||
? -1 // going right all points will be on right side
|
||||
: 1); // going right all points will be on left side
|
||||
}
|
||||
}
|
||||
|
||||
if (side == 0)
|
||||
{
|
||||
// Point is lying on segment
|
||||
state.m_touches = true;
|
||||
state.m_count = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Side is NEG for right, POS for left.
|
||||
// The count is -2 for left, 2 for right (or -1/1)
|
||||
// Side positive thus means RIGHT and LEFTSIDE or LEFT and RIGHTSIDE
|
||||
// See accompagnying figure (TODO)
|
||||
if (side * ci.count > 0)
|
||||
{
|
||||
state.m_count += ci.count;
|
||||
}
|
||||
|
||||
state.m_raw_count += ci.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Count negated because the segment is on the other side of the globe
|
||||
// so it is reversed to match this side of the globe
|
||||
|
||||
// Assuming geometry wraps around north pole, for segments on the other side of the globe
|
||||
// the point will always be RIGHT+RIGHTSIDE or LEFT+LEFTSIDE, so side*-count always < 0
|
||||
//state.m_count_n -= 0;
|
||||
|
||||
// Assuming geometry wraps around south pole, for segments on the other side of the globe
|
||||
// the point will always be RIGHT+LEFTSIDE or LEFT+RIGHTSIDE, so side*-count always > 0
|
||||
state.m_count_s -= ci.count;
|
||||
|
||||
state.m_raw_count_anti -= ci.count;
|
||||
}
|
||||
}
|
||||
return ! state.m_touches;
|
||||
}
|
||||
|
||||
static inline int result(counter const& state)
|
||||
{
|
||||
return state.code();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static inline count_info check_segment(Point const& point,
|
||||
PointOfSegment const& seg1,
|
||||
PointOfSegment const& seg2,
|
||||
counter& state,
|
||||
bool& eq1, bool& eq2, bool& s_antipodal)
|
||||
{
|
||||
if (check_touch(point, seg1, seg2, state, eq1, eq2, s_antipodal))
|
||||
{
|
||||
return count_info(0, false);
|
||||
}
|
||||
|
||||
return calculate_count(point, seg1, seg2, eq1, eq2, s_antipodal);
|
||||
}
|
||||
|
||||
static inline int check_touch(Point const& point,
|
||||
PointOfSegment const& seg1,
|
||||
PointOfSegment const& seg2,
|
||||
counter& state,
|
||||
bool& eq1,
|
||||
bool& eq2,
|
||||
bool& s_antipodal)
|
||||
{
|
||||
calculation_type const c0 = 0;
|
||||
calculation_type const c2 = 2;
|
||||
calculation_type const pi = constants::half_period();
|
||||
calculation_type const half_pi = pi / c2;
|
||||
|
||||
calculation_type const p_lon = get<0>(point);
|
||||
calculation_type const s1_lon = get<0>(seg1);
|
||||
calculation_type const s2_lon = get<0>(seg2);
|
||||
calculation_type const p_lat = get<1>(point);
|
||||
calculation_type const s1_lat = get<1>(seg1);
|
||||
calculation_type const s2_lat = get<1>(seg2);
|
||||
|
||||
// NOTE: lat in {-90, 90} and arbitrary lon
|
||||
// it doesn't matter what lon it is if it's a pole
|
||||
// so e.g. if one of the segment endpoints is a pole
|
||||
// then only the other lon matters
|
||||
|
||||
bool eq1_strict = longitudes_equal(s1_lon, p_lon);
|
||||
bool eq2_strict = longitudes_equal(s2_lon, p_lon);
|
||||
bool eq1_anti = false;
|
||||
bool eq2_anti = false;
|
||||
|
||||
calculation_type const anti_p_lon = p_lon + (p_lon <= c0 ? pi : -pi);
|
||||
|
||||
eq1 = eq1_strict // lon strictly equal to s1
|
||||
|| (eq1_anti = longitudes_equal(s1_lon, anti_p_lon)) // anti-lon strictly equal to s1
|
||||
|| math::equals(math::abs(s1_lat), half_pi); // s1 is pole
|
||||
eq2 = eq2_strict // lon strictly equal to s2
|
||||
|| (eq2_anti = longitudes_equal(s2_lon, anti_p_lon)) // anti-lon strictly equal to s2
|
||||
|| math::equals(math::abs(s2_lat), half_pi); // s2 is pole
|
||||
|
||||
// segment overlapping pole
|
||||
calculation_type const s_lon_diff = math::longitude_distance_signed<units_t>(s1_lon, s2_lon);
|
||||
s_antipodal = math::equals(s_lon_diff, pi);
|
||||
if (s_antipodal)
|
||||
{
|
||||
eq1 = eq2 = eq1 || eq2;
|
||||
|
||||
// segment overlapping pole and point is pole
|
||||
if (math::equals(math::abs(p_lat), half_pi))
|
||||
{
|
||||
eq1 = eq2 = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Both equal p -> segment vertical
|
||||
// The only thing which has to be done is check if point is ON segment
|
||||
if (eq1 && eq2)
|
||||
{
|
||||
// segment endpoints on the same sides of the globe
|
||||
if (! s_antipodal)
|
||||
{
|
||||
// p's lat between segment endpoints' lats
|
||||
if ( (s1_lat <= p_lat && s2_lat >= p_lat) || (s2_lat <= p_lat && s1_lat >= p_lat) )
|
||||
{
|
||||
if (!eq1_anti || !eq2_anti)
|
||||
{
|
||||
state.m_touches = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// going through north or south pole?
|
||||
if (pi - s1_lat - s2_lat <= pi)
|
||||
{
|
||||
if ( (eq1_strict && s1_lat <= p_lat) || (eq2_strict && s2_lat <= p_lat) // north
|
||||
|| math::equals(p_lat, half_pi) ) // point on north pole
|
||||
{
|
||||
state.m_touches = true;
|
||||
}
|
||||
else if (! eq1_strict && ! eq2_strict && math::equals(p_lat, -half_pi) ) // point on south pole
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // south pole
|
||||
{
|
||||
if ( (eq1_strict && s1_lat >= p_lat) || (eq2_strict && s2_lat >= p_lat) // south
|
||||
|| math::equals(p_lat, -half_pi) ) // point on south pole
|
||||
{
|
||||
state.m_touches = true;
|
||||
}
|
||||
else if (! eq1_strict && ! eq2_strict && math::equals(p_lat, half_pi) ) // point on north pole
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called if point is not aligned with a vertical segment
|
||||
static inline count_info calculate_count(Point const& point,
|
||||
PointOfSegment const& seg1,
|
||||
PointOfSegment const& seg2,
|
||||
bool eq1, bool eq2, bool s_antipodal)
|
||||
{
|
||||
// If both segment endpoints were poles below checks wouldn't be enough
|
||||
// but this means that either both are the same or that they are N/S poles
|
||||
// and therefore the segment is not valid.
|
||||
// If needed (eq1 && eq2 ? 0) could be returned
|
||||
|
||||
calculation_type const c0 = 0;
|
||||
calculation_type const pi = constants::half_period();
|
||||
|
||||
calculation_type const p = get<0>(point);
|
||||
calculation_type const s1 = get<0>(seg1);
|
||||
calculation_type const s2 = get<0>(seg2);
|
||||
|
||||
calculation_type const s1_p = math::longitude_distance_signed<units_t>(s1, p);
|
||||
|
||||
if (s_antipodal)
|
||||
{
|
||||
return count_info(s1_p < c0 ? -2 : 2, false); // choose W/E
|
||||
}
|
||||
|
||||
calculation_type const s1_s2 = math::longitude_distance_signed<units_t>(s1, s2);
|
||||
|
||||
if (eq1 || eq2) // Point on level s1 or s2
|
||||
{
|
||||
return count_info(s1_s2 < c0 ? -1 : 1, // choose W/E
|
||||
longitudes_equal(p + pi, (eq1 ? s1 : s2)));
|
||||
}
|
||||
|
||||
// Point between s1 and s2
|
||||
if ( math::sign(s1_p) == math::sign(s1_s2)
|
||||
&& math::abs(s1_p) < math::abs(s1_s2) )
|
||||
{
|
||||
return count_info(s1_s2 < c0 ? -2 : 2, false); // choose W/E
|
||||
}
|
||||
|
||||
calculation_type const s1_p_anti = math::longitude_distance_signed<units_t>(s1, p + pi);
|
||||
|
||||
// Anti-Point between s1 and s2
|
||||
if ( math::sign(s1_p_anti) == math::sign(s1_s2)
|
||||
&& math::abs(s1_p_anti) < math::abs(s1_s2) )
|
||||
{
|
||||
return count_info(s1_s2 < c0 ? -2 : 2, true); // choose W/E
|
||||
}
|
||||
|
||||
return count_info(0, false);
|
||||
}
|
||||
|
||||
|
||||
// Fix for https://svn.boost.org/trac/boost/ticket/9628
|
||||
// For floating point coordinates, the <D> coordinate of a point is compared
|
||||
// with the segment's points using some EPS. If the coordinates are "equal"
|
||||
// the sides are calculated. Therefore we can treat a segment as a long areal
|
||||
// geometry having some width. There is a small ~triangular area somewhere
|
||||
// between the segment's effective area and a segment's line used in sides
|
||||
// calculation where the segment is on the one side of the line but on the
|
||||
// other side of a segment (due to the width).
|
||||
// Below picture assuming D = 1, if D = 0 horiz<->vert, E<->N, RIGHT<->UP.
|
||||
// For the s1 of a segment going NE the real side is RIGHT but the point may
|
||||
// be detected as LEFT, like this:
|
||||
// RIGHT
|
||||
// ___----->
|
||||
// ^ O Pt __ __
|
||||
// EPS __ __
|
||||
// v__ __ BUT DETECTED AS LEFT OF THIS LINE
|
||||
// _____7
|
||||
// _____/
|
||||
// _____/
|
||||
// In the code below actually D = 0, so segments are nearly-vertical
|
||||
// Called when the point is on the same level as one of the segment's points
|
||||
// but the point is not aligned with a vertical segment
|
||||
inline int side_equal(Point const& point,
|
||||
PointOfSegment const& se,
|
||||
count_info const& ci) const
|
||||
{
|
||||
typedef typename coordinate_type<PointOfSegment>::type scoord_t;
|
||||
typedef typename geometry::detail::cs_angular_units<PointOfSegment>::type units_t;
|
||||
|
||||
if (math::equals(get<1>(point), get<1>(se)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a horizontal segment intersecting the original segment's endpoint
|
||||
// equal to the point, with the derived direction (E/W).
|
||||
PointOfSegment ss1, ss2;
|
||||
set<1>(ss1, get<1>(se));
|
||||
set<0>(ss1, get<0>(se));
|
||||
set<1>(ss2, get<1>(se));
|
||||
scoord_t ss20 = get<0>(se);
|
||||
if (ci.count > 0)
|
||||
{
|
||||
ss20 += small_angle();
|
||||
}
|
||||
else
|
||||
{
|
||||
ss20 -= small_angle();
|
||||
}
|
||||
math::normalize_longitude<units_t>(ss20);
|
||||
set<0>(ss2, ss20);
|
||||
|
||||
// Check the side using this vertical segment
|
||||
return m_side_strategy.apply(ss1, ss2, point);
|
||||
}
|
||||
|
||||
// 1 deg or pi/180 rad
|
||||
static inline calculation_type small_angle()
|
||||
{
|
||||
return constants::half_period() / calculation_type(180);
|
||||
};
|
||||
|
||||
static inline bool longitudes_equal(calculation_type const& lon1, calculation_type const& lon2)
|
||||
{
|
||||
return math::equals(
|
||||
math::longitude_distance_signed<units_t>(lon1, lon2),
|
||||
calculation_type(0));
|
||||
}
|
||||
|
||||
SideStrategy m_side_strategy;
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
/*!
|
||||
\brief Within detection using winding rule in spherical coordinate system.
|
||||
\ingroup strategies
|
||||
\tparam Point \tparam_point
|
||||
\tparam PointOfSegment \tparam_segment_point
|
||||
\tparam CalculationType \tparam_calculation
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.within.within_3_with_strategy within (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename PointOfSegment = Point,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class spherical_winding
|
||||
: public within::detail::spherical_winding_base
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
side::spherical_side_formula<CalculationType>,
|
||||
CalculationType
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
|
||||
struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, polygonal_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef within::detail::spherical_winding_base
|
||||
<
|
||||
typename geometry::point_type<PointLike>::type,
|
||||
typename geometry::point_type<Geometry>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
|
||||
struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, linear_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef within::detail::spherical_winding_base
|
||||
<
|
||||
typename geometry::point_type<PointLike>::type,
|
||||
typename geometry::point_type<Geometry>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace strategy::within
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace strategy { namespace covered_by { namespace services
|
||||
{
|
||||
|
||||
template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
|
||||
struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, polygonal_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef within::detail::spherical_winding_base
|
||||
<
|
||||
typename geometry::point_type<PointLike>::type,
|
||||
typename geometry::point_type<Geometry>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
|
||||
struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, linear_tag, spherical_tag, spherical_tag>
|
||||
{
|
||||
typedef within::detail::spherical_winding_base
|
||||
<
|
||||
typename geometry::point_type<PointLike>::type,
|
||||
typename geometry::point_type<Geometry>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
}}} // namespace strategy::covered_by::services
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POLY_WINDING_HPP
|
||||
@@ -0,0 +1,89 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2014-2017.
|
||||
// Modifications copyright (c) 2014-2017, Oracle and/or its affiliates.
|
||||
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
|
||||
#include <boost/geometry/formulas/spherical.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
//#include <boost/geometry/strategies/concepts/side_concept.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace strategy { namespace side
|
||||
{
|
||||
|
||||
/*!
|
||||
\brief Check at which side of a Great Circle segment a point lies
|
||||
left of segment (> 0), right of segment (< 0), on segment (0)
|
||||
\ingroup strategies
|
||||
\tparam CalculationType \tparam_calculation
|
||||
*/
|
||||
template <typename CalculationType = void>
|
||||
class side_by_cross_track
|
||||
{
|
||||
|
||||
public :
|
||||
template <typename P1, typename P2, typename P>
|
||||
static inline int apply(P1 const& p1, P2 const& p2, P const& p)
|
||||
{
|
||||
typedef typename promote_floating_point
|
||||
<
|
||||
typename select_calculation_type_alt
|
||||
<
|
||||
CalculationType,
|
||||
P1, P2, P
|
||||
>::type
|
||||
>::type calc_t;
|
||||
|
||||
calc_t d1 = 0.001; // m_strategy.apply(sp1, p);
|
||||
|
||||
calc_t lon1 = geometry::get_as_radian<0>(p1);
|
||||
calc_t lat1 = geometry::get_as_radian<1>(p1);
|
||||
calc_t lon2 = geometry::get_as_radian<0>(p2);
|
||||
calc_t lat2 = geometry::get_as_radian<1>(p2);
|
||||
calc_t lon = geometry::get_as_radian<0>(p);
|
||||
calc_t lat = geometry::get_as_radian<1>(p);
|
||||
|
||||
calc_t crs_AD = geometry::formula::spherical_azimuth<calc_t, false>
|
||||
(lon1, lat1, lon, lat).azimuth;
|
||||
|
||||
calc_t crs_AB = geometry::formula::spherical_azimuth<calc_t, false>
|
||||
(lon1, lat1, lon2, lat2).azimuth;
|
||||
|
||||
calc_t XTD = asin(sin(d1) * sin(crs_AD - crs_AB));
|
||||
|
||||
return math::equals(XTD, 0) ? 0 : XTD < 0 ? 1 : -1;
|
||||
}
|
||||
};
|
||||
|
||||
}} // namespace strategy::side
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
|
||||
164
macx64/include/boost/geometry/strategies/spherical/ssf.hpp
Normal file
164
macx64/include/boost/geometry/strategies/spherical/ssf.hpp
Normal file
@@ -0,0 +1,164 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2016, 2018.
|
||||
// Modifications copyright (c) 2016-2018, 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_STRATEGIES_SPHERICAL_SSF_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/radian_access.hpp>
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/promote_floating_point.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
#include <boost/geometry/strategies/spherical/disjoint_segment_box.hpp>
|
||||
#include <boost/geometry/strategies/spherical/envelope.hpp>
|
||||
//#include <boost/geometry/strategies/concepts/side_concept.hpp>
|
||||
#include <boost/geometry/strategies/spherical/point_in_point.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
|
||||
namespace strategy { namespace side
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
int spherical_side_formula(T const& lambda1, T const& delta1,
|
||||
T const& lambda2, T const& delta2,
|
||||
T const& lambda, T const& delta)
|
||||
{
|
||||
// Create temporary points (vectors) on unit a sphere
|
||||
T const cos_delta1 = cos(delta1);
|
||||
T const c1x = cos_delta1 * cos(lambda1);
|
||||
T const c1y = cos_delta1 * sin(lambda1);
|
||||
T const c1z = sin(delta1);
|
||||
|
||||
T const cos_delta2 = cos(delta2);
|
||||
T const c2x = cos_delta2 * cos(lambda2);
|
||||
T const c2y = cos_delta2 * sin(lambda2);
|
||||
T const c2z = sin(delta2);
|
||||
|
||||
// (Third point is converted directly)
|
||||
T const cos_delta = cos(delta);
|
||||
|
||||
// Apply the "Spherical Side Formula" as presented on my blog
|
||||
T const dist
|
||||
= (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
|
||||
+ (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
|
||||
+ (c1x * c2y - c1y * c2x) * sin(delta);
|
||||
|
||||
T zero = T();
|
||||
return math::equals(dist, zero) ? 0
|
||||
: dist > zero ? 1
|
||||
: -1; // dist < zero
|
||||
}
|
||||
|
||||
}
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
/*!
|
||||
\brief Check at which side of a Great Circle segment a point lies
|
||||
left of segment (> 0), right of segment (< 0), on segment (0)
|
||||
\ingroup strategies
|
||||
\tparam CalculationType \tparam_calculation
|
||||
*/
|
||||
template <typename CalculationType = void>
|
||||
class spherical_side_formula
|
||||
{
|
||||
|
||||
public :
|
||||
typedef strategy::envelope::spherical<CalculationType> envelope_strategy_type;
|
||||
|
||||
static inline envelope_strategy_type get_envelope_strategy()
|
||||
{
|
||||
return envelope_strategy_type();
|
||||
}
|
||||
|
||||
typedef strategy::disjoint::segment_box_spherical disjoint_strategy_type;
|
||||
|
||||
static inline disjoint_strategy_type get_disjoint_strategy()
|
||||
{
|
||||
return disjoint_strategy_type();
|
||||
}
|
||||
|
||||
typedef strategy::within::spherical_point_point equals_point_point_strategy_type;
|
||||
static inline equals_point_point_strategy_type get_equals_point_point_strategy()
|
||||
{
|
||||
return equals_point_point_strategy_type();
|
||||
}
|
||||
|
||||
template <typename P1, typename P2, typename P>
|
||||
static inline int apply(P1 const& p1, P2 const& p2, P const& p)
|
||||
{
|
||||
typedef typename promote_floating_point
|
||||
<
|
||||
typename select_calculation_type_alt
|
||||
<
|
||||
CalculationType,
|
||||
P1, P2, P
|
||||
>::type
|
||||
>::type calculation_type;
|
||||
|
||||
calculation_type const lambda1 = get_as_radian<0>(p1);
|
||||
calculation_type const delta1 = get_as_radian<1>(p1);
|
||||
calculation_type const lambda2 = get_as_radian<0>(p2);
|
||||
calculation_type const delta2 = get_as_radian<1>(p2);
|
||||
calculation_type const lambda = get_as_radian<0>(p);
|
||||
calculation_type const delta = get_as_radian<1>(p);
|
||||
|
||||
return detail::spherical_side_formula(lambda1, delta1,
|
||||
lambda2, delta2,
|
||||
lambda, delta);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace services
|
||||
{
|
||||
|
||||
/*template <typename CalculationType>
|
||||
struct default_strategy<spherical_polar_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_side_formula<CalculationType> type;
|
||||
};*/
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<spherical_equatorial_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_side_formula<CalculationType> type;
|
||||
};
|
||||
|
||||
template <typename CalculationType>
|
||||
struct default_strategy<geographic_tag, CalculationType>
|
||||
{
|
||||
typedef spherical_side_formula<CalculationType> type;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
}} // namespace strategy::side
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
|
||||
Reference in New Issue
Block a user