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/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..9cef8eaf5 --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp @@ -0,0 +1,175 @@ +// 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 + + +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..a58bff41d --- /dev/null +++ b/include/boost/geometry/algorithms/detail/disjoint/point_geometry.hpp @@ -0,0 +1,111 @@ +// 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 + + +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