- Timestamp:
- 2010-01-10T13:24:25+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r2717 r2805 19 19 * The minimum and maximum coordinates. 20 20 */ 21 private LatLon min, max;21 private double minLat, minLon, maxLat, maxLon; 22 22 23 23 public LatLon getMin() { 24 return min;24 return new LatLon(minLat, minLon); 25 25 } 26 26 27 27 public LatLon getMax() { 28 return max;28 return new LatLon(maxLat, maxLon); 29 29 } 30 30 … … 33 33 */ 34 34 public Bounds(LatLon min, LatLon max) { 35 this.min = min; 36 this.max = max; 35 this(min.lat(), min.lon(), max.lat(), max.lon()); 37 36 } 38 37 39 38 public Bounds(LatLon b) { 40 this.min = b; 41 this.max = b; 39 this(b, b); 42 40 } 43 41 44 42 public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 45 this.min = new LatLon(minlat, minlon); 46 this.max = new LatLon(maxlat, maxlon); 43 this.minLat = minlat; 44 this.minLon = minlon; 45 this.maxLat = maxlat; 46 this.maxLon = maxlon; 47 47 } 48 48 … … 52 52 if (coords.length != 4) 53 53 throw new IllegalArgumentException(tr("Expected array of length 4, got {0}", coords.length)); 54 this.min = new LatLon(coords[0], coords[1]); 55 this.max = new LatLon(coords[2], coords[3]); 54 this.minLat = coords[0]; 55 this.minLon = coords[1]; 56 this.maxLat = coords[2]; 57 this.maxLon = coords[3]; 56 58 } 57 59 … … 79 81 throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[3])); 80 82 81 this.min = new LatLon(values[0], values[1]); 82 this.max = new LatLon(values[2], values[3]); 83 this.minLat = values[0]; 84 this.minLon = values[1]; 85 this.maxLat = values[2]; 86 this.maxLon = values[3]; 83 87 } 84 88 85 89 public Bounds(Bounds other) { 86 this.min = new LatLon(other.min); 87 this.max = new LatLon(other.max); 90 this(other.getMin(), other.getMax()); 88 91 } 89 92 90 93 public Bounds(Rectangle2D rect) { 91 this.min = new LatLon(rect.getMinY(), rect.getMinX()); 92 this.max = new LatLon(rect.getMaxY(), rect.getMaxX()); 94 this(rect.getMinY(), rect.getMinX(), rect.getMaxY(), rect.getMaxX()); 93 95 } 94 96 … … 113 115 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0.0 exptected, got {1}", "lonExtent", lonExtent)); 114 116 115 this.min = new LatLon( 116 center.lat() - latExtent / 2, 117 center.lon() - lonExtent / 2 118 ); 119 this.max = new LatLon( 120 center.lat() + latExtent / 2, 121 center.lon() + lonExtent / 2 122 ); 117 this.minLat = center.lat() - latExtent / 2; 118 this.minLon = center.lon() - lonExtent / 2; 119 this.maxLat = center.lat() + latExtent / 2; 120 this.maxLon = center.lon() + lonExtent / 2; 123 121 } 124 122 125 123 @Override public String toString() { 126 return "Bounds["+min .lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]";124 return "Bounds["+minLat+","+minLon+","+maxLat+","+maxLon+"]"; 127 125 } 128 126 129 127 public String toShortString(DecimalFormat format) { 130 128 return 131 format.format(min.lat()) + " "132 + format.format(min.lon()) + " / "133 + format.format(max.lat()) + " "134 + format.format(max.lon());129 format.format(minLat) + " " 130 + format.format(minLon) + " / " 131 + format.format(maxLat) + " " 132 + format.format(maxLon); 135 133 } 136 134 … … 140 138 public LatLon getCenter() 141 139 { 142 return min.getCenter(max);140 return getMin().getCenter(getMax()); 143 141 } 144 142 … … 147 145 */ 148 146 public void extend(LatLon ll) { 149 if (ll.lat() < min.lat() || ll.lon() < min.lon()) { 150 min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon())); 151 } 152 if (ll.lat() > max.lat() || ll.lon() > max.lon()) { 153 max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon())); 154 } 147 if (ll.lat() < minLat) { 148 minLat = ll.lat(); 149 } 150 if (ll.lon() < minLon) { 151 minLon = ll.lon(); 152 } 153 if (ll.lat() > maxLat) { 154 maxLat = ll.lat(); 155 } 156 if (ll.lon() > maxLon) { 157 maxLon = ll.lon(); 158 } 159 } 160 161 public void extend(Bounds b) { 162 extend(b.getMin()); 163 extend(b.getMax()); 155 164 } 156 165 /** … … 158 167 */ 159 168 public boolean contains(LatLon ll) { 160 if (ll.lat() < min .lat() || ll.lon() < min.lon())161 return false; 162 if (ll.lat() > max .lat() || ll.lon() > max.lon())169 if (ll.lat() < minLat || ll.lon() < minLon) 170 return false; 171 if (ll.lat() > maxLat || ll.lon() > maxLon) 163 172 return false; 164 173 return true; … … 170 179 */ 171 180 public Rectangle2D.Double asRect() { 172 return new Rectangle2D.Double(min .lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat());181 return new Rectangle2D.Double(minLon, minLat, maxLon-minLon, maxLat-minLat); 173 182 } 174 183 175 184 public double getArea() { 176 return (max .lon() - min.lon()) * (max.lat() - min.lat());185 return (maxLon - minLon) * (maxLat - minLat); 177 186 } 178 187 179 188 public String encodeAsString(String separator) { 180 189 StringBuffer sb = new StringBuffer(); 181 sb.append(min .lat()).append(separator).append(min.lon())182 .append(separator).append(max .lat()).append(separator)183 .append(max .lon());190 sb.append(minLat).append(separator).append(minLon) 191 .append(separator).append(maxLat).append(separator) 192 .append(maxLon); 184 193 return sb.toString(); 185 194 } … … 189 198 final int prime = 31; 190 199 int result = 1; 191 result = prime * result + ((max == null) ? 0 : max.hashCode()); 192 result = prime * result + ((min == null) ? 0 : min.hashCode()); 200 long temp; 201 temp = Double.doubleToLongBits(maxLat); 202 result = prime * result + (int) (temp ^ (temp >>> 32)); 203 temp = Double.doubleToLongBits(maxLon); 204 result = prime * result + (int) (temp ^ (temp >>> 32)); 205 temp = Double.doubleToLongBits(minLat); 206 result = prime * result + (int) (temp ^ (temp >>> 32)); 207 temp = Double.doubleToLongBits(minLon); 208 result = prime * result + (int) (temp ^ (temp >>> 32)); 193 209 return result; 194 210 } … … 203 219 return false; 204 220 Bounds other = (Bounds) obj; 205 if (max == null) { 206 if (other.max != null) 207 return false; 208 } else if (!max.equals(other.max)) 209 return false; 210 if (min == null) { 211 if (other.min != null) 212 return false; 213 } else if (!min.equals(other.min)) 221 if (Double.doubleToLongBits(maxLat) != Double.doubleToLongBits(other.maxLat)) 222 return false; 223 if (Double.doubleToLongBits(maxLon) != Double.doubleToLongBits(other.maxLon)) 224 return false; 225 if (Double.doubleToLongBits(minLat) != Double.doubleToLongBits(other.minLat)) 226 return false; 227 if (Double.doubleToLongBits(minLon) != Double.doubleToLongBits(other.minLon)) 214 228 return false; 215 229 return true;
Note:
See TracChangeset
for help on using the changeset viewer.