Changeset 2327 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2009-10-27T01:21:32+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 5 edited
-
Bounds.java (modified) (4 diffs)
-
Preferences.java (modified) (1 diff)
-
coor/Coordinate.java (modified) (1 diff)
-
coor/LatLon.java (modified) (2 diffs)
-
osm/visitor/BoundingXYVisitor.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r2017 r2327 4 4 import java.awt.geom.Rectangle2D; 5 5 6 import org.openstreetmap.josm.Main; 6 7 import org.openstreetmap.josm.data.coor.LatLon; 8 import static org.openstreetmap.josm.tools.I18n.tr; 7 9 8 10 /** … … 16 18 * The minimum and maximum coordinates. 17 19 */ 18 public LatLon min, max; 20 private LatLon min, max; 21 22 public LatLon getMin() { 23 return min; 24 } 25 26 public LatLon getMax() { 27 return max; 28 } 19 29 20 30 /** … … 30 40 this.max = b; 31 41 } 42 43 public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 44 this.min = new LatLon(minlat, minlon); 45 this.max = new LatLon(maxlat, maxlon); 46 } 47 48 public Bounds(double [] coords) { 49 if (coords == null) 50 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "coords")); 51 if (coords.length != 4) 52 throw new IllegalArgumentException(tr("Expected array of length 4, got {0}", coords.length)); 53 this.min = new LatLon(coords[0], coords[1]); 54 this.max = new LatLon(coords[2], coords[3]); 55 } 56 57 public Bounds(String asString, String separator) throws IllegalArgumentException { 58 if (asString == null) 59 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "asString")); 60 String[] components = asString.split(separator); 61 if (components.length != 4) { 62 throw new IllegalArgumentException(tr("Exactly four doubles excpected in string, got {0}", components.length)); 63 } 64 double[] values = new double[4]; 65 for (int i=0; i<4; i++) { 66 try { 67 values[i] = Double.parseDouble(components[i]); 68 } catch(NumberFormatException e) { 69 throw new IllegalArgumentException(tr("Illegal double value ''{0}''", components[i])); 70 } 71 } 72 this.min = new LatLon(values[0], values[1]); 73 this.max = new LatLon(values[2], values[3]); 74 } 75 76 public Bounds(Bounds other) { 77 this.min = new LatLon(other.min); 78 this.max = new LatLon(other.max); 79 } 32 80 81 public Bounds(Rectangle2D rect) { 82 this.min = new LatLon(rect.getMinY(), rect.getMinX()); 83 this.max = new LatLon(rect.getMaxY(), rect.getMaxX()); 84 } 85 33 86 @Override public String toString() { 34 87 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; … … 70 123 return new Rectangle2D.Double(min.lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat()); 71 124 } 125 126 public double getArea() { 127 return (max.lon() - min.lon()) * (max.lat() - min.lat()); 128 } 129 130 public String encodeAsString(String separator) { 131 StringBuffer sb = new StringBuffer(); 132 sb.append(min.lat()).append(separator).append(min.lon()) 133 .append(separator).append(max.lat()).append(separator) 134 .append(max.lon()); 135 return sb.toString(); 136 } 137 138 @Override 139 public int hashCode() { 140 final int prime = 31; 141 int result = 1; 142 result = prime * result + ((max == null) ? 0 : max.hashCode()); 143 result = prime * result + ((min == null) ? 0 : min.hashCode()); 144 return result; 145 } 146 147 @Override 148 public boolean equals(Object obj) { 149 if (this == obj) 150 return true; 151 if (obj == null) 152 return false; 153 if (getClass() != obj.getClass()) 154 return false; 155 Bounds other = (Bounds) obj; 156 if (max == null) { 157 if (other.max != null) 158 return false; 159 } else if (!max.equals(other.max)) 160 return false; 161 if (min == null) { 162 if (other.min != null) 163 return false; 164 } else if (!min.equals(other.min)) 165 return false; 166 return true; 167 } 72 168 73 169 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r2224 r2327 62 62 public String name; 63 63 public double[] latlon = new double[4]; // minlat, minlon, maxlat, maxlon 64 65 public Bookmark() { 66 } 67 68 public Bookmark(Bounds b) { 69 if (b == null) { 70 latlon[0] = 0.0; 71 latlon[1] = 0.0; 72 latlon[2] = 0.0; 73 latlon[3] = 0.0; 74 } else { 75 latlon[0] = b.getMin().lat(); 76 latlon[1] = b.getMin().lon(); 77 latlon[2] = b.getMax().lat(); 78 latlon[3] = b.getMax().lon(); 79 } 80 } 81 64 82 @Override public String toString() { 65 83 return name; 66 84 } 85 67 86 public int compareTo(Bookmark b) { 68 87 return name.toLowerCase().compareTo(b.name.toLowerCase()); 88 } 89 90 public Bounds asBounds() { 91 return new Bounds(latlon[0], latlon[1], latlon[2], latlon[3]); 69 92 } 70 93 } -
trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java
r1169 r2327 45 45 } 46 46 47 @Override 48 public int hashCode() { 49 final int prime = 31; 50 int result = super.hashCode(); 51 long temp; 52 temp = java.lang.Double.doubleToLongBits(x); 53 result = prime * result + (int) (temp ^ (temp >>> 32)); 54 temp = java.lang.Double.doubleToLongBits(y); 55 result = prime * result + (int) (temp ^ (temp >>> 32)); 56 return result; 57 } 58 59 @Override 60 public boolean equals(Object obj) { 61 if (this == obj) 62 return true; 63 if (!super.equals(obj)) 64 return false; 65 if (getClass() != obj.getClass()) 66 return false; 67 Coordinate other = (Coordinate) obj; 68 if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x)) 69 return false; 70 if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y)) 71 return false; 72 return true; 73 } 47 74 } -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r2174 r2327 90 90 public boolean isOutSideWorld() { 91 91 Bounds b = Main.proj.getWorldBoundsLatLon(); 92 return lat() < b. min.lat() || lat() > b.max.lat() ||93 lon() < b. min.lon() || lon() > b.max.lon();92 return lat() < b.getMin().lat() || lat() > b.getMax().lat() || 93 lon() < b.getMin().lon() || lon() > b.getMax().lon(); 94 94 } 95 95 … … 98 98 */ 99 99 public boolean isWithin(Bounds b) { 100 return lat() >= b. min.lat() && lat() <= b.max.lat() && lon() > b.min.lon() && lon() < b.max.lon();100 return lat() >= b.getMin().lat() && lat() <= b.getMax().lat() && lon() > b.getMin().lon() && lon() < b.getMax().lon(); 101 101 } 102 102 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r1946 r2327 45 45 if(b != null) 46 46 { 47 visit(b. min);48 visit(b. max);47 visit(b.getMin()); 48 visit(b.getMax()); 49 49 } 50 50 }
Note:
See TracChangeset
for help on using the changeset viewer.
