Changeset 2948 in josm


Ignore:
Timestamp:
Feb 7, 2010 10:58:30 AM (3 years ago)
Author:
jttt
Message:

Multipolygon with multiple outer polygons optimization - test bbox first when looking for outer polygon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r2793 r2948  
    44import java.awt.Point; 
    55import java.awt.Polygon; 
     6import java.awt.Rectangle; 
    67import java.util.ArrayList; 
    78import java.util.Collection; 
     
    2425        public final boolean selected; 
    2526        private Point lastP; 
     27        private Rectangle bounds; 
    2628 
    2729        public PolyData(NavigatableComponent nc, List<Node> nodes, boolean selected) { 
     
    6870        public Polygon get() { 
    6971            return poly; 
     72        } 
     73 
     74        public Rectangle getBounds() { 
     75            if (bounds == null) { 
     76                bounds = poly.getBounds(); 
     77            } 
     78            return bounds; 
     79        } 
     80 
     81        @Override 
     82        public String toString() { 
     83            return "Points: " + poly.npoints + " Selected: " + selected; 
    7084        } 
    7185    } 
     
    228242    public PolyData findOuterPolygon(PolyData inner, List<PolyData> outerPolygons) { 
    229243        PolyData result = null; 
     244 
     245        {// First try to test only bbox, use precise testing only if we don't get unique result 
     246            Rectangle innerBox = inner.getBounds(); 
     247            PolyData insidePolygon = null; 
     248            PolyData intersectingPolygon = null; 
     249            int insideCount = 0; 
     250            int intersectingCount = 0; 
     251 
     252            for (PolyData outer: outerPolygons) { 
     253                if (outer.getBounds().contains(innerBox)) { 
     254                    insidePolygon = outer; 
     255                    insideCount++; 
     256                } else if (outer.getBounds().intersects(innerBox)) { 
     257                    intersectingPolygon = outer; 
     258                    intersectingCount++; 
     259                } 
     260            } 
     261 
     262            if (insideCount == 1) 
     263                return insidePolygon; 
     264            else if (intersectingCount == 1) 
     265                return intersectingPolygon; 
     266        } 
     267 
    230268        for (PolyData combined : outerPolygons) { 
    231269            Intersection c = combined.contains(inner.poly); 
    232270            if(c != Intersection.OUTSIDE) 
    233271            { 
    234                 if(result == null || result.contains(combined.poly) != Intersection.OUTSIDE) { 
     272                if(result == null || result.contains(combined.poly) != Intersection.INSIDE) { 
    235273                    result = combined; 
    236274                } 
Note: See TracChangeset for help on using the changeset viewer.