diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:24:46 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:25:39 +0900 |
commit | 4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch) | |
tree | fd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/geometry/algorithms/detail/point_on_border.hpp | |
parent | b5c87084afaef42b2d058f68091be31988a6a874 (diff) | |
download | boost-upstream/1.65.0.tar.gz boost-upstream/1.65.0.tar.bz2 boost-upstream/1.65.0.zip |
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/geometry/algorithms/detail/point_on_border.hpp')
-rw-r--r-- | boost/geometry/algorithms/detail/point_on_border.hpp | 193 |
1 files changed, 104 insertions, 89 deletions
diff --git a/boost/geometry/algorithms/detail/point_on_border.hpp b/boost/geometry/algorithms/detail/point_on_border.hpp index 1c751c23e4..831081aa69 100644 --- a/boost/geometry/algorithms/detail/point_on_border.hpp +++ b/boost/geometry/algorithms/detail/point_on_border.hpp @@ -4,6 +4,10 @@ // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// This file was modified by Oracle on 2017. +// Modifications copyright (c) 2017 Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -18,6 +22,7 @@ #include <cstddef> #include <boost/range.hpp> +#include <boost/static_assert.hpp> #include <boost/geometry/core/tags.hpp> #include <boost/geometry/core/point_type.hpp> @@ -29,6 +34,8 @@ #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp> #include <boost/geometry/algorithms/detail/equals/point_point.hpp> +#include <boost/geometry/util/condition.hpp> + namespace boost { namespace geometry { @@ -39,10 +46,10 @@ namespace detail { namespace point_on_border { -template<typename Point> struct get_point { - static inline bool apply(Point& destination, Point const& source, bool) + template <typename Point> + static inline bool apply(Point& destination, Point const& source) { destination = source; return true; @@ -74,66 +81,77 @@ struct midpoint_helper<Point, DimensionCount, DimensionCount> }; -template<typename Point, typename Range> +template <bool Midpoint> struct point_on_range { - static inline bool apply(Point& point, Range const& range, bool midpoint) + // Version with iterator + template<typename Point, typename Iterator> + static inline bool apply(Point& point, Iterator begin, Iterator end) { - const std::size_t n = boost::size(range); - if (midpoint && n > 1) + Iterator it = begin; + if (it == end) { - typedef typename boost::range_iterator - < - Range const - >::type iterator; - - iterator it = boost::begin(range); - iterator prev = it++; - while (it != boost::end(range) - && detail::equals::equals_point_point(*it, *prev)) - { - prev = it++; - } - if (it != boost::end(range)) - { - return midpoint_helper - < - Point, - 0, dimension<Point>::value - >::apply(point, *prev, *it); - } + return false; } - if (n > 0) + if (! Midpoint) { - geometry::detail::conversion::convert_point_to_point(*boost::begin(range), point); + geometry::detail::conversion::convert_point_to_point(*it, point); return true; } + + Iterator prev = it++; + + // Go to next non-duplicate point + while (it != end + && detail::equals::equals_point_point(*it, *prev)) + { + prev = it++; + } + if (it != end) + { + return midpoint_helper + < + Point, + 0, dimension<Point>::value + >::apply(point, *prev, *it); + } return false; } + + // Version with range + template<typename Point, typename Range> + static inline bool apply(Point& point, Range const& range) + { + typedef typename geometry::cs_tag<Point>::type cs_tag; + BOOST_STATIC_ASSERT((! Midpoint || boost::is_same<cs_tag, cartesian_tag>::value)); + + return apply(point, boost::begin(range), boost::end(range)); + } }; -template<typename Point, typename Polygon> +template <bool Midpoint> struct point_on_polygon { - static inline bool apply(Point& point, Polygon const& polygon, bool midpoint) + template<typename Point, typename Polygon> + static inline bool apply(Point& point, Polygon const& polygon) { return point_on_range < - Point, - typename ring_type<Polygon>::type - >::apply(point, exterior_ring(polygon), midpoint); + Midpoint + >::apply(point, exterior_ring(polygon)); } }; -template<typename Point, typename Box> +template <bool Midpoint> struct point_on_box { - static inline bool apply(Point& point, Box const& box, bool midpoint) + template<typename Point, typename Box> + static inline bool apply(Point& point, Box const& box) { - if (midpoint) + if (BOOST_GEOMETRY_CONDITION(Midpoint)) { Point p1, p2; detail::assign::assign_box_2d_corner<min_corner, min_corner>(box, p1); @@ -154,15 +172,11 @@ struct point_on_box }; -template -< - typename Point, - typename MultiGeometry, - typename Policy -> +template <typename Policy> struct point_on_multi { - static inline bool apply(Point& point, MultiGeometry const& multi, bool midpoint) + template<typename Point, typename MultiGeometry> + static inline bool apply(Point& point, MultiGeometry const& multi) { // Take a point on the first multi-geometry // (i.e. the first that is not empty) @@ -173,7 +187,7 @@ struct point_on_multi it != boost::end(multi); ++it) { - if (Policy::apply(point, *it, midpoint)) + if (Policy::apply(point, *it)) { return true; } @@ -195,70 +209,57 @@ namespace dispatch template < typename GeometryTag, - typename Point, - typename Geometry + bool Midpoint > struct point_on_border {}; -template<typename Point> -struct point_on_border<point_tag, Point, Point> - : detail::point_on_border::get_point<Point> +template <bool Midpoint> +struct point_on_border<point_tag, Midpoint> + : detail::point_on_border::get_point {}; -template<typename Point, typename Linestring> -struct point_on_border<linestring_tag, Point, Linestring> - : detail::point_on_border::point_on_range<Point, Linestring> +template <bool Midpoint> +struct point_on_border<linestring_tag, Midpoint> + : detail::point_on_border::point_on_range<Midpoint> {}; -template<typename Point, typename Ring> -struct point_on_border<ring_tag, Point, Ring> - : detail::point_on_border::point_on_range<Point, Ring> +template <bool Midpoint> +struct point_on_border<ring_tag, Midpoint> + : detail::point_on_border::point_on_range<Midpoint> {}; -template<typename Point, typename Polygon> -struct point_on_border<polygon_tag, Point, Polygon> - : detail::point_on_border::point_on_polygon<Point, Polygon> +template <bool Midpoint> +struct point_on_border<polygon_tag, Midpoint> + : detail::point_on_border::point_on_polygon<Midpoint> {}; -template<typename Point, typename Box> -struct point_on_border<box_tag, Point, Box> - : detail::point_on_border::point_on_box<Point, Box> +template <bool Midpoint> +struct point_on_border<box_tag, Midpoint> + : detail::point_on_border::point_on_box<Midpoint> {}; -template<typename Point, typename Multi> -struct point_on_border<multi_polygon_tag, Point, Multi> +template <bool Midpoint> +struct point_on_border<multi_polygon_tag, Midpoint> : detail::point_on_border::point_on_multi < - Point, - Multi, - detail::point_on_border::point_on_polygon - < - Point, - typename boost::range_value<Multi>::type - > + detail::point_on_border::point_on_polygon<Midpoint> > {}; -template<typename Point, typename Multi> -struct point_on_border<multi_linestring_tag, Point, Multi> +template <bool Midpoint> +struct point_on_border<multi_linestring_tag, Midpoint> : detail::point_on_border::point_on_multi < - Point, - Multi, - detail::point_on_border::point_on_range - < - Point, - typename boost::range_value<Multi>::type - > + detail::point_on_border::point_on_range<Midpoint> > {}; @@ -273,18 +274,12 @@ struct point_on_border<multi_linestring_tag, Point, Multi> \tparam Geometry geometry type. This also defines the type of the output point \param point to assign \param geometry geometry to take point from -\param midpoint boolean flag, true if the point should not be a vertex, but some point - in between of two vertices \return TRUE if successful, else false. It is only false if polygon/line have no points \note for a polygon, it is always a point on the exterior ring -\note for take_midpoint, it is not taken from two consecutive duplicate vertices, - (unless there are no other). */ template <typename Point, typename Geometry> -inline bool point_on_border(Point& point, - Geometry const& geometry, - bool midpoint = false) +inline bool point_on_border(Point& point, Geometry const& geometry) { concepts::check<Point>(); concepts::check<Geometry const>(); @@ -292,12 +287,32 @@ inline bool point_on_border(Point& point, return dispatch::point_on_border < typename tag<Geometry>::type, - Point, - Geometry - >::apply(point, geometry, midpoint); + false + >::apply(point, geometry); } +/*! +\tparam Midpoint boolean flag, true if the point should not be a vertex, but some point + in between of two vertices +\note for Midpoint, it is not taken from two consecutive duplicate vertices, + (unless there are no other). + */ +/* +template <bool Midpoint, typename Point, typename Geometry> +inline bool point_on_border(Point& point, Geometry const& geometry) +{ + concepts::check<Point>(); + concepts::check<Geometry const>(); + + return dispatch::point_on_border + < + typename tag<Geometry>::type, + Midpoint + >::apply(point, geometry); +} +*/ + }} // namespace boost::geometry |