Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70136 - trunk/boost/geometry/algorithms/detail/overlay
From: barend.gehrels_at_[hidden]
Date: 2011-03-18 15:35:20


Author: barendgehrels
Date: 2011-03-18 15:35:19 EDT (Fri, 18 Mar 2011)
New Revision: 70136
URL: http://svn.boost.org/trac/boost/changeset/70136

Log:
Moved "within" in "select_rings" to a later phase to avoid too many calls to within in some cases
Text files modified:
   trunk/boost/geometry/algorithms/detail/overlay/ring_properties.hpp | 14 ++------------
   trunk/boost/geometry/algorithms/detail/overlay/select_rings.hpp | 36 +++++++++++++++++++++++++++++-------
   2 files changed, 31 insertions(+), 19 deletions(-)

Modified: trunk/boost/geometry/algorithms/detail/overlay/ring_properties.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/overlay/ring_properties.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/overlay/ring_properties.hpp 2011-03-18 15:35:19 EDT (Fri, 18 Mar 2011)
@@ -32,11 +32,12 @@
     Point point;
     area_type area;
 
+ // Filled by "update_selection_map"
     int within_code;
     bool reversed;
- bool discarded;
 
     // Filled/used by "assign_rings"
+ bool discarded;
     ring_identifier parent;
     area_type parent_area;
     std::vector<ring_identifier> children;
@@ -60,17 +61,6 @@
         geometry::point_on_border(this->point, ring_or_box, true);
     }
 
- template <typename RingOrBox, typename Geometry>
- inline ring_properties(RingOrBox const& ring_or_box, Geometry const& geometry)
- : reversed(false)
- , discarded(false)
- , parent_area(-1)
- {
- this->area = geometry::area(ring_or_box);
- geometry::point_on_border(this->point, ring_or_box, true);
- this->within_code = geometry::within(this->point, geometry) ? 1 : -1;
- }
-
     area_type get_area() const
     {
         return reversed ? -area : area;

Modified: trunk/boost/geometry/algorithms/detail/overlay/select_rings.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/overlay/select_rings.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/overlay/select_rings.hpp 2011-03-18 15:35:19 EDT (Fri, 18 Mar 2011)
@@ -41,7 +41,7 @@
         template <typename Geometry, typename Map>
         static inline void apply(Box const& box, Geometry const& geometry, ring_identifier const& id, Map& map)
         {
- map[id] = typename Map::mapped_type(box, geometry);
+ map[id] = typename Map::mapped_type(box);
         }
 
         template <typename Map>
@@ -59,7 +59,7 @@
         {
             if (boost::size(ring) > 0)
             {
- map[id] = typename Map::mapped_type(ring, geometry);
+ map[id] = typename Map::mapped_type(ring);
             }
         }
 
@@ -171,9 +171,12 @@
 template
 <
     overlay_type OverlayType,
+ typename Geometry1, typename Geometry2,
     typename IntersectionMap, typename SelectionMap
>
-inline void update_selection_map(IntersectionMap const& intersection_map,
+inline void update_selection_map(Geometry1 const& geometry1,
+ Geometry2 const& geometry2,
+ IntersectionMap const& intersection_map,
             SelectionMap const& map_with_all, SelectionMap& selection_map)
 {
     selection_map.clear();
@@ -199,10 +202,29 @@
         bool found = intersection_map.find(it->first) != intersection_map.end();
         if (! found)
         {
- if (decide<OverlayType>::include(it->first, it->second))
+ ring_identifier id = it->first;
+ typename SelectionMap::mapped_type properties = it->second; // Copy by value
+
+ // Calculate the "within code" (previously this was done earlier but is
+ // must efficienter here - it can be even more efficient doing it all at once,
+ // using partition, TODO)
+ // So though this is less elegant than before, it avoids many unused point-in-poly calculations
+ switch(id.source_index)
             {
- selection_map[it->first] = it->second;
- selection_map[it->first].reversed = decide<OverlayType>::reversed(it->first, it->second);
+ case 0 :
+ properties.within_code
+ = geometry::within(properties.point, geometry2) ? 1 : -1;
+ break;
+ case 1 :
+ properties.within_code
+ = geometry::within(properties.point, geometry1) ? 1 : -1;
+ break;
+ }
+
+ if (decide<OverlayType>::include(id, properties))
+ {
+ properties.reversed = decide<OverlayType>::reversed(id, properties);
+ selection_map[id] = properties;
             }
         }
     }
@@ -228,7 +250,7 @@
     dispatch::select_rings<tag1, Geometry1>::apply(geometry1, geometry2, ring_identifier(0, -1, -1), map_with_all);
     dispatch::select_rings<tag2, Geometry2>::apply(geometry2, geometry1, ring_identifier(1, -1, -1), map_with_all);
 
- update_selection_map<OverlayType>(intersection_map, map_with_all, selection_map);
+ update_selection_map<OverlayType>(geometry1, geometry2, intersection_map, map_with_all, selection_map);
 }
 
 template


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