summaryrefslogtreecommitdiff
path: root/boost/geometry/strategies
diff options
context:
space:
mode:
Diffstat (limited to 'boost/geometry/strategies')
-rw-r--r--boost/geometry/strategies/agnostic/point_in_point.hpp20
-rw-r--r--boost/geometry/strategies/agnostic/point_in_poly_winding.hpp94
-rw-r--r--boost/geometry/strategies/cartesian/disjoint_segment_box.hpp9
-rw-r--r--boost/geometry/strategies/cartesian/envelope_segment.hpp1
-rw-r--r--boost/geometry/strategies/cartesian/intersection.hpp9
-rw-r--r--boost/geometry/strategies/cartesian/side_by_triangle.hpp16
-rw-r--r--boost/geometry/strategies/disjoint.hpp5
-rw-r--r--boost/geometry/strategies/geographic/area.hpp23
-rw-r--r--boost/geometry/strategies/geographic/azimuth.hpp18
-rw-r--r--boost/geometry/strategies/geographic/disjoint_segment_box.hpp130
-rw-r--r--boost/geometry/strategies/geographic/intersection.hpp148
-rw-r--r--boost/geometry/strategies/geographic/side.hpp26
-rw-r--r--boost/geometry/strategies/spherical/azimuth.hpp18
-rw-r--r--boost/geometry/strategies/spherical/disjoint_segment_box.hpp105
-rw-r--r--boost/geometry/strategies/spherical/intersection.hpp191
-rw-r--r--boost/geometry/strategies/spherical/ssf.hpp16
-rw-r--r--boost/geometry/strategies/strategies.hpp2
17 files changed, 706 insertions, 125 deletions
diff --git a/boost/geometry/strategies/agnostic/point_in_point.hpp b/boost/geometry/strategies/agnostic/point_in_point.hpp
index c6e2b63623..1a9274149a 100644
--- a/boost/geometry/strategies/agnostic/point_in_point.hpp
+++ b/boost/geometry/strategies/agnostic/point_in_point.hpp
@@ -42,10 +42,14 @@ struct point_in_point
namespace services
{
-template <typename Point, typename PointLike, typename Tag2, typename AnyCS1, typename AnyCS2>
-struct default_strategy<Point, PointLike, point_tag, Tag2, pointlike_tag, pointlike_tag, AnyCS1, AnyCS2>
+template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2, typename AnyCS1, typename AnyCS2>
+struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, AnyCS1, AnyCS2>
{
- typedef strategy::within::point_in_point<Point, typename point_type<PointLike>::type> type;
+ typedef strategy::within::point_in_point
+ <
+ typename point_type<PointLike1>::type,
+ typename point_type<PointLike2>::type
+ > type;
};
@@ -61,10 +65,14 @@ struct default_strategy<Point, PointLike, point_tag, Tag2, pointlike_tag, pointl
namespace strategy { namespace covered_by { namespace services
{
-template <typename Point, typename PointLike, typename Tag2, typename AnyCS1, typename AnyCS2>
-struct default_strategy<Point, PointLike, point_tag, Tag2, pointlike_tag, pointlike_tag, AnyCS1, AnyCS2>
+template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2, typename AnyCS1, typename AnyCS2>
+struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, AnyCS1, AnyCS2>
{
- typedef strategy::within::point_in_point<Point, typename point_type<PointLike>::type> type;
+ typedef strategy::within::point_in_point
+ <
+ typename point_type<PointLike1>::type,
+ typename point_type<PointLike2>::type
+ > type;
};
}}} // namespace strategy::covered_by::services
diff --git a/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp b/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp
index 3e7e258788..0a797ac0f0 100644
--- a/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp
+++ b/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp
@@ -388,6 +388,20 @@ class winding
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();
+ }
+
winding()
{}
@@ -459,28 +473,44 @@ private:
namespace services
{
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, polygonal_tag, cartesian_tag, cartesian_tag>
+template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
+struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, polygonal_tag, cartesian_tag, cartesian_tag>
{
- typedef winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, polygonal_tag, spherical_tag, spherical_tag>
+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 winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, linear_tag, cartesian_tag, cartesian_tag>
+template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
+struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, linear_tag, cartesian_tag, cartesian_tag>
{
- typedef winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, linear_tag, spherical_tag, spherical_tag>
+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 winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
} // namespace services
@@ -495,28 +525,44 @@ struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, linea
namespace strategy { namespace covered_by { namespace services
{
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, polygonal_tag, cartesian_tag, cartesian_tag>
+template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
+struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, polygonal_tag, cartesian_tag, cartesian_tag>
{
- typedef strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef within::winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, polygonal_tag, spherical_tag, spherical_tag>
+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 strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef within::winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, linear_tag, cartesian_tag, cartesian_tag>
+template <typename PointLike, typename Geometry, typename AnyTag1, typename AnyTag2>
+struct default_strategy<PointLike, Geometry, AnyTag1, AnyTag2, pointlike_tag, linear_tag, cartesian_tag, cartesian_tag>
{
- typedef strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef within::winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
-template <typename Point, typename Geometry, typename AnyTag>
-struct default_strategy<Point, Geometry, point_tag, AnyTag, pointlike_tag, linear_tag, spherical_tag, spherical_tag>
+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 strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
+ typedef within::winding
+ <
+ typename geometry::point_type<PointLike>::type,
+ typename geometry::point_type<Geometry>::type
+ > type;
};
}}} // namespace strategy::covered_by::services
diff --git a/boost/geometry/strategies/cartesian/disjoint_segment_box.hpp b/boost/geometry/strategies/cartesian/disjoint_segment_box.hpp
index 4270803322..4da4bc4503 100644
--- a/boost/geometry/strategies/cartesian/disjoint_segment_box.hpp
+++ b/boost/geometry/strategies/cartesian/disjoint_segment_box.hpp
@@ -8,8 +8,9 @@
// This file was modified by Oracle on 2013-2017.
// Modifications copyright (c) 2013-2017, Oracle and/or its affiliates.
-// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
+// 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
@@ -293,16 +294,14 @@ struct segment_box
namespace services
{
-// Currently used in all coordinate systems
-
template <typename Linear, typename Box, typename LinearTag>
-struct default_strategy<Linear, Box, LinearTag, box_tag, 1, 2>
+struct default_strategy<Linear, Box, LinearTag, box_tag, 1, 2, cartesian_tag, cartesian_tag>
{
typedef disjoint::segment_box type;
};
template <typename Box, typename Linear, typename LinearTag>
-struct default_strategy<Box, Linear, box_tag, LinearTag, 2, 1>
+struct default_strategy<Box, Linear, box_tag, LinearTag, 2, 1, cartesian_tag, cartesian_tag>
{
typedef disjoint::segment_box type;
};
diff --git a/boost/geometry/strategies/cartesian/envelope_segment.hpp b/boost/geometry/strategies/cartesian/envelope_segment.hpp
index 0ddbf12a41..a591996b84 100644
--- a/boost/geometry/strategies/cartesian/envelope_segment.hpp
+++ b/boost/geometry/strategies/cartesian/envelope_segment.hpp
@@ -14,6 +14,7 @@
#include <boost/geometry/algorithms/detail/envelope/segment.hpp>
#include <boost/geometry/core/tags.hpp>
+#include <boost/geometry/strategies/envelope.hpp>
#include <boost/geometry/util/select_calculation_type.hpp>
diff --git a/boost/geometry/strategies/cartesian/intersection.hpp b/boost/geometry/strategies/cartesian/intersection.hpp
index 20b6b93367..50e903885b 100644
--- a/boost/geometry/strategies/cartesian/intersection.hpp
+++ b/boost/geometry/strategies/cartesian/intersection.hpp
@@ -36,6 +36,7 @@
#include <boost/geometry/strategies/agnostic/point_in_poly_winding.hpp>
#include <boost/geometry/strategies/cartesian/area_surveyor.hpp>
#include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
+#include <boost/geometry/strategies/cartesian/envelope_segment.hpp>
#include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
#include <boost/geometry/strategies/covered_by.hpp>
#include <boost/geometry/strategies/intersection.hpp>
@@ -133,6 +134,14 @@ struct cartesian_segments
return strategy_type();
}
+ typedef envelope::cartesian_segment<CalculationType>
+ envelope_strategy_type;
+
+ static inline envelope_strategy_type get_envelope_strategy()
+ {
+ return envelope_strategy_type();
+ }
+
template <typename CoordinateType, typename SegmentRatio>
struct segment_intersection_info
{
diff --git a/boost/geometry/strategies/cartesian/side_by_triangle.hpp b/boost/geometry/strategies/cartesian/side_by_triangle.hpp
index ba7749ba76..4d1d97520f 100644
--- a/boost/geometry/strategies/cartesian/side_by_triangle.hpp
+++ b/boost/geometry/strategies/cartesian/side_by_triangle.hpp
@@ -26,6 +26,9 @@
#include <boost/geometry/arithmetic/determinant.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/util/select_coordinate_type.hpp>
+
+#include <boost/geometry/strategies/cartesian/disjoint_segment_box.hpp>
+#include <boost/geometry/strategies/cartesian/envelope_segment.hpp>
#include <boost/geometry/strategies/side.hpp>
#include <boost/geometry/algorithms/detail/relate/less.hpp>
@@ -66,6 +69,19 @@ class side_by_triangle
};
public :
+ typedef strategy::envelope::cartesian_segment<CalculationType> envelope_strategy_type;
+
+ static inline envelope_strategy_type get_envelope_strategy()
+ {
+ return envelope_strategy_type();
+ }
+
+ typedef strategy::disjoint::segment_box disjoint_strategy_type;
+
+ static inline disjoint_strategy_type get_disjoint_strategy()
+ {
+ return disjoint_strategy_type();
+ }
// Template member function, because it is not always trivial
// or convenient to explicitly mention the typenames in the
diff --git a/boost/geometry/strategies/disjoint.hpp b/boost/geometry/strategies/disjoint.hpp
index f844cd86ad..23d2cede49 100644
--- a/boost/geometry/strategies/disjoint.hpp
+++ b/boost/geometry/strategies/disjoint.hpp
@@ -1,6 +1,7 @@
// Boost.Geometry
// Copyright (c) 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,
@@ -37,7 +38,9 @@ template
typename Tag1 = typename geometry::tag<Geometry1>::type,
typename Tag2 = typename geometry::tag<Geometry2>::type,
int TopDim1 = geometry::topological_dimension<Geometry1>::value,
- int TopDim2 = geometry::topological_dimension<Geometry2>::value
+ int TopDim2 = geometry::topological_dimension<Geometry2>::value,
+ typename CsTag1 = typename cs_tag<Geometry1>::type,
+ typename CsTag2 = typename cs_tag<Geometry2>::type
>
struct default_strategy
: relate::services::default_strategy
diff --git a/boost/geometry/strategies/geographic/area.hpp b/boost/geometry/strategies/geographic/area.hpp
index e1d3b09b5a..44dc2e6945 100644
--- a/boost/geometry/strategies/geographic/area.hpp
+++ b/boost/geometry/strategies/geographic/area.hpp
@@ -83,7 +83,7 @@ protected :
CT const m_e2; // squared eccentricity
CT const m_ep2; // squared second eccentricity
CT const m_ep; // second eccentricity
- CT const m_c2; // authalic radius
+ CT const m_c2; // squared authalic radius
inline spheroid_constants(Spheroid const& spheroid)
: m_spheroid(spheroid)
@@ -92,12 +92,27 @@ protected :
* (CT(2.0) - CT(formula::flattening<CT>(spheroid))))
, m_ep2(m_e2 / (CT(1.0) - m_e2))
, m_ep(math::sqrt(m_ep2))
- , m_c2((m_a2 / CT(2.0)) +
- ((math::sqr(get_radius<2>(spheroid)) * boost::math::atanh(math::sqrt(m_e2)))
- / (CT(2.0) * math::sqrt(m_e2))))
+ , m_c2(authalic_radius(spheroid, m_a2, m_e2))
{}
};
+ static inline CT authalic_radius(Spheroid const& sph, CT const& a2, CT const& e2)
+ {
+ CT const c0 = 0;
+
+ if (math::equals(e2, c0))
+ {
+ return a2;
+ }
+
+ CT const sqrt_e2 = math::sqrt(e2);
+ CT const c2 = 2;
+
+ return (a2 / c2) +
+ ((math::sqr(get_radius<2>(sph)) * boost::math::atanh(sqrt_e2))
+ / (c2 * sqrt_e2));
+ }
+
struct area_sums
{
CT m_excess_sum;
diff --git a/boost/geometry/strategies/geographic/azimuth.hpp b/boost/geometry/strategies/geographic/azimuth.hpp
index 47f59d1033..79c49750fb 100644
--- a/boost/geometry/strategies/geographic/azimuth.hpp
+++ b/boost/geometry/strategies/geographic/azimuth.hpp
@@ -71,6 +71,24 @@ public :
a2 = i_res.reverse_azimuth;
}
+ 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
+ {
+ typedef typename boost::mpl::if_
+ <
+ boost::is_void<CalculationType>, T, CalculationType
+ >::type calc_t;
+
+ typedef typename FormulaPolicy::template inverse<calc_t, false, true, false, false, false> inverse_type;
+ typedef typename inverse_type::result_type inverse_result;
+ inverse_result i_res = inverse_type::apply(calc_t(lon1_rad), calc_t(lat1_rad),
+ calc_t(lon2_rad), calc_t(lat2_rad),
+ m_spheroid);
+ a1 = i_res.azimuth;
+ }
+
private :
Spheroid m_spheroid;
};
diff --git a/boost/geometry/strategies/geographic/disjoint_segment_box.hpp b/boost/geometry/strategies/geographic/disjoint_segment_box.hpp
new file mode 100644
index 0000000000..afc9d66775
--- /dev/null
+++ b/boost/geometry/strategies/geographic/disjoint_segment_box.hpp
@@ -0,0 +1,130 @@
+// Boost.Geometry
+
+// Copyright (c) 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_GEOGRAPHIC_DISJOINT_SEGMENT_BOX_HPP
+#define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_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>
+
+#include <boost/geometry/strategies/disjoint.hpp>
+#include <boost/geometry/strategies/geographic/azimuth.hpp>
+#include <boost/geometry/strategies/geographic/parameters.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.
+template
+<
+ typename FormulaPolicy = strategy::andoyer,
+ typename Spheroid = srs::spheroid<double>,
+ typename CalculationType = void
+>
+struct segment_box_geographic
+{
+public:
+ typedef Spheroid model_type;
+
+ inline segment_box_geographic()
+ : m_spheroid()
+ {}
+
+ explicit inline segment_box_geographic(Spheroid const& spheroid)
+ : m_spheroid(spheroid)
+ {}
+
+ 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>
+ inline bool apply(Segment const& segment, Box const& box) const
+ {
+ geometry::strategy::azimuth::geographic
+ <
+ FormulaPolicy,
+ Spheroid,
+ CalculationType
+ > azimuth_geographic(m_spheroid);
+
+ return geometry::detail::disjoint::disjoint_segment_box_sphere_or_spheroid
+ <geographic_tag>::apply(segment, box, azimuth_geographic);
+ }
+
+private:
+ Spheroid m_spheroid;
+};
+
+
+#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
+
+
+namespace services
+{
+
+template <typename Linear, typename Box, typename LinearTag>
+struct default_strategy<Linear, Box, LinearTag, box_tag, 1, 2,
+ geographic_tag, geographic_tag>
+{
+ typedef segment_box_geographic<> type;
+};
+
+template <typename Box, typename Linear, typename LinearTag>
+struct default_strategy<Box, Linear, box_tag, LinearTag, 2, 1,
+ geographic_tag, geographic_tag>
+{
+ typedef segment_box_geographic<> type;
+};
+
+
+} // namespace services
+
+
+#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
+
+
+}}}} // namespace boost::geometry::strategy::disjoint
+
+
+#endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISJOINT_SEGMENT_BOX_HPP
diff --git a/boost/geometry/strategies/geographic/intersection.hpp b/boost/geometry/strategies/geographic/intersection.hpp
index 1708c274c0..59a40f281d 100644
--- a/boost/geometry/strategies/geographic/intersection.hpp
+++ b/boost/geometry/strategies/geographic/intersection.hpp
@@ -34,6 +34,7 @@
#include <boost/geometry/strategies/geographic/area.hpp>
#include <boost/geometry/strategies/geographic/distance.hpp>
+#include <boost/geometry/strategies/geographic/envelope_segment.hpp>
#include <boost/geometry/strategies/geographic/parameters.hpp>
#include <boost/geometry/strategies/geographic/side.hpp>
#include <boost/geometry/strategies/intersection.hpp>
@@ -135,6 +136,14 @@ struct geographic_segments
return strategy_type(m_spheroid);
}
+ typedef envelope::geographic_segment<FormulaPolicy, Spheroid, CalculationType>
+ envelope_strategy_type;
+
+ inline envelope_strategy_type get_envelope_strategy() const
+ {
+ return envelope_strategy_type(m_spheroid);
+ }
+
enum intersection_point_flag { ipi_inters = 0, ipi_at_a1, ipi_at_a2, ipi_at_b1, ipi_at_b2 };
template <typename CoordinateType, typename SegmentRatio>
@@ -280,6 +289,8 @@ private:
typedef typename select_calculation_type
<Segment1, Segment2, CalculationType>::type calc_t;
+ static const calc_t c0 = 0;
+
// normalized spheroid
srs::spheroid<calc_t> spheroid = normalized_spheroid<calc_t>(m_spheroid);
@@ -316,31 +327,80 @@ private:
// TODO: no need to call inverse formula if we know that the points are equal
// distance can be set to 0 in this case and azimuth may be not calculated
- bool const is_equal_a1_b1 = equals_point_point(a1, b1);
- bool const is_equal_a2_b1 = equals_point_point(a2, b1);
+ bool is_equal_a1_b1 = equals_point_point(a1, b1);
+ bool is_equal_a2_b1 = equals_point_point(a2, b1);
+ bool degen_neq_coords = false;
- inverse_result res_b1_b2 = inverse_dist_azi::apply(b1_lon, b1_lat, b2_lon, b2_lat, spheroid);
- inverse_result res_b1_a1 = inverse_dist_azi::apply(b1_lon, b1_lat, a1_lon, a1_lat, spheroid);
- inverse_result res_b1_a2 = inverse_dist_azi::apply(b1_lon, b1_lat, a2_lon, a2_lat, spheroid);
- sides.set<0>(is_equal_a1_b1 ? 0 : formula::azimuth_side_value(res_b1_a1.azimuth, res_b1_b2.azimuth),
- is_equal_a2_b1 ? 0 : formula::azimuth_side_value(res_b1_a2.azimuth, res_b1_b2.azimuth));
- if (sides.same<0>())
+ inverse_result res_b1_b2, res_b1_a1, res_b1_a2;
+ if (! b_is_point)
{
- // Both points are at the same side of other segment, we can leave
- return Policy::disjoint();
+ res_b1_b2 = inverse_dist_azi::apply(b1_lon, b1_lat, b2_lon, b2_lat, spheroid);
+ if (math::equals(res_b1_b2.distance, c0))
+ {
+ b_is_point = true;
+ degen_neq_coords = true;
+ }
+ else
+ {
+ res_b1_a1 = inverse_dist_azi::apply(b1_lon, b1_lat, a1_lon, a1_lat, spheroid);
+ if (math::equals(res_b1_a1.distance, c0))
+ {
+ is_equal_a1_b1 = true;
+ }
+ res_b1_a2 = inverse_dist_azi::apply(b1_lon, b1_lat, a2_lon, a2_lat, spheroid);
+ if (math::equals(res_b1_a2.distance, c0))
+ {
+ is_equal_a2_b1 = true;
+ }
+ sides.set<0>(is_equal_a1_b1 ? 0 : formula::azimuth_side_value(res_b1_a1.azimuth, res_b1_b2.azimuth),
+ is_equal_a2_b1 ? 0 : formula::azimuth_side_value(res_b1_a2.azimuth, res_b1_b2.azimuth));
+ if (sides.same<0>())
+ {
+ // Both points are at the same side of other segment, we can leave
+ return Policy::disjoint();
+ }
+ }
}
- bool const is_equal_a1_b2 = equals_point_point(a1, b2);
+ bool is_equal_a1_b2 = equals_point_point(a1, b2);
- inverse_result res_a1_a2 = inverse_dist_azi::apply(a1_lon, a1_lat, a2_lon, a2_lat, spheroid);
- inverse_result res_a1_b1 = inverse_dist_azi::apply(a1_lon, a1_lat, b1_lon, b1_lat, spheroid);
- inverse_result res_a1_b2 = inverse_dist_azi::apply(a1_lon, a1_lat, b2_lon, b2_lat, spheroid);
- sides.set<1>(is_equal_a1_b1 ? 0 : formula::azimuth_side_value(res_a1_b1.azimuth, res_a1_a2.azimuth),
- is_equal_a1_b2 ? 0 : formula::azimuth_side_value(res_a1_b2.azimuth, res_a1_a2.azimuth));
- if (sides.same<1>())
+ inverse_result res_a1_a2, res_a1_b1, res_a1_b2;
+ if (! a_is_point)
{
- // Both points are at the same side of other segment, we can leave
- return Policy::disjoint();
+ res_a1_a2 = inverse_dist_azi::apply(a1_lon, a1_lat, a2_lon, a2_lat, spheroid);
+ if (math::equals(res_a1_a2.distance, c0))
+ {
+ a_is_point = true;
+ degen_neq_coords = true;
+ }
+ else
+ {
+ res_a1_b1 = inverse_dist_azi::apply(a1_lon, a1_lat, b1_lon, b1_lat, spheroid);
+ if (math::equals(res_a1_b1.distance, c0))
+ {
+ is_equal_a1_b1 = true;
+ }
+ res_a1_b2 = inverse_dist_azi::apply(a1_lon, a1_lat, b2_lon, b2_lat, spheroid);
+ if (math::equals(res_a1_b2.distance, c0))
+ {
+ is_equal_a1_b2 = true;
+ }
+ sides.set<1>(is_equal_a1_b1 ? 0 : formula::azimuth_side_value(res_a1_b1.azimuth, res_a1_a2.azimuth),
+ is_equal_a1_b2 ? 0 : formula::azimuth_side_value(res_a1_b2.azimuth, res_a1_a2.azimuth));
+ if (sides.same<1>())
+ {
+ // Both points are at the same side of other segment, we can leave
+ return Policy::disjoint();
+ }
+ }
+ }
+
+ if(a_is_point && b_is_point)
+ {
+ return is_equal_a1_b2
+ ? Policy::degenerate(a, true)
+ : Policy::disjoint()
+ ;
}
// NOTE: at this point the segments may still be disjoint
@@ -370,11 +430,11 @@ private:
{
if (a_is_point)
{
- return collinear_one_degenerated<Policy, calc_t>(a, true, b1, b2, a1, a2, res_b1_b2, res_b1_a1, is_b_reversed);
+ return collinear_one_degenerated<Policy, calc_t>(a, true, b1, b2, a1, a2, res_b1_b2, res_b1_a1, res_b1_a2, is_b_reversed, degen_neq_coords);
}
else if (b_is_point)
{
- return collinear_one_degenerated<Policy, calc_t>(b, false, a1, a2, b1, b2, res_a1_a2, res_a1_b1, is_a_reversed);
+ return collinear_one_degenerated<Policy, calc_t>(b, false, a1, a2, b1, b2, res_a1_a2, res_a1_b1, res_a1_b2, is_a_reversed, degen_neq_coords);
}
else
{
@@ -383,16 +443,16 @@ private:
// use shorter segment
if (res_a1_a2.distance <= res_b1_b2.distance)
{
- calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_b1, dist_a1_a2, dist_a1_b1);
- calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_b2, dist_a1_a2, dist_a1_b2);
+ calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_b1, res_a1_b2, dist_a1_a2, dist_a1_b1);
+ calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_b2, res_a1_b1, dist_a1_a2, dist_a1_b2);
dist_b1_b2 = dist_a1_b2 - dist_a1_b1;
dist_b1_a1 = -dist_a1_b1;
dist_b1_a2 = dist_a1_a2 - dist_a1_b1;
}
else
{
- calculate_collinear_data(b1, b2, a1, a2, res_b1_b2, res_b1_a1, dist_b1_b2, dist_b1_a1);
- calculate_collinear_data(b1, b2, a1, a2, res_b1_b2, res_b1_a2, dist_b1_b2, dist_b1_a2);
+ calculate_collinear_data(b1, b2, a1, a2, res_b1_b2, res_b1_a1, res_b1_a2, dist_b1_b2, dist_b1_a1);
+ calculate_collinear_data(b1, b2, a1, a2, res_b1_b2, res_b1_a2, res_b1_a1, dist_b1_b2, dist_b1_a2);
dist_a1_a2 = dist_b1_a2 - dist_b1_a1;
dist_a1_b1 = -dist_b1_a1;
dist_a1_b2 = dist_b1_b2 - dist_b1_a1;
@@ -540,11 +600,13 @@ private:
Point1 const& a1, Point1 const& a2,
Point2 const& b1, Point2 const& b2,
ResultInverse const& res_a1_a2,
- ResultInverse const& res_a1_bi,
- bool is_other_reversed)
+ ResultInverse const& res_a1_b1,
+ ResultInverse const& res_a1_b2,
+ bool is_other_reversed,
+ bool degen_neq_coords)
{
CalcT dist_1_2, dist_1_o;
- if (! calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_bi, dist_1_2, dist_1_o))
+ if (! calculate_collinear_data(a1, a2, b1, b2, res_a1_a2, res_a1_b1, res_a1_b2, dist_1_2, dist_1_o, degen_neq_coords))
{
return Policy::disjoint();
}
@@ -565,13 +627,16 @@ private:
static inline bool calculate_collinear_data(Point1 const& a1, Point1 const& a2, // in
Point2 const& b1, Point2 const& b2, // in
ResultInverse const& res_a1_a2, // in
- ResultInverse const& res_a1_bi, // in
- CalcT& dist_a1_a2, CalcT& dist_a1_bi) // out
+ ResultInverse const& res_a1_b1, // in
+ ResultInverse const& res_a1_b2, // in
+ CalcT& dist_a1_a2, // out
+ CalcT& dist_a1_bi, // out
+ bool degen_neq_coords = false) // in
{
dist_a1_a2 = res_a1_a2.distance;
- dist_a1_bi = res_a1_bi.distance;
- if (! same_direction(res_a1_bi.azimuth, res_a1_a2.azimuth))
+ dist_a1_bi = res_a1_b1.distance;
+ if (! same_direction(res_a1_b1.azimuth, res_a1_a2.azimuth))
{
dist_a1_bi = -dist_a1_bi;
}
@@ -589,6 +654,22 @@ private:
return true;
}
+ // check the other endpoint of a very short segment near the pole
+ if (degen_neq_coords)
+ {
+ static CalcT const c0 = 0;
+ if (math::equals(res_a1_b2.distance, c0))
+ {
+ dist_a1_bi = 0;
+ return true;
+ }
+ else if (math::equals(dist_a1_a2 - res_a1_b2.distance, c0))
+ {
+ dist_a1_bi = dist_a1_a2;
+ return true;
+ }
+ }
+
// or i1 is on b
return segment_ratio<CalcT>(dist_a1_bi, dist_a1_a2).on_segment();
}
@@ -816,8 +897,9 @@ private:
static inline bool is_endpoint_equal(CalcT const& dist,
P1 const& ai, P2 const& b1, P2 const& b2)
{
+ static CalcT const c0 = 0;
using geometry::detail::equals::equals_point_point;
- return is_near(dist) && (equals_point_point(ai, b1) || equals_point_point(ai, b2));
+ return is_near(dist) && (equals_point_point(ai, b1) || equals_point_point(ai, b2) || math::equals(dist, c0));
}
template <typename CalcT>
diff --git a/boost/geometry/strategies/geographic/side.hpp b/boost/geometry/strategies/geographic/side.hpp
index 0d40e4da20..9276965a97 100644
--- a/boost/geometry/strategies/geographic/side.hpp
+++ b/boost/geometry/strategies/geographic/side.hpp
@@ -26,6 +26,8 @@
#include <boost/geometry/util/promote_floating_point.hpp>
#include <boost/geometry/util/select_calculation_type.hpp>
+#include <boost/geometry/strategies/geographic/disjoint_segment_box.hpp>
+#include <boost/geometry/strategies/geographic/envelope_segment.hpp>
#include <boost/geometry/strategies/geographic/parameters.hpp>
#include <boost/geometry/strategies/side.hpp>
//#include <boost/geometry/strategies/concepts/side_concept.hpp>
@@ -56,6 +58,30 @@ template
class geographic
{
public:
+ typedef strategy::envelope::geographic_segment
+ <
+ FormulaPolicy,
+ Spheroid,
+ CalculationType
+ > envelope_strategy_type;
+
+ inline envelope_strategy_type get_envelope_strategy() const
+ {
+ return envelope_strategy_type(m_model);
+ }
+
+ typedef strategy::disjoint::segment_box_geographic
+ <
+ FormulaPolicy,
+ Spheroid,
+ CalculationType
+ > disjoint_strategy_type;
+
+ inline disjoint_strategy_type get_disjoint_strategy() const
+ {
+ return disjoint_strategy_type(m_model);
+ }
+
geographic()
{}
diff --git a/boost/geometry/strategies/spherical/azimuth.hpp b/boost/geometry/strategies/spherical/azimuth.hpp
index 3c208fe2e2..7a711c9814 100644
--- a/boost/geometry/strategies/spherical/azimuth.hpp
+++ b/boost/geometry/strategies/spherical/azimuth.hpp
@@ -55,6 +55,24 @@ public :
a2 = result.reverse_azimuth;
}
+ 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
+ {
+ 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, false>(
+ calc_t(lon1_rad), calc_t(lat1_rad),
+ calc_t(lon2_rad), calc_t(lat2_rad));
+
+ a1 = result.azimuth;
+ }
+
};
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
diff --git a/boost/geometry/strategies/spherical/disjoint_segment_box.hpp b/boost/geometry/strategies/spherical/disjoint_segment_box.hpp
new file mode 100644
index 0000000000..bda62a77fc
--- /dev/null
+++ b/boost/geometry/strategies/spherical/disjoint_segment_box.hpp
@@ -0,0 +1,105 @@
+// Boost.Geometry
+
+// Copyright (c) 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_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>
+
+#include <boost/geometry/strategies/spherical/azimuth.hpp>
+#include <boost/geometry/strategies/disjoint.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);
+ }
+};
+
+
+#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
+
diff --git a/boost/geometry/strategies/spherical/intersection.hpp b/boost/geometry/strategies/spherical/intersection.hpp
index 5d37583333..44b1cc62bf 100644
--- a/boost/geometry/strategies/spherical/intersection.hpp
+++ b/boost/geometry/strategies/spherical/intersection.hpp
@@ -41,6 +41,7 @@
#include <boost/geometry/strategies/side_info.hpp>
#include <boost/geometry/strategies/spherical/area.hpp>
#include <boost/geometry/strategies/spherical/distance_haversine.hpp>
+#include <boost/geometry/strategies/spherical/envelope_segment.hpp>
#include <boost/geometry/strategies/spherical/ssf.hpp>
#include <boost/geometry/strategies/within.hpp>
@@ -147,6 +148,14 @@ struct ecef_segments
return strategy_type();
}
+ typedef envelope::spherical_segment<CalculationType>
+ envelope_strategy_type;
+
+ static inline envelope_strategy_type get_envelope_strategy()
+ {
+ return envelope_strategy_type();
+ }
+
enum intersection_point_flag { ipi_inters = 0, ipi_at_a1, ipi_at_a2, ipi_at_b1, ipi_at_b2 };
// segment_intersection_info cannot outlive relate_ecef_segments
@@ -293,36 +302,64 @@ struct ecef_segments
vec3d_t const b1v = calc_policy.template to_cart3d<vec3d_t>(b1);
vec3d_t const b2v = calc_policy.template to_cart3d<vec3d_t>(b2);
+ bool degen_neq_coords = false;
side_info sides;
typename CalcPolicy::template plane<vec3d_t>
plane2 = calc_policy.get_plane(b1v, b2v);
- // not normalized normals, the same as in side strategy
- sides.set<0>(plane2.side_value(a1v), plane2.side_value(a2v));
- if (sides.same<0>())
+ calc_t dist_b1_b2 = 0;
+ if (! b_is_point)
{
- // Both points are at same side of other segment, we can leave
- return Policy::disjoint();
+ calculate_dist(b1v, b2v, plane2, dist_b1_b2);
+ if (math::equals(dist_b1_b2, c0))
+ {
+ degen_neq_coords = true;
+ b_is_point = true;
+ dist_b1_b2 = 0;
+ }
+ else
+ {
+ // not normalized normals, the same as in side strategy
+ sides.set<0>(plane2.side_value(a1v), plane2.side_value(a2v));
+ if (sides.same<0>())
+ {
+ // Both points are at same side of other segment, we can leave
+ return Policy::disjoint();
+ }
+ }
}
typename CalcPolicy::template plane<vec3d_t>
plane1 = calc_policy.get_plane(a1v, a2v);
- // not normalized normals, the same as in side strategy
- sides.set<1>(plane1.side_value(b1v), plane1.side_value(b2v));
- if (sides.same<1>())
+ calc_t dist_a1_a2 = 0;
+ if (! a_is_point)
{
- // Both points are at same side of other segment, we can leave
- return Policy::disjoint();
+ calculate_dist(a1v, a2v, plane1, dist_a1_a2);
+ if (math::equals(dist_a1_a2, c0))
+ {
+ degen_neq_coords = true;
+ a_is_point = true;
+ dist_a1_a2 = 0;
+ }
+ else
+ {
+ // not normalized normals, the same as in side strategy
+ sides.set<1>(plane1.side_value(b1v), plane1.side_value(b2v));
+ if (sides.same<1>())
+ {
+ // Both points are at same side of other segment, we can leave
+ return Policy::disjoint();
+ }
+ }
}
// NOTE: at this point the segments may still be disjoint
- calc_t len1, len2;
-
+ calc_t len1 = 0;
// point or opposite sides of a sphere/spheroid, assume point
- if (! detail::vec_normalize(plane1.normal, len1))
+ if (! a_is_point && ! detail::vec_normalize(plane1.normal, len1))
{
a_is_point = true;
if (sides.get<0, 0>() == 0 || sides.get<0, 1>() == 0)
@@ -331,7 +368,8 @@ struct ecef_segments
}
}
- if (! detail::vec_normalize(plane2.normal, len2))
+ calc_t len2 = 0;
+ if (! b_is_point && ! detail::vec_normalize(plane2.normal, len2))
{
b_is_point = true;
if (sides.get<1, 0>() == 0 || sides.get<1, 1>() == 0)
@@ -395,30 +433,32 @@ struct ecef_segments
{
if (a_is_point)
{
- return collinear_one_degenerated<Policy, calc_t>(a, true, b1, b2, a1, a2, b1v, b2v, plane2, a1v);
+ return collinear_one_degenerated<Policy, calc_t>(a, true, b1, b2, a1, a2, b1v, b2v,
+ plane2, a1v, a2v, dist_b1_b2, degen_neq_coords);
}
else if (b_is_point)
{
// b2 used to be consistent with (degenerated) checks above (is it needed?)
- return collinear_one_degenerated<Policy, calc_t>(b, false, a1, a2, b1, b2, a1v, a2v, plane1, b1v);
+ return collinear_one_degenerated<Policy, calc_t>(b, false, a1, a2, b1, b2, a1v, a2v,
+ plane1, b1v, b2v, dist_a1_a2, degen_neq_coords);
}
else
{
- calc_t dist_a1_a2, dist_a1_b1, dist_a1_b2;
- calc_t dist_b1_b2, dist_b1_a1, dist_b1_a2;
+ calc_t dist_a1_b1, dist_a1_b2;
+ calc_t dist_b1_a1, dist_b1_a2;
// use shorter segment
if (len1 <= len2)
{
- calculate_collinear_data(a1, a2, b1, b2, a1v, a2v, plane1, b1v, dist_a1_a2, dist_a1_b1);
- calculate_collinear_data(a1, a2, b1, b2, a1v, a2v, plane1, b2v, dist_a1_a2, dist_a1_b2);
+ calculate_collinear_data(a1, a2, b1, b2, a1v, a2v, plane1, b1v, b2v, dist_a1_a2, dist_a1_b1);
+ calculate_collinear_data(a1, a2, b1, b2, a1v, a2v, plane1, b2v, b1v, dist_a1_a2, dist_a1_b2);
dist_b1_b2 = dist_a1_b2 - dist_a1_b1;
dist_b1_a1 = -dist_a1_b1;
dist_b1_a2 = dist_a1_a2 - dist_a1_b1;
}
else
{
- calculate_collinear_data(b1, b2, a1, a2, b1v, b2v, plane2, a1v, dist_b1_b2, dist_b1_a1);
- calculate_collinear_data(b1, b2, a1, a2, b1v, b2v, plane2, a2v, dist_b1_b2, dist_b1_a2);
+ calculate_collinear_data(b1, b2, a1, a2, b1v, b2v, plane2, a1v, a2v, dist_b1_b2, dist_b1_a1);
+ calculate_collinear_data(b1, b2, a1, a2, b1v, b2v, plane2, a2v, a1v, dist_b1_b2, dist_b1_a2);
dist_a1_a2 = dist_b1_a2 - dist_b1_a1;
dist_a1_b1 = -dist_b1_a1;
dist_a1_b2 = dist_b1_b2 - dist_b1_a1;
@@ -478,10 +518,11 @@ struct ecef_segments
vec3d_t i1;
intersection_point_flag ip_flag;
- calc_t dist_a1_a2, dist_a1_i1, dist_b1_b2, dist_b1_i1;
+ calc_t dist_a1_i1, dist_b1_i1;
if (calculate_ip_data(a1, a2, b1, b2, a1v, a2v, b1v, b2v,
- plane1, plane2, calc_policy, sides,
- i1, dist_a1_a2, dist_a1_i1, dist_b1_b2, dist_b1_i1, ip_flag))
+ plane1, plane2, calc_policy,
+ sides, dist_a1_a2, dist_b1_b2,
+ i1, dist_a1_i1, dist_b1_i1, ip_flag))
{
// intersects
segment_intersection_info
@@ -511,12 +552,14 @@ private:
collinear_one_degenerated(Segment const& segment, bool degenerated_a,
Point1 const& a1, Point1 const& a2,
Point2 const& b1, Point2 const& b2,
- Vec3d const& v1, Vec3d const& v2,
+ Vec3d const& a1v, Vec3d const& a2v,
Plane const& plane,
- Vec3d const& vother)
+ Vec3d const& b1v, Vec3d const& b2v,
+ CalcT const& dist_1_2,
+ bool degen_neq_coords)
{
- CalcT dist_1_2, dist_1_o;
- return ! calculate_collinear_data(a1, a2, b1, b2, v1, v2, plane, vother, dist_1_2, dist_1_o)
+ CalcT dist_1_o;
+ return ! calculate_collinear_data(a1, a2, b1, b2, a1v, a2v, plane, b1v, b2v, dist_1_2, dist_1_o, degen_neq_coords)
? Policy::disjoint()
: Policy::one_degenerate(segment, segment_ratio<CalcT>(dist_1_o, dist_1_2), degenerated_a);
}
@@ -527,11 +570,14 @@ private:
Vec3d const& a1v, // in
Vec3d const& a2v, // in
Plane const& plane1, // in
- Vec3d const& b1v_or_b2v, // in
- CalcT& dist_a1_a2, CalcT& dist_a1_i1) // out
+ Vec3d const& b1v, // in
+ Vec3d const& b2v, // in
+ CalcT const& dist_a1_a2, // in
+ CalcT& dist_a1_i1, // out
+ bool degen_neq_coords = false) // in
{
// calculate dist_a1_a2 and dist_a1_i1
- calculate_dists(a1v, a2v, plane1, b1v_or_b2v, dist_a1_a2, dist_a1_i1);
+ calculate_dist(a1v, a2v, plane1, b1v, dist_a1_i1);
// if i1 is close to a1 and b1 or b2 is equal to a1
if (is_endpoint_equal(dist_a1_i1, a1, b1, b2))
@@ -546,6 +592,26 @@ private:
return true;
}
+ // check the other endpoint of a very short segment near the pole
+ if (degen_neq_coords)
+ {
+ static CalcT const c0 = 0;
+
+ CalcT dist_a1_i2 = 0;
+ calculate_dist(a1v, a2v, plane1, b2v, dist_a1_i2);
+
+ if (math::equals(dist_a1_i2, c0))
+ {
+ dist_a1_i1 = 0;
+ return true;
+ }
+ else if (math::equals(dist_a1_a2 - dist_a1_i2, c0))
+ {
+ dist_a1_i1 = dist_a1_a2;
+ return true;
+ }
+ }
+
// or i1 is on b
return segment_ratio<CalcT>(dist_a1_i1, dist_a1_a2).on_segment();
}
@@ -559,15 +625,17 @@ private:
Plane const& plane2, // in
CalcPolicy const& calc_policy, // in
side_info const& sides, // in
- Vec3d & ip, // out
- CalcT& dist_a1_a2, CalcT& dist_a1_ip, // out
- CalcT& dist_b1_b2, CalcT& dist_b1_ip, // out
- intersection_point_flag& ip_flag) // out
+ CalcT const& dist_a1_a2, // in
+ CalcT const& dist_b1_b2, // in
+ Vec3d & ip, // out
+ CalcT& dist_a1_ip, // out
+ CalcT& dist_b1_ip, // out
+ intersection_point_flag& ip_flag) // out
{
Vec3d ip1, ip2;
calc_policy.intersection_points(plane1, plane2, ip1, ip2);
- calculate_dists(a1v, a2v, plane1, ip1, dist_a1_a2, dist_a1_ip);
+ calculate_dist(a1v, a2v, plane1, ip1, dist_a1_ip);
ip = ip1;
// choose the opposite side of the globe if the distance is shorter
@@ -593,7 +661,7 @@ private:
return false;
}
- calculate_dists(b1v, b2v, plane2, ip, dist_b1_b2, dist_b1_ip);
+ calculate_dist(b1v, b2v, plane2, ip, dist_b1_ip);
bool is_on_b = false, is_near_b1 = false, is_near_b2 = false;
if (! is_potentially_crossing(dist_b1_b2, dist_b1_ip, is_on_b, is_near_b1, is_near_b2))
@@ -692,20 +760,26 @@ private:
}
template <typename Vec3d, typename Plane, typename CalcT>
- static inline void calculate_dists(Vec3d const& a1v, // in
- Vec3d const& a2v, // in
- Plane const& plane1, // in
- Vec3d const& i1, // in
- CalcT& dist_a1_a2, // out
- CalcT& dist_a1_i1) // out
+ static inline void calculate_dist(Vec3d const& a1v, // in
+ Vec3d const& a2v, // in
+ Plane const& plane1, // in
+ CalcT& dist_a1_a2) // out
{
- //CalcT const c0 = 0;
- CalcT const c1 = 1;
- CalcT const c2 = 2;
- CalcT const c4 = 4;
-
- CalcT cos_a1_a2 = plane1.cos_angle_between(a1v, a2v);
+ static CalcT const c1 = 1;
+ CalcT const cos_a1_a2 = plane1.cos_angle_between(a1v, a2v);
dist_a1_a2 = -cos_a1_a2 + c1; // [1, -1] -> [0, 2] representing [0, pi]
+ }
+
+ template <typename Vec3d, typename Plane, typename CalcT>
+ static inline void calculate_dist(Vec3d const& a1v, // in
+ Vec3d const& /*a2v*/, // in
+ Plane const& plane1, // in
+ Vec3d const& i1, // in
+ CalcT& dist_a1_i1) // out
+ {
+ static CalcT const c1 = 1;
+ static CalcT const c2 = 2;
+ static CalcT const c4 = 4;
bool is_forward = true;
CalcT cos_a1_i1 = plane1.cos_angle_between(a1v, i1, is_forward);
@@ -719,7 +793,19 @@ private:
dist_a1_i1 += c4; // += 2pi
}
}
-
+ /*
+ template <typename Vec3d, typename Plane, typename CalcT>
+ static inline void calculate_dists(Vec3d const& a1v, // in
+ Vec3d const& a2v, // in
+ Plane const& plane1, // in
+ Vec3d const& i1, // in
+ CalcT& dist_a1_a2, // out
+ CalcT& dist_a1_i1) // out
+ {
+ calculate_dist(a1v, a2v, plane1, dist_a1_a2);
+ calculate_dist(a1v, a2v, plane1, i1, dist_a1_i1);
+ }
+ */
// the dist of the ip on the other side of the sphere
template <typename CalcT>
static inline CalcT dist_of_i2(CalcT const& dist_a1_i1)
@@ -760,8 +846,9 @@ private:
static inline bool is_endpoint_equal(CalcT const& dist,
P1 const& ai, P2 const& b1, P2 const& b2)
{
+ static CalcT const c0 = 0;
using geometry::detail::equals::equals_point_point;
- return is_near(dist) && (equals_point_point(ai, b1) || equals_point_point(ai, b2));
+ return is_near(dist) && (equals_point_point(ai, b1) || equals_point_point(ai, b2) || math::equals(dist, c0));
}
template <typename CalcT>
diff --git a/boost/geometry/strategies/spherical/ssf.hpp b/boost/geometry/strategies/spherical/ssf.hpp
index c99e5835e2..03f5428ede 100644
--- a/boost/geometry/strategies/spherical/ssf.hpp
+++ b/boost/geometry/strategies/spherical/ssf.hpp
@@ -23,6 +23,8 @@
#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_segment.hpp>
//#include <boost/geometry/strategies/concepts/side_concept.hpp>
@@ -82,6 +84,20 @@ class spherical_side_formula
{
public :
+ typedef strategy::envelope::spherical_segment<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();
+ }
+
template <typename P1, typename P2, typename P>
static inline int apply(P1 const& p1, P2 const& p2, P const& p)
{
diff --git a/boost/geometry/strategies/strategies.hpp b/boost/geometry/strategies/strategies.hpp
index f3c6787a4b..27a025c7c4 100644
--- a/boost/geometry/strategies/strategies.hpp
+++ b/boost/geometry/strategies/strategies.hpp
@@ -69,6 +69,7 @@
#include <boost/geometry/strategies/spherical/area.hpp>
#include <boost/geometry/strategies/spherical/azimuth.hpp>
+#include <boost/geometry/strategies/spherical/disjoint_segment_box.hpp>
#include <boost/geometry/strategies/spherical/distance_haversine.hpp>
#include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
#include <boost/geometry/strategies/spherical/distance_cross_track_point_box.hpp>
@@ -79,6 +80,7 @@
#include <boost/geometry/strategies/geographic/area.hpp>
#include <boost/geometry/strategies/geographic/azimuth.hpp>
+#include <boost/geometry/strategies/geographic/disjoint_segment_box.hpp>
#include <boost/geometry/strategies/geographic/distance.hpp>
#include <boost/geometry/strategies/geographic/distance_andoyer.hpp>
#include <boost/geometry/strategies/geographic/distance_thomas.hpp>