Changeset 71 in josm for src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
- Timestamp:
- 2006-03-25T16:21:09+01:00 (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r66 r71 1 1 package org.openstreetmap.josm.data.osm.visitor; 2 2 3 import org.openstreetmap.josm.Main; 3 4 import org.openstreetmap.josm.data.Bounds; 5 import org.openstreetmap.josm.data.coor.EastNorth; 4 6 import org.openstreetmap.josm.data.osm.LineSegment; 5 7 import org.openstreetmap.josm.data.osm.Node; … … 7 9 8 10 /** 9 * Calculates the total bounding rectangle of a serie of OsmPrimitives. 11 * Calculates the total bounding rectangle of a serie of OsmPrimitives, using the EastNorth values 12 * as reference. 10 13 * @author imi 11 14 */ 12 public class Bounding Visitor implements Visitor {15 public class BoundingXYVisitor implements Visitor { 13 16 14 /** 15 * The bounding rectangle of all primitives visited so far. 16 */ 17 public Bounds bounds; 18 19 /** 20 * Calculate regarding lat/lon or x/y? 21 */ 22 public static enum Type {LATLON, XY} 23 private Type type; 24 25 26 public BoundingVisitor(Type type) { 27 this.type = type; 28 } 29 17 public EastNorth min, max; 30 18 31 19 public void visit(Node n) { 32 if (bounds == null) 33 bounds = new Bounds(n.coor.clone(), n.coor.clone()); 34 else { 35 if (type == Type.LATLON) { 36 bounds.min.lat = Math.min(bounds.min.lat, n.coor.lat); 37 bounds.min.lon = Math.min(bounds.min.lon, n.coor.lon); 38 bounds.max.lat = Math.max(bounds.max.lat, n.coor.lat); 39 bounds.max.lon = Math.max(bounds.max.lon, n.coor.lon); 40 } else { 41 bounds.min.x = Math.min(bounds.min.x, n.coor.x); 42 bounds.min.y = Math.min(bounds.min.y, n.coor.y); 43 bounds.max.x = Math.max(bounds.max.x, n.coor.x); 44 bounds.max.y = Math.max(bounds.max.y, n.coor.y); 45 } 46 } 20 visit(n.eastNorth); 47 21 } 48 22 … … 58 32 visit(ls); 59 33 } 34 35 public void visit(EastNorth eastNorth) { 36 if (eastNorth != null) { 37 if (min == null) 38 min = eastNorth; 39 else if (eastNorth.east() < min.east() || eastNorth.north() < min.north()) 40 min = new EastNorth(Math.min(min.east(), eastNorth.east()), Math.min(min.north(), eastNorth.north())); 41 42 if (max == null) 43 max = eastNorth; 44 else if (eastNorth.east() > max.east() || eastNorth.north() > max.north()) 45 max = new EastNorth(Math.max(max.east(), eastNorth.east()), Math.max(max.north(), eastNorth.north())); 46 } 47 } 48 49 /** 50 * @return The bounding box or <code>null</code> if no coordinates have passed 51 */ 52 public Bounds getBounds() { 53 if (min == null || max == null) 54 return null; 55 return new Bounds(Main.pref.getProjection().eastNorth2latlon(min), Main.pref.getProjection().eastNorth2latlon(max)); 56 } 60 57 } 61
Note:
See TracChangeset
for help on using the changeset viewer.