diff --git a/include/boost/geometry/algorithms/buffer.hpp b/include/boost/geometry/algorithms/buffer.hpp index 236c2c147..13d48c0d5 100644 --- a/include/boost/geometry/algorithms/buffer.hpp +++ b/include/boost/geometry/algorithms/buffer.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include diff --git a/include/boost/geometry/algorithms/detail/disjoint.hpp b/include/boost/geometry/algorithms/detail/disjoint.hpp deleted file mode 100644 index 10917cded..000000000 --- a/include/boost/geometry/algorithms/detail/disjoint.hpp +++ /dev/null @@ -1,246 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) - -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland - -// 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_ALGORITHMS_DETAIL_DISJOINT_HPP -#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP - -// Note: contrary to most files, the geometry::detail::disjoint namespace -// is partly implemented in separate files, to avoid circular references -// disjoint -> get_turns -> disjoint - -#include - -#include - -#include -#include -#include - -#include - -#include - -#include -#include - - -namespace boost { namespace geometry -{ - - -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace disjoint -{ - - -struct disjoint_interrupt_policy -{ - static bool const enabled = true; - bool has_intersections; - - inline disjoint_interrupt_policy() - : has_intersections(false) - {} - - template - inline bool apply(Range const& range) - { - // If there is any IP in the range, it is NOT disjoint - if (boost::size(range) > 0) - { - has_intersections = true; - return true; - } - return false; - } -}; - - - -template -< - typename Point, typename Box, - std::size_t Dimension, std::size_t DimensionCount -> -struct point_box -{ - static inline bool apply(Point const& point, Box const& box) - { - if (get(point) < get(box) - || get(point) > get(box)) - { - return true; - } - return point_box - < - Point, Box, - Dimension + 1, DimensionCount - >::apply(point, box); - } -}; - - -template -struct point_box -{ - static inline bool apply(Point const& , Box const& ) - { - return false; - } -}; - - -// Segment - Box intersection -// Based on Ray-AABB intersection -// http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm - -// TODO - later maybe move to strategy::intersects and add a policy to conditionally extract intersection points - -template -struct segment_box_intersection_dim -{ - //BOOST_STATIC_ASSERT(I < dimension::value); - //BOOST_STATIC_ASSERT(I < dimension::value); - //BOOST_STATIC_ASSERT(dimension::value == dimension::value); - - typedef typename coordinate_type::type point_coordinate; - - template static inline - bool apply(Point const& p0, Point const& p1, Box const& b, RelativeDistance & t_near, RelativeDistance & t_far) - { - //// WARNING! - RelativeDistance must be IEEE float for this to work (division by 0) - //BOOST_STATIC_ASSERT(boost::is_float::value); - //// Ray origin is in segment point 0 - //RelativeDistance ray_d = geometry::get(p1) - geometry::get(p0); - //RelativeDistance tn = ( geometry::get(b) - geometry::get(p0) ) / ray_d; - //RelativeDistance tf = ( geometry::get(b) - geometry::get(p0) ) / ray_d; - - // TODO - should we support also unsigned integers? - BOOST_STATIC_ASSERT(!boost::is_unsigned::value); - point_coordinate ray_d = geometry::get(p1) - geometry::get(p0); - RelativeDistance tn, tf; - if ( is_zero(ray_d) ) - { - tn = dist_div_by_zero(geometry::get(b) - geometry::get(p0)); - tf = dist_div_by_zero(geometry::get(b) - geometry::get(p0)); - } - else - { - tn = static_cast(geometry::get(b) - geometry::get(p0)) / ray_d; - tf = static_cast(geometry::get(b) - geometry::get(p0)) / ray_d; - } - - if ( tf < tn ) - ::std::swap(tn, tf); - - if ( t_near < tn ) - t_near = tn; - if ( tf < t_far ) - t_far = tf; - - return 0 <= t_far && t_near <= t_far && t_near <= 1; - } - - template static inline - R dist_div_by_zero(T const& val) - { - if ( is_zero(val) ) - return 0; - else if ( val < 0 ) - return -(::std::numeric_limits::max)(); - else - return (::std::numeric_limits::max)(); - } - - template static inline - bool is_zero(T const& val) - { - // ray_d == 0 is here because eps of rational is 0 which isn't < than 0 - return val == 0 || math::abs(val) < ::std::numeric_limits::epsilon(); - } -}; - -template -struct segment_box_intersection_impl -{ - BOOST_STATIC_ASSERT(0 < CurrentDimension); - - typedef segment_box_intersection_dim for_dim; - - template - static inline bool apply(Point const& p0, Point const& p1, Box const& b, - RelativeDistance & t_near, RelativeDistance & t_far) - { - return segment_box_intersection_impl::apply(p0, p1, b, t_near, t_far) - && for_dim::apply(p0, p1, b, t_near, t_far); - } -}; - -template -struct segment_box_intersection_impl -{ - typedef segment_box_intersection_dim for_dim; - - template - static inline bool apply(Point const& p0, Point const& p1, Box const& b, - RelativeDistance & t_near, RelativeDistance & t_far) - { - return for_dim::apply(p0, p1, b, t_near, t_far); - } -}; - -template -struct segment_box_intersection -{ - typedef segment_box_intersection_impl::value> impl; - - static inline bool apply(Point const& p0, Point const& p1, Box const& b) - { - typedef - typename geometry::promote_floating_point< - typename geometry::select_most_precise< - typename coordinate_type::type, - typename coordinate_type::type - >::type - >::type relative_distance_type; - - relative_distance_type t_near = -(::std::numeric_limits::max)(); - relative_distance_type t_far = (::std::numeric_limits::max)(); - - // relative_distance = 0 < t_near ? t_near : 0; - - return impl::apply(p0, p1, b, t_near, t_far); - } -}; - -template -< - typename Geometry1, typename Geometry2 -> -struct reverse_covered_by -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - return ! geometry::covered_by(geometry1, geometry2); - } -}; - - -}} // namespace detail::disjoint -#endif // DOXYGEN_NO_DETAIL - - -}} // namespace boost::geometry - -#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp b/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp new file mode 100644 index 000000000..75e0ae293 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp @@ -0,0 +1,138 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP + +#include +#include + +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct check_each_ring_for_within +{ + bool has_within; + Geometry const& m_geometry; + + inline check_each_ring_for_within(Geometry const& g) + : has_within(false) + , m_geometry(g) + {} + + template + inline void apply(Range const& range) + { + if ( geometry::within(geometry::return_point_on_surface(range), m_geometry) ) + { + has_within = true; + } + } +}; + + + +template +inline bool rings_containing(FirstGeometry const& geometry1, + SecondGeometry const& geometry2) +{ + check_each_ring_for_within checker(geometry1); + geometry::detail::for_each_range(geometry2, checker); + return checker.has_within; +} + + + +template +struct general_areal +{ + static inline + bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) + { + if ( !disjoint_linear::apply(geometry1, geometry2)) + { + return false; + } + + // If there is no intersection of segments, they might located + // inside each other + + // We check that using a point on the surface, and see if that is inside + // the other geometry. And vice versa. + + typedef typename geometry::point_type::type point_type1; + typedef typename geometry::point_type::type point_type2; + + if (rings_containing(geometry1, geometry2) + || rings_containing(geometry2, geometry1)) + { + return false; + } + + return true; + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::general_areal +{}; + + +template +struct disjoint + : detail::disjoint::general_areal +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp index 24f9aa24e..ccff9799f 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/box_box.hpp @@ -1,9 +1,15 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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. @@ -15,7 +21,12 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP +#include + #include +#include + +#include namespace boost { namespace geometry @@ -81,6 +92,22 @@ inline bool disjoint_box_box(Box1 const& box1, Box2 const& box2) }} // namespace detail::disjoint #endif // DOXYGEN_NO_DETAIL + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::box_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + }} // namespace boost::geometry diff --git a/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp b/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp new file mode 100644 index 000000000..0c8079b8e --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/implementation.hpp @@ -0,0 +1,36 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_IMPLEMENTATION_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/interface.hpp b/include/boost/geometry/algorithms/detail/disjoint/interface.hpp new file mode 100644 index 000000000..ec9057ba0 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/interface.hpp @@ -0,0 +1,187 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP + +#include + +#include +#include +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +// If reversal is needed, perform it +template +< + typename Geometry1, typename Geometry2, + std::size_t DimensionCount, + typename Tag1, typename Tag2 +> +struct disjoint +{ + static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) + { + return disjoint + < + Geometry2, Geometry1, + DimensionCount, + Tag2, Tag1 + >::apply(g2, g1); + } +}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +namespace resolve_variant { + +template +struct disjoint +{ + static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) + { + concept::check_concepts_and_equal_dimensions + < + Geometry1 const, + Geometry2 const + >(); + + return dispatch::disjoint::apply(geometry1, geometry2); + } +}; + +template +struct disjoint, Geometry2> +{ + struct visitor: boost::static_visitor + { + Geometry2 const& m_geometry2; + + visitor(Geometry2 const& geometry2): m_geometry2(geometry2) {} + + template + bool operator()(Geometry1 const& geometry1) const + { + return disjoint::apply(geometry1, m_geometry2); + } + }; + + static inline bool + apply(boost::variant const& geometry1, + Geometry2 const& geometry2) + { + return boost::apply_visitor(visitor(geometry2), geometry1); + } +}; + +template +struct disjoint > +{ + struct visitor: boost::static_visitor + { + Geometry1 const& m_geometry1; + + visitor(Geometry1 const& geometry1): m_geometry1(geometry1) {} + + template + bool operator()(Geometry2 const& geometry2) const + { + return disjoint::apply(m_geometry1, geometry2); + } + }; + + static inline bool + apply(Geometry1 const& geometry1, + boost::variant const& geometry2) + { + return boost::apply_visitor(visitor(geometry1), geometry2); + } +}; + +template < + BOOST_VARIANT_ENUM_PARAMS(typename T1), + BOOST_VARIANT_ENUM_PARAMS(typename T2) +> +struct disjoint< + boost::variant, + boost::variant +> +{ + struct visitor: boost::static_visitor + { + template + bool operator()(Geometry1 const& geometry1, + Geometry2 const& geometry2) const + { + return disjoint::apply(geometry1, geometry2); + } + }; + + static inline bool + apply(boost::variant const& geometry1, + boost::variant const& geometry2) + { + return boost::apply_visitor(visitor(), geometry1, geometry2); + } +}; + +} // namespace resolve_variant + + + +/*! +\brief \brief_check2{are disjoint} +\ingroup disjoint +\tparam Geometry1 \tparam_geometry +\tparam Geometry2 \tparam_geometry +\param geometry1 \param_geometry +\param geometry2 \param_geometry +\return \return_check2{are disjoint} + +\qbk{[include reference/algorithms/disjoint.qbk]} +*/ +template +inline bool disjoint(Geometry1 const& geometry1, + Geometry2 const& geometry2) +{ + return resolve_variant::disjoint::apply(geometry1, geometry2); +} + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp new file mode 100644 index 000000000..b4e11e5b4 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_areal.hpp @@ -0,0 +1,222 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct disjoint_linear_areal +{ + static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) + { + // if there are intersections - return false + if ( !disjoint_linear::apply(g1, g2) ) + return false; + + typedef typename point_type::type point1_type; + point1_type p; + geometry::point_on_border(p, g1); + return !geometry::covered_by(p, g2); + } +}; + + + + +template +< + typename Segment, + typename Areal, + typename Tag = typename tag::type +> +struct disjoint_segment_areal + : not_implemented +{}; + + +template +struct disjoint_segment_areal +{ + static inline bool apply(Segment const& segment, Polygon const& polygon) + { + typedef typename geometry::ring_type::type ring; + typedef typename geometry::interior_return_type + < + Polygon const + >::type interior_rings; + + if ( !disjoint_range_segment_or_box + < + ring, closure::value, Segment + >::apply(geometry::exterior_ring(polygon), segment) ) + { + return false; + } + + interior_rings const& irings = geometry::interior_rings(polygon); + + for (BOOST_AUTO_TPL(it, boost::begin(irings)); + it != boost::end(irings); ++it) + { + if ( !disjoint_range_segment_or_box + < + ring, closure::value, Segment + >::apply(*it, segment) ) + { + return false; + } + } + + typename point_type::type p; + detail::assign_point_from_index<0>(segment, p); + + return !geometry::covered_by(p, polygon); + } +}; + + +template +struct disjoint_segment_areal +{ + static inline + bool apply(Segment const& segment, MultiPolygon const& multipolygon) + { + return disjoint_multirange_segment_or_box + < + MultiPolygon, Segment + >::apply(multipolygon, segment); + } +}; + + +template +struct disjoint_segment_areal +{ + static inline bool apply(Segment const& segment, Ring const& ring) + { + if ( !disjoint_range_segment_or_box + < + Ring, closure::value, Segment + >::apply(ring, segment) ) + { + return false; + } + + typename point_type::type p; + detail::assign_point_from_index<0>(segment, p); + + return !geometry::covered_by(p, ring); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : public detail::disjoint::disjoint_linear_areal +{}; + + +template +struct disjoint +{ + static inline + bool apply(Areal const& areal, Linear const& linear) + { + return detail::disjoint::disjoint_linear_areal + < + Linear, Areal + >::apply(linear, areal); + } +}; + + +template +struct disjoint +{ + static inline bool apply(Areal const& g1, Segment const& g2) + { + return detail::disjoint::disjoint_segment_areal + < + Segment, Areal + >::apply(g2, g1); + } +}; + + +template +struct disjoint + : detail::disjoint::disjoint_segment_areal +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_AREAL_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp new file mode 100644 index 000000000..0eab4c649 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp @@ -0,0 +1,176 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + +template +struct disjoint_segment +{ + static inline bool apply(Segment1 const& segment1, Segment2 const& segment2) + { + typedef typename point_type::type point_type; + + // We don't need to rescale to detect disjointness + typedef no_rescale_policy rescale_policy_type; + rescale_policy_type robust_policy; + + typedef segment_intersection_points + < + point_type, + typename segment_ratio_type + < + point_type, + rescale_policy_type + >::type + > intersection_return_type; + + intersection_return_type is + = strategy::intersection::relate_cartesian_segments + < + policies::relate::segments_intersection_points + < + intersection_return_type + > + >::apply(segment1, segment2, robust_policy); + + return is.count == 0; + } +}; + + +struct assign_disjoint_policy +{ + // We want to include all points: + static bool const include_no_turn = true; + static bool const include_degenerate = true; + static bool const include_opposite = true; + + // We don't assign extra info: + template + < + typename Info, + typename Point1, + typename Point2, + typename IntersectionInfo, + typename DirInfo + > + static inline void apply(Info& , Point1 const& , Point2 const&, + IntersectionInfo const&, DirInfo const&) + {} +}; + + +template +struct disjoint_linear +{ + static inline + bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) + { + typedef typename geometry::point_type::type point_type; + typedef detail::no_rescale_policy rescale_policy_type; + typedef overlay::turn_info + < + point_type, + typename segment_ratio_type::type + > turn_info; + std::deque turns; + + static const bool reverse1 = overlay::do_reverse::value>::value; // should be false + static const bool reverse2 = overlay::do_reverse::value>::value; // should be false + + // Specify two policies: + // 1) Stop at any intersection + // 2) In assignment, include also degenerate points (which are normally skipped) + disjoint_interrupt_policy policy; + rescale_policy_type robust_policy; + geometry::get_turns + < + reverse1, reverse2, + assign_disjoint_policy + >(geometry1, geometry2, robust_policy, turns, policy); + + return !policy.has_intersections; + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_linear +{}; + + +template +struct disjoint + : detail::disjoint::disjoint_segment +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_LINEAR_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp new file mode 100644 index 000000000..d181726e2 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_segment_or_box.hpp @@ -0,0 +1,195 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP + +#include +#include + +#include + +#include + +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct disjoint_multirange_segment_or_box +{ + static inline + bool apply(MultiRange const& multirange, SegmentOrBox const& segment_or_box) + { + typedef typename boost::range_iterator + < + MultiRange const + >::type const_iterator; + + for (const_iterator it = boost::begin(multirange); + it != boost::end(multirange); ++it) + { + if ( !dispatch::disjoint + < + typename boost::range_value::type, + SegmentOrBox + >::apply(*it, segment_or_box) ) + { + return false; + } + } + return true; + } +}; + + +template +< + typename Range, + closure_selector Closure, + typename SegmentOrBox +> +struct disjoint_range_segment_or_box +{ + static inline + bool apply(Range const& range, SegmentOrBox const& segment_or_box) + { + typedef typename closeable_view::type view_type; + + typedef typename ::boost::range_value::type point_type; + typedef typename ::boost::range_iterator + < + view_type const + >::type const_iterator; + + typedef typename ::boost::range_size::type size_type; + + typedef typename geometry::model::referring_segment + < + point_type const + > range_segment; + + view_type view(range); + + const size_type count = ::boost::size(view); + + if ( count == 0 ) + { + return false; + } + else if ( count == 1 ) + { + return dispatch::disjoint + < + point_type, SegmentOrBox + >::apply(geometry::range::front(view), + segment_or_box); + } + else + { + const_iterator it0 = ::boost::begin(view); + const_iterator it1 = ::boost::begin(view) + 1; + const_iterator last = ::boost::end(view); + + for ( ; it1 != last ; ++it0, ++it1 ) + { + range_segment rng_segment(*it0, *it1); + if ( !dispatch::disjoint + < + range_segment, SegmentOrBox + >::apply(rng_segment, segment_or_box) ) + { + return false; + } + } + return true; + } + } +}; + + + + +template +< + typename Linear, + typename SegmentOrBox, + typename Tag = typename tag::type +> +struct disjoint_linear_segment_or_box + : not_implemented +{}; + + +template +struct disjoint_linear_segment_or_box + : disjoint_range_segment_or_box +{}; + + +template +struct disjoint_linear_segment_or_box + < + MultiLinestring, SegmentOrBox, multi_linestring_tag + > : disjoint_multirange_segment_or_box +{}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_linear_segment_or_box +{}; + + +template +struct disjoint + : detail::disjoint::disjoint_linear_segment_or_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_LINEAR_SEGMENT_OR_BOX_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp new file mode 100644 index 000000000..ea6609a15 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/point_box.hpp @@ -0,0 +1,94 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP + +#include + +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +< + typename Point, typename Box, + std::size_t Dimension, std::size_t DimensionCount +> +struct point_box +{ + static inline bool apply(Point const& point, Box const& box) + { + if (get(point) < get(box) + || get(point) > get(box)) + { + return true; + } + return point_box + < + Point, Box, + Dimension + 1, DimensionCount + >::apply(point, box); + } +}; + + +template +struct point_box +{ + static inline bool apply(Point const& , Box const& ) + { + return false; + } +}; + + +}} // namespace detail::equals +#endif // DOXYGEN_NO_DETAIL + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::point_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_BOX_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp new file mode 100644 index 000000000..77234e0d4 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp @@ -0,0 +1,112 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP + +#include + +#include +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct disjoint_point_linear +{ + static inline + bool apply(Point const& pt, Geometry const& g) + { + return !geometry::covered_by(pt, g); + } +}; + + +template +struct reverse_covered_by +{ + static inline + bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) + { + return !geometry::covered_by(geometry1, geometry2); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : public detail::disjoint::disjoint_point_linear +{}; + + +template +struct disjoint + : detail::disjoint::reverse_covered_by +{}; + + +template +struct disjoint +{ + static inline bool apply(Point const& point, Segment const& segment) + { + typedef geometry::model::referring_segment other_segment; + + other_segment other(point, point); + return detail::disjoint::disjoint_segment + < + Segment, other_segment + >::apply(segment, other); + } +}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_POINT_GEOMETRY_HPP diff --git a/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp b/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp index e762e1fdd..b1d32bf95 100644 --- a/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp +++ b/include/boost/geometry/algorithms/detail/disjoint/point_point.hpp @@ -1,9 +1,15 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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. @@ -19,9 +25,13 @@ #include #include +#include #include +#include + + namespace boost { namespace geometry { @@ -81,23 +91,21 @@ inline bool disjoint_point_point(Point1 const& point1, Point2 const& point2) #endif // DOXYGEN_NO_DETAIL -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace equals + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch { -/*! - \brief Internal utility function to detect of points are disjoint - \note To avoid circular references - */ -template -inline bool equals_point_point(Point1 const& point1, Point2 const& point2) -{ - return ! detail::disjoint::disjoint_point_point(point1, point2); -} + +template +struct disjoint + : detail::disjoint::point_point +{}; -}} // namespace detail::equals -#endif // DOXYGEN_NO_DETAIL +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH }} // namespace boost::geometry diff --git a/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp new file mode 100644 index 000000000..08ac1c236 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/segment_box.hpp @@ -0,0 +1,272 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +template +struct compute_tmin_tmax_per_dim +{ + template + static inline void apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box, + RelativeDistance& ti_min, + RelativeDistance& ti_max, + RelativeDistance& diff) + { + typedef typename coordinate_type::type box_coordinate_type; + typedef typename coordinate_type + < + SegmentPoint + >::type point_coordinate_type; + + RelativeDistance c_p0 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get(p0) ); + + RelativeDistance c_p1 = boost::numeric_cast + < + point_coordinate_type + >( geometry::get(p1) ); + + RelativeDistance c_b_min = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + RelativeDistance c_b_max = boost::numeric_cast + < + box_coordinate_type + >( geometry::get(box) ); + + if ( geometry::get(p1) >= geometry::get(p0) ) + { + diff = c_p1 - c_p0; + ti_min = c_b_min - c_p0; + ti_max = c_b_max - c_p0; + } + else + { + diff = c_p0 - c_p1; + ti_min = c_p0 - c_b_max; + ti_max = c_p0 - c_b_min; + } + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t I, + std::size_t Dimension +> +struct disjoint_segment_box_impl +{ + template + static inline bool apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box, + RelativeDistancePair& t_min, + RelativeDistancePair& t_max) + { + RelativeDistance ti_min, ti_max, diff; + + compute_tmin_tmax_per_dim::apply(p0, p1, box, ti_min, ti_max, diff); + + RelativeDistance t_min_x_diff = t_min.first * diff; + RelativeDistance t_max_x_diff = t_max.first * diff; + + if ( t_min_x_diff > ti_max * t_min.second + || t_max_x_diff < ti_min * t_max.second ) + { + return true; + } + + if ( ti_min * t_min.second > t_min_x_diff ) + { + t_min.first = ti_min; + t_min.second = diff; + } + if ( ti_max * t_max.second < t_max_x_diff ) + { + t_max.first = ti_max; + t_max.second = diff; + } + + if ( t_min.first > t_min.second || t_max.first < 0 ) + { + return true; + } + + return disjoint_segment_box_impl + < + RelativeDistance, + SegmentPoint, + Box, + I + 1, + Dimension + >::apply(p0, p1, box, t_min, t_max); + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t Dimension +> +struct disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, 0, Dimension + > +{ + static inline bool apply(SegmentPoint const& p0, + SegmentPoint const& p1, + Box const& box) + { + std::pair t_min, t_max; + RelativeDistance diff; + + compute_tmin_tmax_per_dim<0>::apply(p0, p1, box, + t_min.first, t_max.first, diff); + + if ( t_min.first > diff || t_max.first < 0 ) + { + return true; + } + + t_min.second = t_max.second = diff; + + return disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, 1, Dimension + >::apply(p0, p1, box, t_min, t_max); + } +}; + + +template +< + typename RelativeDistance, + typename SegmentPoint, + typename Box, + std::size_t Dimension +> +struct disjoint_segment_box_impl + < + RelativeDistance, SegmentPoint, Box, Dimension, Dimension + > +{ + template + static inline bool apply(SegmentPoint const&, SegmentPoint const&, + Box const&, + RelativeDistancePair&, RelativeDistancePair&) + { + return false; + } +}; + + +//========================================================================= + + +template +struct disjoint_segment_box +{ + static inline bool apply(Segment const& segment, Box const& box) + { + assert_dimension_equal(); + + typedef typename util::calculation_type::geometric::binary + < + Segment, Box, void + >::type relative_distance_type; + + typedef typename point_type::type segment_point_type; + segment_point_type p0, p1; + geometry::detail::assign_point_from_index<0>(segment, p0); + geometry::detail::assign_point_from_index<1>(segment, p1); + + return disjoint_segment_box_impl + < + relative_distance_type, segment_point_type, Box, + 0, dimension::value + >::apply(p0, p1, box); + } +}; + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +struct disjoint + : detail::disjoint::disjoint_segment_box +{}; + + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_SEGMENT_BOX_HPP diff --git a/include/boost/geometry/algorithms/detail/equals/point_point.hpp b/include/boost/geometry/algorithms/detail/equals/point_point.hpp new file mode 100644 index 000000000..12daa85e9 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/equals/point_point.hpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace equals +{ + +/*! + \brief Internal utility function to detect of points are disjoint + \note To avoid circular references + */ +template +inline bool equals_point_point(Point1 const& point1, Point2 const& point2) +{ + return ! detail::disjoint::disjoint_point_point(point1, point2); +} + + +}} // namespace detail::equals +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_POINT_POINT_HPP diff --git a/include/boost/geometry/algorithms/detail/has_self_intersections.hpp b/include/boost/geometry/algorithms/detail/has_self_intersections.hpp index 65a58ee8c..632ec595d 100644 --- a/include/boost/geometry/algorithms/detail/has_self_intersections.hpp +++ b/include/boost/geometry/algorithms/detail/has_self_intersections.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include diff --git a/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp b/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp index 37066192a..0fd1fe4de 100644 --- a/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/append_no_duplicates.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include diff --git a/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp b/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp index b911b6b6d..a785bd608 100644 --- a/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/append_no_dups_or_spikes.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include namespace boost { namespace geometry diff --git a/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp b/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp index 321a512bf..157f1993a 100644 --- a/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/pointlike_pointlike.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include diff --git a/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp b/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp index 46d0be3bf..e2a21a0fe 100644 --- a/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/self_turn_points.hpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include diff --git a/include/boost/geometry/algorithms/detail/point_on_border.hpp b/include/boost/geometry/algorithms/detail/point_on_border.hpp index 70113ab3a..d99ab3c90 100644 --- a/include/boost/geometry/algorithms/detail/point_on_border.hpp +++ b/include/boost/geometry/algorithms/detail/point_on_border.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include namespace boost { namespace geometry diff --git a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp index 99553b9fe..f98c3e9b8 100644 --- a/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp +++ b/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include namespace boost { namespace geometry { diff --git a/include/boost/geometry/algorithms/detail/relate/point_point.hpp b/include/boost/geometry/algorithms/detail/relate/point_point.hpp index 3dcff8578..fcbb1d7ee 100644 --- a/include/boost/geometry/algorithms/detail/relate/point_point.hpp +++ b/include/boost/geometry/algorithms/detail/relate/point_point.hpp @@ -14,7 +14,7 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_POINT_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_POINT_HPP -#include +#include #include #include diff --git a/include/boost/geometry/algorithms/detail/relate/topology_check.hpp b/include/boost/geometry/algorithms/detail/relate/topology_check.hpp index 9c343727a..98b857a48 100644 --- a/include/boost/geometry/algorithms/detail/relate/topology_check.hpp +++ b/include/boost/geometry/algorithms/detail/relate/topology_check.hpp @@ -13,7 +13,7 @@ #include -#include +#include #include namespace boost { namespace geometry { diff --git a/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp b/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp index a3841496f..18a46c279 100644 --- a/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp +++ b/include/boost/geometry/algorithms/detail/within/point_in_geometry.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include diff --git a/include/boost/geometry/algorithms/disjoint.hpp b/include/boost/geometry/algorithms/disjoint.hpp index 7ee61c602..f997487c7 100644 --- a/include/boost/geometry/algorithms/disjoint.hpp +++ b/include/boost/geometry/algorithms/disjoint.hpp @@ -1,12 +1,15 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. -// Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. -// This file was modified by Oracle on 2013. -// Modifications copyright (c) 2013, Oracle and/or its affiliates. +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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. @@ -18,591 +21,7 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP #define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include - -#include -#include - - -namespace boost { namespace geometry -{ - - -#ifndef DOXYGEN_NO_DETAIL -namespace detail { namespace disjoint -{ - -template -struct check_each_ring_for_within -{ - bool has_within; - Geometry const& m_geometry; - - inline check_each_ring_for_within(Geometry const& g) - : has_within(false) - , m_geometry(g) - {} - - template - inline void apply(Range const& range) - { - if ( geometry::within(geometry::return_point_on_surface(range), m_geometry) ) - { - has_within = true; - } - } -}; - -template -inline bool rings_containing(FirstGeometry const& geometry1, - SecondGeometry const& geometry2) -{ - check_each_ring_for_within checker(geometry1); - geometry::detail::for_each_range(geometry2, checker); - return checker.has_within; -} - - - -struct assign_disjoint_policy -{ - // We want to include all points: - static bool const include_no_turn = true; - static bool const include_degenerate = true; - static bool const include_opposite = true; - - // We don't assign extra info: - template - < - typename Info, - typename Point1, - typename Point2, - typename IntersectionInfo, - typename DirInfo - > - static inline void apply(Info& , Point1 const& , Point2 const&, - IntersectionInfo const&, DirInfo const&) - {} -}; - - -template -struct disjoint_linear -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - typedef typename geometry::point_type::type point_type; - typedef detail::no_rescale_policy rescale_policy_type; - typedef overlay::turn_info - < - point_type, - typename segment_ratio_type::type - > turn_info; - std::deque turns; - - static const bool reverse1 = overlay::do_reverse::value>::value; // should be false - static const bool reverse2 = overlay::do_reverse::value>::value; // should be false - - // Specify two policies: - // 1) Stop at any intersection - // 2) In assignment, include also degenerate points (which are normally skipped) - disjoint_interrupt_policy policy; - rescale_policy_type robust_policy; - geometry::get_turns - < - reverse1, reverse2, - assign_disjoint_policy - >(geometry1, geometry2, robust_policy, turns, policy); - - return !policy.has_intersections; - } -}; - -template -struct disjoint_segment -{ - static inline bool apply(Segment1 const& segment1, Segment2 const& segment2) - { - typedef typename point_type::type point_type; - - // We don't need to rescale to detect disjointness - typedef no_rescale_policy rescale_policy_type; - rescale_policy_type robust_policy; - - typedef segment_intersection_points - < - point_type, - typename segment_ratio_type - < - point_type, - rescale_policy_type - >::type - > intersection_return_type; - - intersection_return_type is - = strategy::intersection::relate_cartesian_segments - < - policies::relate::segments_intersection_points - < - intersection_return_type - > - >::apply(segment1, segment2, robust_policy); - - return is.count == 0; - } -}; - -template -struct general_areal -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - if (! disjoint_linear::apply(geometry1, geometry2)) - { - return false; - } - - // If there is no intersection of segments, they might located - // inside each other - - // We check that using a point on the surface, and see if that is inside - // the other geometry. And vice versa. - - typedef typename geometry::point_type::type point_type1; - typedef typename geometry::point_type::type point_type2; - - if (rings_containing(geometry1, geometry2) - || rings_containing(geometry2, geometry1)) - { - return false; - } - - return true; - } -}; - -template -struct disjoint_segment_box -{ - static inline bool apply(Segment const& segment, Box const& box) - { - typedef typename point_type::type point_type; - point_type p0, p1; - geometry::detail::assign_point_from_index<0>(segment, p0); - geometry::detail::assign_point_from_index<1>(segment, p1); - - return ! detail::disjoint::segment_box_intersection::apply(p0, p1, box); - } -}; - -template -struct disjoint_linestring_box -{ - static inline bool apply(Linestring const& linestring, Box const& box) - { - typedef typename ::boost::range_value::type point_type; - typedef typename ::boost::range_const_iterator::type const_iterator; - typedef typename ::boost::range_size::type size_type; - - const size_type count = ::boost::size(linestring); - - if ( count == 0 ) - return false; - else if ( count == 1 ) - return detail::disjoint::point_box::value> - ::apply(*::boost::begin(linestring), box); - else - { - const_iterator it0 = ::boost::begin(linestring); - const_iterator it1 = ::boost::begin(linestring) + 1; - const_iterator last = ::boost::end(linestring); - - for ( ; it1 != last ; ++it0, ++it1 ) - { - if ( detail::disjoint::segment_box_intersection::apply(*it0, *it1, box) ) - return false; - } - return true; - } - } -}; - -template -struct disjoint_point_linear -{ - static inline - bool apply(Point const& pt, Geometry const& g) - { - return !geometry::covered_by(pt, g); - } -}; - -// computes disjointness of segment and linestring -template -struct disjoint_linestring_segment -{ - static inline - bool apply(Linestring const& ls, Segment const& seg) - { - return disjoint_linear - < - Linestring, segment_view - >::apply(ls, geometry::segment_view(seg)); - } -}; - -template -struct disjoint_linear_areal -{ - static inline - bool apply(Geometry1 const& g1, Geometry2 const& g2) - { - // if there are intersections - return false - if ( !disjoint_linear::apply(g1, g2) ) - return false; - - typedef typename point_type::type point1_type; - point1_type p; - geometry::point_on_border(p, g1); - return !geometry::covered_by(p, g2); - } -}; - -template -struct disjoint_segment_areal -{ - static inline - bool apply(Segment const& seg, Geometry const& g) - { - return disjoint_linear_areal - < - segment_view, Geometry - >::apply(segment_view(seg), g); - } -}; - -}} // namespace detail::disjoint -#endif // DOXYGEN_NO_DETAIL - - -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch -{ - - -template -< - typename Geometry1, typename Geometry2, - std::size_t DimensionCount = dimension::type::value, - typename Tag1 = typename tag::type, - typename Tag2 = typename tag::type, - bool Reverse = reverse_dispatch::type::value -> -struct disjoint - : detail::disjoint::general_areal -{}; - - -// If reversal is needed, perform it -template -< - typename Geometry1, typename Geometry2, - std::size_t DimensionCount, - typename Tag1, typename Tag2 -> -struct disjoint - : disjoint -{ - static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) - { - return disjoint - < - Geometry2, Geometry1, - DimensionCount, - Tag2, Tag1 - >::apply(g2, g1); - } -}; - - -template -struct disjoint - : detail::disjoint::point_point -{}; - - -template -struct disjoint - : detail::disjoint::box_box -{}; - - -template -struct disjoint - : detail::disjoint::point_box -{}; - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -template -struct disjoint - : detail::disjoint::disjoint_linear -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment_box -{}; - -template -struct disjoint - : detail::disjoint::disjoint_linestring_box -{}; - -//template -//struct disjoint -// : detail::disjoint::disjoint_linear -//{}; -template -struct disjoint - : detail::disjoint::disjoint_linestring_segment -{}; - -template -struct disjoint - : detail::disjoint::disjoint_segment_areal -{}; - -template -struct disjoint -{ - static inline - bool apply(Polygon const& g1, Segment const& g2) - { - return detail::disjoint::disjoint_segment_areal::apply(g2, g1); - } -}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear -{}; - -template -struct disjoint -{ - static inline bool apply(Polygon const& polygon, - MultiLinestring const& multilinestring) - { - return detail::disjoint::disjoint_linear_areal - < - MultiLinestring, - Polygon - >::apply(multilinestring, polygon); - } -}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear_areal -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_linear -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_point_linear -{}; - -template -struct disjoint - : public detail::disjoint::disjoint_point_linear -{}; - -} // namespace dispatch -#endif // DOXYGEN_NO_DISPATCH - - -namespace resolve_variant { - -template -struct disjoint -{ - static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) - { - concept::check_concepts_and_equal_dimensions - < - Geometry1 const, - Geometry2 const - >(); - - return dispatch::disjoint::apply(geometry1, geometry2); - } -}; - -template -struct disjoint, Geometry2> -{ - struct visitor: boost::static_visitor - { - Geometry2 const& m_geometry2; - - visitor(Geometry2 const& geometry2): m_geometry2(geometry2) {} - - template - bool operator()(Geometry1 const& geometry1) const - { - return disjoint::apply(geometry1, m_geometry2); - } - }; - - static inline bool - apply(boost::variant const& geometry1, - Geometry2 const& geometry2) - { - return boost::apply_visitor(visitor(geometry2), geometry1); - } -}; - -template -struct disjoint > -{ - struct visitor: boost::static_visitor - { - Geometry1 const& m_geometry1; - - visitor(Geometry1 const& geometry1): m_geometry1(geometry1) {} - - template - bool operator()(Geometry2 const& geometry2) const - { - return disjoint::apply(m_geometry1, geometry2); - } - }; - - static inline bool - apply(Geometry1 const& geometry1, - boost::variant const& geometry2) - { - return boost::apply_visitor(visitor(geometry1), geometry2); - } -}; - -template < - BOOST_VARIANT_ENUM_PARAMS(typename T1), - BOOST_VARIANT_ENUM_PARAMS(typename T2) -> -struct disjoint< - boost::variant, - boost::variant -> -{ - struct visitor: boost::static_visitor - { - template - bool operator()(Geometry1 const& geometry1, - Geometry2 const& geometry2) const - { - return disjoint::apply(geometry1, geometry2); - } - }; - - static inline bool - apply(boost::variant const& geometry1, - boost::variant const& geometry2) - { - return boost::apply_visitor(visitor(), geometry1, geometry2); - } -}; - -} // namespace resolve_variant - - - -/*! -\brief \brief_check2{are disjoint} -\ingroup disjoint -\tparam Geometry1 \tparam_geometry -\tparam Geometry2 \tparam_geometry -\param geometry1 \param_geometry -\param geometry2 \param_geometry -\return \return_check2{are disjoint} - -\qbk{[include reference/algorithms/disjoint.qbk]} -*/ -template -inline bool disjoint(Geometry1 const& geometry1, - Geometry2 const& geometry2) -{ - return resolve_variant::disjoint::apply(geometry1, geometry2); -} - - -}} // namespace boost::geometry - +#include +#include #endif // BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP diff --git a/include/boost/geometry/algorithms/dispatch/disjoint.hpp b/include/boost/geometry/algorithms/dispatch/disjoint.hpp new file mode 100644 index 000000000..627bcff83 --- /dev/null +++ b/include/boost/geometry/algorithms/dispatch/disjoint.hpp @@ -0,0 +1,70 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_DISPATCH_DISJOINT_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DISPATCH_DISJOINT_HPP + +#include + +#include +#include +#include +#include + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +< + typename Geometry1, typename Geometry2, + std::size_t DimensionCount = dimension::type::value, + typename Tag1 = typename tag_cast + < + typename tag::type, + segment_tag, box_tag, linear_tag, areal_tag + >::type, + typename Tag2 = typename tag_cast + < + typename tag::type, + segment_tag, box_tag, linear_tag, areal_tag + >::type, + bool Reverse = reverse_dispatch::type::value +> +struct disjoint + : not_implemented +{}; + +} // namespace dispatch +#endif // DOXYGEN_NO_DISPATCH + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DISPATCH_DISJOINT_HPP diff --git a/include/boost/geometry/algorithms/equals.hpp b/include/boost/geometry/algorithms/equals.hpp index 4cd577d69..081c8f2c4 100644 --- a/include/boost/geometry/algorithms/equals.hpp +++ b/include/boost/geometry/algorithms/equals.hpp @@ -32,7 +32,7 @@ #include -#include +#include #include #include diff --git a/include/boost/geometry/extensions/contrib/ttmath_stub.hpp b/include/boost/geometry/extensions/contrib/ttmath_stub.hpp index d1383d1db..e2ade189b 100644 --- a/include/boost/geometry/extensions/contrib/ttmath_stub.hpp +++ b/include/boost/geometry/extensions/contrib/ttmath_stub.hpp @@ -116,6 +116,18 @@ struct ttmath_big : ttmath::Big<1,4> : ttmath::Big<1,4>(v) {} + // needed in order to work with boost::geometry::math::abs + inline ttmath_big operator-() const + { + return ttmath::Big<1,4>::operator-(); + } + + // needed because unary operator-() is defined (above) + inline ttmath_big operator-(ttmath_big const& other) const + { + return ttmath::Big<1,4>::operator-(other); + } + /* inline operator double() const { diff --git a/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp b/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp index b61775b8f..0affcff98 100644 --- a/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp +++ b/include/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp @@ -16,7 +16,6 @@ #include -#include #include #include diff --git a/include/boost/geometry/multi/algorithms/disjoint.hpp b/include/boost/geometry/multi/algorithms/disjoint.hpp index e5f57b2a8..55f0f01cd 100644 --- a/include/boost/geometry/multi/algorithms/disjoint.hpp +++ b/include/boost/geometry/multi/algorithms/disjoint.hpp @@ -1,8 +1,13 @@ // Boost.Geometry (aka GGL, Generic Geometry Library) -// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2012 Bruno Lalande, Paris, France. -// Copyright (c) 2012 Mateusz Loskot, London, UK. +// Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2012-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2012-2014 Mateusz Loskot, London, UK. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -11,35 +16,6 @@ #ifndef BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP #define BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP - #include -#include -#include - -#include -#include - - -namespace boost { namespace geometry -{ - - -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch -{ - -template -struct disjoint - : detail::disjoint::reverse_covered_by -{}; - -} // namespace dispatch - - -#endif // DOXYGEN_NO_DISPATCH - - -}} // namespace boost::geometry - #endif // BOOST_GEOMETRY_MULTI_ALGORITHMS_DISJOINT_HPP diff --git a/include/boost/geometry/policies/disjoint_interrupt_policy.hpp b/include/boost/geometry/policies/disjoint_interrupt_policy.hpp new file mode 100644 index 000000000..2a6e54b07 --- /dev/null +++ b/include/boost/geometry/policies/disjoint_interrupt_policy.hpp @@ -0,0 +1,67 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2014 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2014 Mateusz Loskot, London, UK. +// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland. + +// This file was modified by Oracle on 2013-2014. +// Modifications copyright (c) 2013-2014, 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_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP +#define BOOST_GEOMETRY_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP + +#include + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace disjoint +{ + + +struct disjoint_interrupt_policy +{ + static bool const enabled = true; + bool has_intersections; + + inline disjoint_interrupt_policy() + : has_intersections(false) + {} + + template + inline bool apply(Range const& range) + { + // If there is any IP in the range, it is NOT disjoint + if (boost::size(range) > 0) + { + has_intersections = true; + return true; + } + return false; + } +}; + + + +}} // namespace detail::disjoint +#endif // DOXYGEN_NO_DETAIL + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_POLICIES_DISJOINT_INTERRUPT_POLICY_HPP diff --git a/include/boost/geometry/strategies/agnostic/point_in_point.hpp b/include/boost/geometry/strategies/agnostic/point_in_point.hpp index 8ef2a5d2c..e4f9bec4c 100644 --- a/include/boost/geometry/strategies/agnostic/point_in_point.hpp +++ b/include/boost/geometry/strategies/agnostic/point_in_point.hpp @@ -11,7 +11,7 @@ #ifndef BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POINT_HPP #define BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POINT_HPP -#include +#include #include #include diff --git a/include/boost/geometry/strategies/cartesian/cart_intersect.hpp b/include/boost/geometry/strategies/cartesian/cart_intersect.hpp index fa939cd23..66af2d2e9 100644 --- a/include/boost/geometry/strategies/cartesian/cart_intersect.hpp +++ b/include/boost/geometry/strategies/cartesian/cart_intersect.hpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index 63b7fe3c4..e871cb545 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -30,6 +30,7 @@ test-suite boost-geometry-algorithms [ run difference_linear_linear.cpp ] [ run difference_pl_pl.cpp ] [ run disjoint.cpp ] + [ run disjoint_coverage.cpp ] [ run distance.cpp : : : msvc:/bigobj ] [ run distance_areal_areal.cpp ] [ run distance_linear_areal.cpp ] diff --git a/test/algorithms/disjoint_coverage.cpp b/test/algorithms/disjoint_coverage.cpp new file mode 100644 index 000000000..1f2aa8aa3 --- /dev/null +++ b/test/algorithms/disjoint_coverage.cpp @@ -0,0 +1,1335 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Licensed under the Boost Software License version 1.0. +// http://www.boost.org/users/license.html + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle + +#ifndef BOOST_TEST_MODULE +#define BOOST_TEST_MODULE test_disjoint_coverage +#endif + +// unit test to test disjoint for all geometry combinations + +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "from_wkt.hpp" + + +#ifdef HAVE_TTMATH +#include +#endif + +namespace bg = ::boost::geometry; + +//============================================================================ + +template ::type> +struct pretty_print_geometry +{ + static inline std::ostream& apply(Geometry const& geometry) + { + std::cout << bg::wkt(geometry); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Segment const& segment) + { + std::cout << "SEGMENT" << bg::dsv(segment); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Ring const& ring) + { + std::cout << "RING" << bg::dsv(ring); + return std::cout; + } +}; + +template +struct pretty_print_geometry +{ + static inline std::ostream& apply(Box const& box) + { + std::cout << "BOX" << bg::dsv(box); + return std::cout; + } +}; + +//============================================================================ + +struct test_disjoint +{ + template + static inline void apply(Geometry1 const& geometry1, + Geometry2 const& geometry2, + bool expected_result) + { + bool result = bg::disjoint(geometry1, geometry2); + BOOST_CHECK( result == expected_result ); + + result = bg::disjoint(geometry2, geometry1); + BOOST_CHECK( result == expected_result ); + +#ifdef GEOMETRY_TEST_DEBUG + std::cout << "G1 - G2: "; + pretty_print_geometry::apply(geometry1) << " - "; + pretty_print_geometry::apply(geometry2) << std::endl; + std::cout << std::boolalpha; + std::cout << "expected/computed result: " + << expected_result << " / " << result << std::endl; + std::cout << std::endl; + std::cout << std::noboolalpha; +#endif + } +}; + +//============================================================================ + +// pointlike-pointlike geometries +template +inline void test_point_point() +{ + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt

("POINT(0 0)"), + false); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt

("POINT(1 1)"), + true); +} + +template +inline void test_point_multipoint() +{ + typedef bg::model::multi_point

MP; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOINT(1 1,2 2)"), + true); +} + +template +inline void test_multipoint_multipoint() +{ + typedef bg::model::multi_point

MP; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOINT(0 0,1 1)"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOINT(1 1,2 2)"), + true); +} + +//============================================================================ + +// pointlike-linear geometries +template +inline void test_point_segment() +{ + typedef test_disjoint tester; + typedef bg::model::segment

S; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + true); +} + +template +inline void test_point_linestring() +{ + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(3 3)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + true); +} + +template +inline void test_point_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt

("POINT(1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); +} + +template +inline void test_multipoint_segment() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point

MP; + typedef bg::model::segment

S; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("SEGMENT(0 0,2 0)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 2)"), + from_wkt("SEGMENT(0 0,2 0)"), + true); +} + +template +inline void test_multipoint_linestring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,3 3)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,2 0)"), + from_wkt("LINESTRING(0 0,2 2,4 4)"), + true); +} + +template +inline void test_multipoint_multilinestring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 1,0 2)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + true); + + tester::apply(from_wkt("POINT(0 0,1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt("POINT(0 1,1 1)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); + + tester::apply(from_wkt("POINT(0 1,1 0)"), + from_wkt("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"), + false); +} + +//============================================================================ + +// pointlike-areal geometries +template +inline void test_point_box() +{ + typedef test_disjoint tester; + typedef bg::model::box

B; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("BOX(0 0,1 1)"), + false); + + tester::apply(from_wkt

("POINT(2 2)"), + from_wkt("BOX(0 0,1 0)"), + true); +} + +template +inline void test_point_ring() +{ + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_point_polygon() +{ + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_point_multipolygon() +{ + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt

("POINT(0 0)"), + from_wkt("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + false); + + tester::apply(from_wkt

("POINT(1 1)"), + from_wkt("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"), + true); +} + +template +inline void test_multipoint_box() +{ + typedef test_disjoint tester; + typedef bg::model::multi_point

MP; + typedef bg::model::box

B; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 1)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTIPOINT(3 3,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_multipoint_ring() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 0,1 1)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 2)"), + from_wkt("POLYGON((0 0,1 0,0 1))"), + true); +} + +template +inline void test_multipoint_polygon() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,2 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 0)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + true); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 3)"), + from_wkt("POLYGON(((0 0,1 0,0 1)))"), + true); +} + +template +inline void test_multipoint_multipolygon() +{ + typedef bg::model::multi_point

MP; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOINT(0 0,2 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(0 0,1 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 0)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + false); + + tester::apply(from_wkt("MULTIPOINT(1 1,2 3)"), + from_wkt("MULTIPOLYGON((0 0,1 0,0 1)),(2 0,3 0,2 1))"), + true); +} + +//============================================================================ + +// linear-linear geometries +template +inline void test_segment_segment() +{ + typedef bg::model::segment

S; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(0 0,0 2)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(2 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 0,1 1)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("SEGMENT(1 1,2 2)"), + true); +} + +template +inline void test_linestring_segment() +{ + typedef bg::model::segment

S; + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(0 0,0 2)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(2 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 0,3 0)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 0,1 1)"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("LINESTRING(1 1,2 2)"), + true); +} + +template +inline void test_multilinestring_segment() +{ + typedef bg::model::segment

S; + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +template +inline void test_linestring_linestring() +{ + typedef bg::model::linestring

L; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(0 0,0 2)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(2 0,3 0)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 0,3 0)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 0,1 1)"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("LINESTRING(1 1,2 2)"), + true); +} + +template +inline void test_linestring_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +template +inline void test_multilinestring_multilinestring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((0 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((2 0,3 0))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 0,3 0))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 0,1 1))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTILINESTRING((1 1,2 2))"), + true); +} + +//============================================================================ + +// linear-areal geometries +template +inline void test_segment_box() +{ + typedef bg::model::segment

S; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("SEGMENT(4 4,3 3)"), + from_wkt("BOX(0 0,2 2)"), + true); + + tester::apply(from_wkt("SEGMENT(0 4,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); + + tester::apply(from_wkt("SEGMENT(4 0,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_segment_ring() +{ + typedef bg::model::segment

S; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_segment_polygon() +{ + typedef bg::model::segment

S; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_segment_multipolygon() +{ + typedef bg::model::segment

S; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("SEGMENT(0 0,2 0)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(1 0,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("SEGMENT(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template +inline void test_linestring_box() +{ + typedef bg::model::linestring

L; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("LINESTRING(4 4,3 3)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_linestring_ring() +{ + typedef bg::model::linestring

L; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_linestring_polygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_linestring_multipolygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("LINESTRING(0 0,2 0)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(1 0,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("LINESTRING(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +template +inline void test_multilinestring_box() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("MULTILINESTRING((4 4,3 3))"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_multilinestring_ring() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_multilinestring_polygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("POLYGON((0 0,2 0,0 2))"), + true); +} + +template +inline void test_multilinestring_multipolygon() +{ + typedef bg::model::linestring

L; + typedef bg::model::multi_linestring ML; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTILINESTRING((0 0,2 0))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 0,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((1 1,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + false); + + tester::apply(from_wkt("MULTILINESTRING((2 2,3 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,0 2)))"), + true); +} + +//============================================================================ + +// areal-areal geometries +template +inline void test_box_box() +{ + typedef bg::model::box

B; + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("BOX(0 0,2 2)"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("BOX(0 0,2 2)"), + true); +} + +template +inline void test_ring_box() +{ + typedef bg::model::box

B; + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_box() +{ + typedef bg::model::box

B; + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_multipolygon_box() +{ + typedef bg::model::box

B; + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("BOX(2 2,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("BOX(1 1,3 3)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("BOX(3 3,4 4)"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_ring_ring() +{ + typedef bg::model::ring R; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_ring() +{ + typedef bg::model::ring R; // ccw, open + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_multipolygon_ring() +{ + typedef bg::model::ring R; // ccw, open + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_polygon_polygon() +{ + typedef bg::model::polygon PL; // ccw, open + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("POLYGON((0 0,2 0,2 2,0 2))"), + true); +} + +template +inline void test_polygon_multipolygon() +{ + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("POLYGON((2 2,2 3,3 3,3 2))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((1 1,1 3,3 3,3 1))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("POLYGON((3 3,3 4,4 4,4 3))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +template +inline void test_multipolygon_multipolygon() +{ + typedef bg::model::polygon PL; // ccw, open + typedef bg::model::multi_polygon MPL; + + typedef test_disjoint tester; + + tester::apply(from_wkt("MULTIPOLYGON(((2 2,2 3,3 3,3 2)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("MULTIPOLYGON(((1 1,1 3,3 3,3 1)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + false); + + tester::apply(from_wkt("MULTIPOLYGON(((3 3,3 4,4 4,4 3)))"), + from_wkt("MULTIPOLYGON(((0 0,2 0,2 2,0 2)))"), + true); +} + +//============================================================================ + +template +inline void test_pointlike_pointlike() +{ + typedef bg::model::point point_type; + + test_point_point(); + // not implemented yet + // test_point_multipoint(); + + // test_multipoint_multipoint(); +} + +template +inline void test_pointlike_linear() +{ + typedef bg::model::point point_type; + + test_point_linestring(); + test_point_multilinestring(); + test_point_segment(); + + // not implemented yet + // test_multipoint_linestring(); + // test_multipoint_multilinestring(); + // test_multipoint_segment(); +} + +template +inline void test_pointlike_areal() +{ + typedef bg::model::point point_type; + + test_point_polygon(); + test_point_multipolygon(); + test_point_ring(); + test_point_box(); + + // not implemented yet + // test_multipoint_polygon(); + // test_multipoint_multipolygon(); + // test_multipoint_ring(); + // test_multipoint_box(); +} + +template +inline void test_linear_linear() +{ + typedef bg::model::point point_type; + + test_linestring_linestring(); + test_linestring_multilinestring(); + test_linestring_segment(); + + test_multilinestring_multilinestring(); + test_multilinestring_segment(); + + test_segment_segment(); +} + +template +inline void test_linear_areal() +{ + typedef bg::model::point point_type; + + test_segment_polygon(); + test_segment_multipolygon(); + test_segment_ring(); + test_segment_box(); + + test_linestring_polygon(); + test_linestring_multipolygon(); + test_linestring_ring(); + test_linestring_box(); + + test_multilinestring_polygon(); + test_multilinestring_multipolygon(); + test_multilinestring_ring(); + test_multilinestring_box(); +} + +template +inline void test_areal_areal() +{ + typedef bg::model::point point_type; + + test_polygon_polygon(); + test_polygon_multipolygon(); + test_polygon_ring(); + test_polygon_box(); + + test_multipolygon_multipolygon(); + test_multipolygon_ring(); + test_multipolygon_box(); + + test_ring_ring(); + test_ring_box(); + + test_box_box(); +} + +//============================================================================ + +BOOST_AUTO_TEST_CASE( test_pointlike_pointlike_all ) +{ + test_pointlike_pointlike(); + test_pointlike_pointlike(); +#ifdef HAVE_TTMATH + test_pointlike_pointlike(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_linear_all ) +{ + test_pointlike_linear(); + test_pointlike_linear(); +#ifdef HAVE_TTMATH + test_pointlike_linear(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_pointlike_areal_all ) +{ + test_pointlike_areal(); + test_pointlike_areal(); +#ifdef HAVE_TTMATH + test_pointlike_areal(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_linear_all ) +{ + test_linear_linear(); + test_linear_linear(); +#ifdef HAVE_TTMATH + test_linear_linear(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_linear_areal_all ) +{ + test_linear_areal(); + test_linear_areal(); +#ifdef HAVE_TTMATH + test_linear_areal(); +#endif +} + +BOOST_AUTO_TEST_CASE( test_areal_areal_all ) +{ + test_areal_areal(); + test_areal_areal(); +#ifdef HAVE_TTMATH + test_areal_areal(); +#endif +}