From 7abd0bb0aaab3a6fb3fc5262d612e203b69a7bc8 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 28 Feb 2010 21:20:07 +0000 Subject: [PATCH] Added difference and sym_difference Added reverse conform std::reverse [SVN r60001] --- .../detail/overlay/debug_turn_info.hpp | 1 + .../boost/geometry/algorithms/difference.hpp | 53 +++++++ .../geometry/algorithms/overlay/get_turns.hpp | 118 ++------------- include/boost/geometry/algorithms/reverse.hpp | 141 ++++++++++++++++++ .../geometry/algorithms/sym_difference.hpp | 55 +++++++ .../geometry/extensions/io/svg/svg_mapper.hpp | 2 + .../transform/matrix_transformers.hpp | 13 +- 7 files changed, 266 insertions(+), 117 deletions(-) create mode 100644 include/boost/geometry/algorithms/difference.hpp create mode 100644 include/boost/geometry/algorithms/reverse.hpp create mode 100644 include/boost/geometry/algorithms/sym_difference.hpp diff --git a/include/boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp b/include/boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp index 71b9798e2..6eeea5b56 100644 --- a/include/boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp @@ -9,6 +9,7 @@ #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_DEBUG_TURN_INFO_HPP #include +#include namespace boost { namespace geometry diff --git a/include/boost/geometry/algorithms/difference.hpp b/include/boost/geometry/algorithms/difference.hpp new file mode 100644 index 000000000..37388e07e --- /dev/null +++ b/include/boost/geometry/algorithms/difference.hpp @@ -0,0 +1,53 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_DIFFERENCE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP + +#include + + +#include +#include + + +/*! +\defgroup difference difference: difference of two geometries +*/ + + +namespace boost { namespace geometry +{ + + +/*! + \ingroup difference + \tparam Geometry geometry type + \param geometry the geometry to make difference +*/ +template +< + typename Geometry1, + typename Geometry2, + typename Collection +> +inline void difference(Geometry1 const& geometry1, + Geometry2 geometry2, Collection& output_collection) +{ + concept::check(); + concept::check(); + + reverse(geometry2); + + intersection(geometry1, geometry2, output_collection); +} + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP diff --git a/include/boost/geometry/algorithms/overlay/get_turns.hpp b/include/boost/geometry/algorithms/overlay/get_turns.hpp index 7f3462485..78fe0f29e 100644 --- a/include/boost/geometry/algorithms/overlay/get_turns.hpp +++ b/include/boost/geometry/algorithms/overlay/get_turns.hpp @@ -654,6 +654,8 @@ private: namespace dispatch { +// Because this is "detail" method, and most implementations will use "generic", +// we take the freedom to derive it from "generic". template < typename GeometryTag1, typename GeometryTag2, @@ -665,8 +667,15 @@ template typename InterruptPolicy > struct get_turns -{ -}; + : detail::get_turns::get_turns_generic + < + Geometry1, + Geometry2, + Turns, + IntersectionStrategy, + AssignPolicy, InterruptPolicy + > +{}; template @@ -776,111 +785,6 @@ struct get_turns }; -template -< - typename Ring1, - typename Ring2, - typename Turns, - typename IntersectionStrategy, - typename AssignPolicy, - typename InterruptPolicy -> -struct get_turns - < - ring_tag, ring_tag, false, false, - Ring1, Ring2, - Turns, IntersectionStrategy, - AssignPolicy, InterruptPolicy - > - : detail::get_turns::get_turns_generic - < - Ring1, - Ring2, - Turns, - IntersectionStrategy, - AssignPolicy, InterruptPolicy - > -{}; - - -template -< - typename Polygon1, - typename Polygon2, - typename Turns, - typename IntersectionStrategy, - typename AssignPolicy, - typename InterruptPolicy -> -struct get_turns - < - polygon_tag, polygon_tag, false, false, - Polygon1, Polygon2, - Turns, IntersectionStrategy, - AssignPolicy, InterruptPolicy - > - : detail::get_turns::get_turns_generic - < - Polygon1, - Polygon2, - Turns, - IntersectionStrategy, - AssignPolicy, InterruptPolicy - > -{}; - -template -< - typename Polygon, - typename Ring, - typename Turns, - typename IntersectionStrategy, - typename AssignPolicy, - typename InterruptPolicy -> -struct get_turns - < - polygon_tag, ring_tag, false, false, - Polygon, Ring, - Turns, IntersectionStrategy, - AssignPolicy, InterruptPolicy - > - : detail::get_turns::get_turns_generic - < - Polygon, - Ring, - Turns, - IntersectionStrategy, - AssignPolicy, InterruptPolicy - > -{}; - -template -< - typename LineString1, - typename LineString2, - typename Turns, - typename IntersectionStrategy, - typename AssignPolicy, - typename InterruptPolicy -> -struct get_turns - < - linestring_tag, linestring_tag, false, false, - LineString1, LineString2, - Turns, IntersectionStrategy, - AssignPolicy, InterruptPolicy - > - : detail::get_turns::get_turns_generic - < - LineString1, - LineString2, - Turns, - IntersectionStrategy, - AssignPolicy, InterruptPolicy - > -{}; - template < typename GeometryTag1, typename GeometryTag2, diff --git a/include/boost/geometry/algorithms/reverse.hpp b/include/boost/geometry/algorithms/reverse.hpp new file mode 100644 index 000000000..ce89d9dd5 --- /dev/null +++ b/include/boost/geometry/algorithms/reverse.hpp @@ -0,0 +1,141 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_REVERSE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_REVERSE_HPP + +#include + +#include +#include +#include + +#include +#include + + +/*! +\defgroup reverse reverse: reverse a geometry + This is functionally equivalent to the std::reverse algorithm. + For a linestring or a linear ring, it is exactly the same as calling the std::reverse algorithm. + For a polygon or a multi-geometry, all its rings or elements are reversed. + + No check on order is applied. So a clockwise polygon (having positive area) + will be made counterclockwise (having negative area). + + The first and last points are reversed as well, even if they are closed and the same. +*/ + + +namespace boost { namespace geometry +{ + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail { namespace reverse +{ + + +template +struct range_reverse +{ + static inline void apply(Range& range) + { + std::reverse(boost::begin(range), boost::end(range)); + } +}; + + +template +struct polygon_reverse +{ + static inline void apply(Polygon& polygon) + { + typedef typename geometry::ring_type::type ring_type; + + typedef range_reverse per_range; + per_range::apply(exterior_ring(polygon)); + + for (typename boost::range_iterator + < + typename interior_type::type + >::type it = boost::begin(interior_rings(polygon)); + it != boost::end(interior_rings(polygon)); + ++it) + { + per_range::apply(*it); + } + } +}; + + + +}} // namespace detail::reverse +#endif // DOXYGEN_NO_DETAIL + + + +#ifndef DOXYGEN_NO_DISPATCH +namespace dispatch +{ + + +template +< + typename Tag, + typename Geometry +> +struct reverse +{ + static inline void apply(Geometry&) + {} +}; + + +template +struct reverse + : detail::reverse::range_reverse +{}; + + +template +struct reverse + : detail::reverse::range_reverse +{}; + + +template +struct reverse + : detail::reverse::polygon_reverse +{}; + + +} // namespace dispatch +#endif + + +/*! + \ingroup reverse + \tparam Geometry geometry type + \param geometry the geometry to make reverse +*/ +template +inline void reverse(Geometry& geometry) +{ + concept::check(); + + dispatch::reverse + < + typename tag::type, + Geometry + >::apply(geometry); +} + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_REVERSE_HPP diff --git a/include/boost/geometry/algorithms/sym_difference.hpp b/include/boost/geometry/algorithms/sym_difference.hpp new file mode 100644 index 000000000..47daa13d2 --- /dev/null +++ b/include/boost/geometry/algorithms/sym_difference.hpp @@ -0,0 +1,55 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright Barend Gehrels 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_SYM_DIFFERENCE_HPP +#define BOOST_GEOMETRY_ALGORITHMS_SYM_DIFFERENCE_HPP + +#include + + +#include +#include + + +/*! +\defgroup sym_difference sym_difference: sym_difference of two geometries +*/ + + +namespace boost { namespace geometry +{ + + +/*! + \ingroup sym_difference + \tparam Geometry geometry type + \param geometry the geometry to make symmetric difference +*/ +template +< + typename Geometry1, + typename Geometry2, + typename Collection +> +inline void sym_difference(Geometry1 geometry1, + Geometry2 geometry2, Collection& output_collection) +{ + concept::check(); + concept::check(); + + reverse(geometry2); + intersection(geometry1, geometry2, output_collection); + reverse(geometry2); + reverse(geometry1); + intersection(geometry1, geometry2, output_collection); +} + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_ALGORITHMS_SYM_DIFFERENCE_HPP diff --git a/include/boost/geometry/extensions/io/svg/svg_mapper.hpp b/include/boost/geometry/extensions/io/svg/svg_mapper.hpp index 60fc3a3cc..e107c3849 100644 --- a/include/boost/geometry/extensions/io/svg/svg_mapper.hpp +++ b/include/boost/geometry/extensions/io/svg/svg_mapper.hpp @@ -12,6 +12,8 @@ #include #include +#include + //#include #include diff --git a/include/boost/geometry/strategies/transform/matrix_transformers.hpp b/include/boost/geometry/strategies/transform/matrix_transformers.hpp index acb252cb2..36a24f6c7 100644 --- a/include/boost/geometry/strategies/transform/matrix_transformers.hpp +++ b/include/boost/geometry/strategies/transform/matrix_transformers.hpp @@ -88,20 +88,13 @@ public : coordinate_type const& c1 = get<0>(p1); coordinate_type const& c2 = get<1>(p1); - typedef typename geometry::coordinate_type::type ct2; - - /* - set<0>(p2, boost::numeric_cast( - c1 * m_matrix(0,0) + c2 * m_matrix(0,1) + m_matrix(0,2))); - set<1>(p2, boost::numeric_cast( - c1 * m_matrix(1,0) + c2 * m_matrix(1,1) + m_matrix(1,2))); - */ coordinate_type p2x = c1 * m_matrix(0,0) + c2 * m_matrix(0,1) + m_matrix(0,2); coordinate_type p2y = c1 * m_matrix(1,0) + c2 * m_matrix(1,1) + m_matrix(1,2); - set<0>(p2, p2x); - set<1>(p2, p2y); + typedef typename geometry::coordinate_type::type ct2; + set<0>(p2, boost::numeric_cast(p2x)); + set<1>(p2, boost::numeric_cast(p2y)); return true; }