Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69252 - in trunk/boost/geometry: algorithms algorithms/detail/overlay multi/algorithms/detail/overlay
From: barend.gehrels_at_[hidden]
Date: 2011-02-24 17:29:04


Author: barendgehrels
Date: 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
New Revision: 69252
URL: http://svn.boost.org/trac/boost/changeset/69252

Log:
Doc update
Fixed/added difference with box (box/Reversed)
Fixed/added append for some combinations (segment), splitted dispatch into two cases

Text files modified:
   trunk/boost/geometry/algorithms/append.hpp | 110 ++++++++++++++++++++++++++++-----------
   trunk/boost/geometry/algorithms/assign.hpp | 63 ++++++++++++++++------
   trunk/boost/geometry/algorithms/clear.hpp | 8 +-
   trunk/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp | 17 +----
   trunk/boost/geometry/algorithms/detail/overlay/copy_segments.hpp | 23 ++++++--
   trunk/boost/geometry/algorithms/detail/overlay/get_turns.hpp | 27 ++++-----
   trunk/boost/geometry/algorithms/difference.hpp | 3
   trunk/boost/geometry/algorithms/sym_difference.hpp | 2
   trunk/boost/geometry/algorithms/union.hpp | 2
   trunk/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp | 13 ++--
   10 files changed, 173 insertions(+), 95 deletions(-)

Modified: trunk/boost/geometry/algorithms/append.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/append.hpp (original)
+++ trunk/boost/geometry/algorithms/append.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -31,6 +31,15 @@
 {
 
 template <typename Geometry, typename Point>
+struct append_no_action
+{
+ static inline void apply(Geometry& geometry, Point const& point,
+ int = 0, int = 0)
+ {
+ }
+};
+
+template <typename Geometry, typename Point>
 struct append_point
 {
     static inline void apply(Geometry& geometry, Point const& point,
@@ -114,32 +123,67 @@
 namespace dispatch
 {
 
-// (RoP = range or point = use std library)
+namespace splitted_dispatch
+{
 
-// Default case (where RoP will be range/array/etc)
-template <typename Tag, typename TagRoP, typename G, typename RoP>
-struct append : detail::append::append_range<G, RoP> {};
+template <typename Tag, typename Geometry, typename Point>
+struct append_point
+ : detail::append::append_no_action<Geometry, Point>
+{};
 
-// Append a point to any geometry
-template <typename Tag, typename G, typename P>
-struct append<Tag, point_tag, G, P>
- : detail::append::append_point<G, P> {};
+template <typename Geometry, typename Point>
+struct append_point<linestring_tag, Geometry, Point>
+ : detail::append::append_point<Geometry, Point>
+{};
 
-// Never possible to append anything to a point/box/n-sphere
-template <typename TagRoP, typename Point, typename RoP>
-struct append<point_tag, TagRoP, Point, RoP> {};
+template <typename Geometry, typename Point>
+struct append_point<ring_tag, Geometry, Point>
+ : detail::append::append_point<Geometry, Point>
+{};
 
-template <typename TagRoP, typename Box, typename RoP>
-struct append<box_tag, TagRoP, Box, RoP> {};
 
+template <typename Polygon, typename Point>
+struct append_point<polygon_tag, Polygon, Point>
+ : detail::append::point_to_polygon<Polygon, Point>
+{};
 
-template <typename Polygon, typename TagRange, typename Range>
-struct append<polygon_tag, TagRange, Polygon, Range>
- : detail::append::range_to_polygon<Polygon, Range> {};
 
-template <typename Polygon, typename Point>
-struct append<polygon_tag, point_tag, Polygon, Point>
- : detail::append::point_to_polygon<Polygon, Point> {};
+template <typename Tag, typename Geometry, typename Range>
+struct append_range
+ : detail::append::append_no_action<Geometry, Range>
+{};
+
+template <typename Geometry, typename Range>
+struct append_range<linestring_tag, Geometry, Range>
+ : detail::append::append_range<Geometry, Range>
+{};
+
+template <typename Geometry, typename Range>
+struct append_range<ring_tag, Geometry, Range>
+ : detail::append::append_range<Geometry, Range>
+{};
+
+
+template <typename Polygon, typename Range>
+struct append_range<polygon_tag, Polygon, Range>
+ : detail::append::range_to_polygon<Polygon, Range>
+{};
+
+}
+
+
+// Default: append a range (or linestring or ring or whatever) to any geometry
+template <typename TagRangeOrPoint, typename Geometry, typename RangeOrPoint>
+struct append
+ : splitted_dispatch::append_range<typename tag<Geometry>::type, Geometry, RangeOrPoint>
+{};
+
+// Specialization for point to append a point to any geometry
+template <typename Geometry, typename RangeOrPoint>
+struct append<point_tag, Geometry, RangeOrPoint>
+ : splitted_dispatch::append_point<typename tag<Geometry>::type, Geometry, RangeOrPoint>
+{};
+
 
 
 } // namespace dispatch
@@ -147,26 +191,30 @@
 
 
 /*!
- \brief Appends one or more points to a linestring, ring, polygon, multi
- \ingroup append
- \param geometry a geometry
- \param range_or_point the point or range to add
- \param ring_index the index of the ring in case of a polygon:
- exterior ring (-1, the default) or interior ring index
- \param multi_index reserved for multi polygons
+\brief Appends one or more points to a linestring, ring, polygon, multi-geometry
+\ingroup append
+\tparam Geometry \tparam_geometry
+\tparam RangeOrPoint Either a range or a point, fullfilling Boost.Range concept or Boost.Geometry Point Concept
+\param geometry \param_geometry
+\param range_or_point The point or range to add
+\param ring_index The index of the ring in case of a polygon:
+ exterior ring (-1, the default) or interior ring index
+\param multi_index Reserved for multi polygons or multi linestrings
+
+\qbk{[include ref/algorithms/append.qbk]}
+}
  */
-template <typename Geometry, typename RoP>
-inline void append(Geometry& geometry, RoP const& range_or_point,
+template <typename Geometry, typename RangeOrPoint>
+inline void append(Geometry& geometry, RangeOrPoint const& range_or_point,
             int ring_index = -1, int multi_index = 0)
 {
     concept::check<Geometry>();
 
     dispatch::append
         <
- typename tag<Geometry>::type,
- typename tag<RoP>::type,
+ typename tag<RangeOrPoint>::type,
             Geometry,
- RoP
+ RangeOrPoint
>::apply(geometry, range_or_point, ring_index, multi_index);
 }
 

Modified: trunk/boost/geometry/algorithms/assign.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/assign.hpp (original)
+++ trunk/boost/geometry/algorithms/assign.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -113,12 +113,12 @@
 };
 
 
-template <typename Box>
-struct assign_inverse_box
+template <typename BoxOrSegment>
+struct assign_inverse_box_or_segment
 {
- typedef typename point_type<Box>::type point_type;
+ typedef typename point_type<BoxOrSegment>::type point_type;
 
- static inline void apply(Box& box)
+ static inline void apply(BoxOrSegment& geometry)
     {
         typedef typename coordinate_type<point_type>::type coordinate_type;
 
@@ -131,33 +131,33 @@
 
         initialize
             <
- Box, min_corner, 0, dimension<Box>::type::value
+ BoxOrSegment, 0, 0, dimension<BoxOrSegment>::type::value
>::apply(
- box, boost::numeric::bounds<bound_type>::highest());
+ geometry, boost::numeric::bounds<bound_type>::highest());
         initialize
             <
- Box, max_corner, 0, dimension<Box>::type::value
+ BoxOrSegment, 1, 0, dimension<BoxOrSegment>::type::value
>::apply(
- box, boost::numeric::bounds<bound_type>::lowest());
+ geometry, boost::numeric::bounds<bound_type>::lowest());
     }
 };
 
 
-template <typename Box>
-struct assign_zero_box
+template <typename BoxOrSegment>
+struct assign_zero_box_or_segment
 {
- static inline void apply(Box& box)
+ static inline void apply(BoxOrSegment& geometry)
     {
- typedef typename coordinate_type<Box>::type coordinate_type;
+ typedef typename coordinate_type<BoxOrSegment>::type coordinate_type;
 
         initialize
             <
- Box, min_corner, 0, dimension<Box>::type::value
- >::apply(box, coordinate_type());
+ BoxOrSegment, 0, 0, dimension<BoxOrSegment>::type::value
+ >::apply(geometry, coordinate_type());
         initialize
             <
- Box, max_corner, 0, dimension<Box>::type::value
- >::apply(box, coordinate_type());
+ BoxOrSegment, 1, 0, dimension<BoxOrSegment>::type::value
+ >::apply(geometry, coordinate_type());
     }
 };
 
@@ -354,7 +354,12 @@
 
 template <typename Box>
 struct assign_zero<box_tag, Box>
- : detail::assign::assign_zero_box<Box>
+ : detail::assign::assign_zero_box_or_segment<Box>
+{};
+
+template <typename Segment>
+struct assign_zero<segment_tag, Segment>
+ : detail::assign::assign_zero_box_or_segment<Segment>
 {};
 
 
@@ -363,7 +368,12 @@
 
 template <typename Box>
 struct assign_inverse<box_tag, Box>
- : detail::assign::assign_inverse_box<Box>
+ : detail::assign::assign_inverse_box_or_segment<Box>
+{};
+
+template <typename Segment>
+struct assign_inverse<segment_tag, Segment>
+ : detail::assign::assign_inverse_box_or_segment<Segment>
 {};
 
 
@@ -474,11 +484,14 @@
 
 \qbk{distinguish, with a range}
 \qbk{
+[heading Notes]
+[note Assign automatically clears the geometry before assigning (use append if you don't want that)]
 [heading Example]
 [assign_with_range] [assign_with_range_output]
 
 [heading See also]
 \* [link geometry.reference.algorithms.make.make_1_with_a_range make]
+\* [link geometry.reference.algorithms.append.append append]
 }
  */
 template <typename Geometry, typename Range>
@@ -577,6 +590,20 @@
             <max_corner, max_corner>(box, upper_right);
 }
 
+template <bool Reverse, typename Box, typename Range>
+inline void assign_box_corners_oriented(Box const& box, Range& corners)
+{
+ if (Reverse)
+ {
+ // make counterclockwise ll,lr,ur,ul
+ assign_box_corners(box, corners[0], corners[1], corners[3], corners[2]);
+ }
+ else
+ {
+ // make clockwise ll,ul,ur,lr
+ assign_box_corners(box, corners[0], corners[3], corners[1], corners[2]);
+ }
+}
 
 
 /*!

Modified: trunk/boost/geometry/algorithms/clear.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/clear.hpp (original)
+++ trunk/boost/geometry/algorithms/clear.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -123,10 +123,10 @@
 
 
 /*!
- \brief Clears a linestring, linear ring or polygon (exterior+interiors) or multi*
- \details Generic function to clear a geometry
- \ingroup clear
- \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
+\brief Clears a linestring, linear ring or polygon (exterior+interiors) or multi*
+\details Generic function to clear a geometry
+\ingroup clear
+\note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
 */
 template <typename Geometry>
 inline void clear(Geometry& geometry)

Modified: trunk/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/overlay/copy_segment_point.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -102,7 +102,7 @@
 };
 
 
-template <typename Box, typename SegmentIdentifier, typename PointOut>
+template <typename Box, bool Reverse, typename SegmentIdentifier, typename PointOut>
 struct copy_segment_point_box
 {
     static inline bool apply(Box const& box,
@@ -115,16 +115,9 @@
             index++;
         }
 
- PointOut ll, lr, ul, ur;
- assign_box_corners(box, ll, lr, ul, ur);
- switch(index)
- {
- case 1 : point = ul; break;
- case 2 : point = ur; break;
- case 3 : point = lr; break;
- default : // 0,4 or 'overflow'
- point = ll; break;
- }
+ boost::array<typename point_type<Box>::type, 4> bp;
+ assign_box_corners_oriented<Reverse>(box, bp);
+ point = bp[index % 4];
         return true;
     }
 };
@@ -189,7 +182,7 @@
 struct copy_segment_point<box_tag, Box, Reverse, SegmentIdentifier, PointOut>
     : detail::copy_segments::copy_segment_point_box
         <
- Box, SegmentIdentifier, PointOut
+ Box, Reverse, SegmentIdentifier, PointOut
>
 {};
 

Modified: trunk/boost/geometry/algorithms/detail/overlay/copy_segments.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/overlay/copy_segments.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/overlay/copy_segments.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -38,7 +38,13 @@
 {
 
 
-template <typename Ring, bool Reverse, typename SegmentIdentifier, typename RangeOut>
+template
+<
+ typename Ring,
+ bool Reverse,
+ typename SegmentIdentifier,
+ typename RangeOut
+>
 struct copy_segments_ring
 {
     typedef typename closeable_view
@@ -98,7 +104,13 @@
 };
 
 
-template <typename Polygon, bool Reverse, typename SegmentIdentifier, typename RangeOut>
+template
+<
+ typename Polygon,
+ bool Reverse,
+ typename SegmentIdentifier,
+ typename RangeOut
+>
 struct copy_segments_polygon
 {
     static inline void apply(Polygon const& polygon,
@@ -127,6 +139,7 @@
 template
 <
     typename Box,
+ bool Reverse,
     typename SegmentIdentifier,
     typename RangeOut
>
@@ -145,9 +158,7 @@
 
         // Create array of points, the fifth one closes it
         boost::array<typename point_type<Box>::type, 5> bp;
-
- // Points are retrieved by "assign_box_order" in order ll, lr, ul, ur
- assign_box_corners(box, bp[0], bp[3], bp[1], bp[2]);
+ assign_box_corners_oriented<Reverse>(box, bp);
         bp[4] = bp[0];
 
         // (possibly cyclic) copy to output
@@ -226,7 +237,7 @@
 struct copy_segments<box_tag, Box, Reverse, SegmentIdentifier, RangeOut>
     : detail::copy_segments::copy_segments_box
         <
- Box, SegmentIdentifier, RangeOut
+ Box, Reverse, SegmentIdentifier, RangeOut
>
 {};
 

Modified: trunk/boost/geometry/algorithms/detail/overlay/get_turns.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/overlay/get_turns.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/overlay/get_turns.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -523,9 +523,8 @@
 // Get turns for a range with a box, following Cohen-Sutherland (cs) approach
 template
 <
- typename Range,
- bool Reverse,
- typename Box,
+ typename Range, typename Box,
+ bool ReverseRange, bool ReverseBox,
     typename Turns,
     typename TurnPolicy,
     typename InterruptPolicy
@@ -545,7 +544,7 @@
     typedef typename reversible_view
         <
             cview_type const,
- Reverse ? iterate_reverse : iterate_forward
+ ReverseRange ? iterate_reverse : iterate_forward
>::type view_type;
 
     typedef typename boost::range_iterator
@@ -566,12 +565,8 @@
             return;
         }
 
- // Box-points in clockwise order ll, ul, ur, lr
         boost::array<box_point_type,4> bp;
-
- // Points are retrieved by "assign_box_order" in order ll, lr, ul, ur,
- // so make them clockwise here
- assign_box_corners(box, bp[0], bp[3], bp[1], bp[2]);
+ assign_box_corners_oriented<ReverseBox>(box, bp);
 
         cview_type cview(range);
         view_type view(cview);
@@ -696,8 +691,8 @@
 
 template
 <
- typename Polygon, bool Reverse,
- typename Box,
+ typename Polygon, typename Box,
+ bool Reverse, bool ReverseBox,
     typename Turns,
     typename TurnPolicy,
     typename InterruptPolicy
@@ -714,8 +709,8 @@
 
         typedef detail::get_turns::get_turns_cs
             <
- ring_type, Reverse,
- Box,
+ ring_type, Box,
+ Reverse, ReverseBox,
                 Turns,
                 TurnPolicy,
                 InterruptPolicy
@@ -791,8 +786,8 @@
         InterruptPolicy
> : detail::get_turns::get_turns_polygon_cs
             <
- Polygon, ReversePolygon,
- Box,
+ Polygon, Box,
+ ReversePolygon, ReverseBox,
                 Turns, TurnPolicy, InterruptPolicy
>
 {};
@@ -816,7 +811,7 @@
         InterruptPolicy
> : detail::get_turns::get_turns_cs
             <
- Ring, ReverseRing, Box,
+ Ring, Box, ReverseRing, ReverseBox,
                 Turns, TurnPolicy, InterruptPolicy
>
 

Modified: trunk/boost/geometry/algorithms/difference.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/difference.hpp (original)
+++ trunk/boost/geometry/algorithms/difference.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -26,6 +26,8 @@
 \param geometry1 \param_geometry
 \param geometry2 \param_geometry
 \param output_collection the output collection
+
+\qbk{[include ref/algorithms/difference.qbk]}
 */
 template
 <
@@ -50,7 +52,6 @@
             typename geometry::point_type<geometry_out>::type
> strategy;
 
-
     detail::intersection::inserter<geometry_out, false, true, false, overlay_difference>(
             geometry1, geometry2,
             std::back_inserter(output_collection),

Modified: trunk/boost/geometry/algorithms/sym_difference.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/sym_difference.hpp (original)
+++ trunk/boost/geometry/algorithms/sym_difference.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -28,6 +28,8 @@
 \param geometry1 \param_geometry
 \param geometry2 \param_geometry
 \param output_collection the output collection
+
+\qbk{[include ref/algorithms/sym_difference.qbk]}
 */
 template
 <

Modified: trunk/boost/geometry/algorithms/union.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/union.hpp (original)
+++ trunk/boost/geometry/algorithms/union.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -241,6 +241,8 @@
 \param geometry2 \param_geometry
 \param output_collection the output collection
 \note Called union_ because union is a reserved word.
+
+\qbk{[include ref/algorithms/union.qbk]}
 */
 template
 <

Modified: trunk/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp
==============================================================================
--- trunk/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp (original)
+++ trunk/boost/geometry/multi/algorithms/detail/overlay/get_turns.hpp 2011-02-24 17:29:01 EST (Thu, 24 Feb 2011)
@@ -29,9 +29,8 @@
 
 template
 <
- typename Multi,
- bool Reverse,
- typename Box,
+ typename Multi, typename Box,
+ bool Reverse, bool ReverseBox,
     typename Turns,
     typename TurnPolicy,
     typename InterruptPolicy
@@ -56,8 +55,8 @@
             // Call its single version
             get_turns_polygon_cs
                 <
- typename boost::range_value<Multi>::type, Reverse,
- Box,
+ typename boost::range_value<Multi>::type, Box,
+ Reverse, ReverseBox,
                     Turns, TurnPolicy, InterruptPolicy
>::apply(source_id1, *it, source_id2, box,
                             turns, interrupt_policy, i);
@@ -93,8 +92,8 @@
>
     : detail::get_turns::get_turns_multi_polygon_cs
         <
- MultiPolygon, ReverseMultiPolygon,
- Box,
+ MultiPolygon, Box,
+ ReverseMultiPolygon, ReverseBox,
             Turns,
             TurnPolicy, InterruptPolicy
>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk