1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2017, 2018.
8 // Modifications copyright (c) 2017-2018 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.Dimension. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_POINT_ON_BORDER_HPP
19 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_POINT_ON_BORDER_HPP
24 #include <boost/range.hpp>
25 #include <boost/static_assert.hpp>
27 #include <boost/geometry/core/tags.hpp>
28 #include <boost/geometry/core/point_type.hpp>
29 #include <boost/geometry/core/ring_type.hpp>
31 #include <boost/geometry/geometries/concepts/check.hpp>
33 #include <boost/geometry/algorithms/assign.hpp>
34 #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
35 #include <boost/geometry/algorithms/detail/equals/point_point.hpp>
37 #include <boost/geometry/util/condition.hpp>
40 namespace boost { namespace geometry
44 #ifndef DOXYGEN_NO_DETAIL
45 namespace detail { namespace point_on_border
51 template <typename Point>
52 static inline bool apply(Point& destination, Point const& source)
62 // Version with iterator
63 template<typename Point, typename Iterator>
64 static inline bool apply(Point& point, Iterator begin, Iterator end)
71 geometry::detail::conversion::convert_point_to_point(*begin, point);
76 template<typename Point, typename Range>
77 static inline bool apply(Point& point, Range const& range)
79 return apply(point, boost::begin(range), boost::end(range));
84 struct point_on_polygon
86 template<typename Point, typename Polygon>
87 static inline bool apply(Point& point, Polygon const& polygon)
89 return point_on_range::apply(point, exterior_ring(polygon));
96 template<typename Point, typename Box>
97 static inline bool apply(Point& point, Box const& box)
99 detail::assign::assign_box_2d_corner<min_corner, min_corner>(box, point);
105 template <typename Policy>
106 struct point_on_multi
108 template<typename Point, typename MultiGeometry>
109 static inline bool apply(Point& point, MultiGeometry const& multi)
111 // Take a point on the first multi-geometry
112 // (i.e. the first that is not empty)
113 for (typename boost::range_iterator
116 >::type it = boost::begin(multi);
117 it != boost::end(multi);
120 if (Policy::apply(point, *it))
130 }} // namespace detail::point_on_border
131 #endif // DOXYGEN_NO_DETAIL
134 #ifndef DOXYGEN_NO_DISPATCH
139 template <typename GeometryTag>
140 struct point_on_border
144 struct point_on_border<point_tag>
145 : detail::point_on_border::get_point
149 struct point_on_border<linestring_tag>
150 : detail::point_on_border::point_on_range
154 struct point_on_border<ring_tag>
155 : detail::point_on_border::point_on_range
159 struct point_on_border<polygon_tag>
160 : detail::point_on_border::point_on_polygon
164 struct point_on_border<box_tag>
165 : detail::point_on_border::point_on_box
170 struct point_on_border<multi_polygon_tag>
171 : detail::point_on_border::point_on_multi
173 detail::point_on_border::point_on_polygon
179 struct point_on_border<multi_linestring_tag>
180 : detail::point_on_border::point_on_multi
182 detail::point_on_border::point_on_range
187 } // namespace dispatch
188 #endif // DOXYGEN_NO_DISPATCH
192 \brief Take point on a border
194 \tparam Geometry geometry type. This also defines the type of the output point
195 \param point to assign
196 \param geometry geometry to take point from
197 \return TRUE if successful, else false.
198 It is only false if polygon/line have no points
199 \note for a polygon, it is always a point on the exterior ring
201 template <typename Point, typename Geometry>
202 inline bool point_on_border(Point& point, Geometry const& geometry)
204 concepts::check<Point>();
205 concepts::check<Geometry const>();
207 return dispatch::point_on_border
209 typename tag<Geometry>::type
210 >::apply(point, geometry);
214 }} // namespace boost::geometry
217 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_POINT_ON_BORDER_HPP