Ignore:
Timestamp:
2006-03-25T16:21:09+01:00 (18 years ago)
Author:
imi
Message:
  • refactored GpsPoint to be immutable and added LatLon and NorthEast
  • refactored Bounding Box calculations
  • various other renames
File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r66 r71  
    11package org.openstreetmap.josm.data.osm.visitor;
    22
     3import org.openstreetmap.josm.Main;
    34import org.openstreetmap.josm.data.Bounds;
     5import org.openstreetmap.josm.data.coor.EastNorth;
    46import org.openstreetmap.josm.data.osm.LineSegment;
    57import org.openstreetmap.josm.data.osm.Node;
     
    79
    810/**
    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.
    1013 * @author imi
    1114 */
    12 public class BoundingVisitor implements Visitor {
     15public class BoundingXYVisitor implements Visitor {
    1316
    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;
    3018
    3119        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);
    4721        }
    4822
     
    5832                        visit(ls);
    5933        }
     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        }
    6057}
    61 
Note: See TracChangeset for help on using the changeset viewer.