Changeset 2456 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-11-15T11:33:47+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r2327 r2456 2 2 package org.openstreetmap.josm.data; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.geom.Rectangle2D; 5 7 6 import org.openstreetmap.josm.Main;7 8 import org.openstreetmap.josm.data.coor.LatLon; 8 import static org.openstreetmap.josm.tools.I18n.tr;9 9 10 10 /** … … 19 19 */ 20 20 private LatLon min, max; 21 21 22 22 public LatLon getMin() { 23 23 return min; … … 40 40 this.max = b; 41 41 } 42 42 43 43 public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 44 44 this.min = new LatLon(minlat, minlon); 45 45 this.max = new LatLon(maxlat, maxlon); 46 46 } 47 47 48 48 public Bounds(double [] coords) { 49 49 if (coords == null) … … 54 54 this.max = new LatLon(coords[2], coords[3]); 55 55 } 56 56 57 57 public Bounds(String asString, String separator) throws IllegalArgumentException { 58 58 if (asString == null) 59 59 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "asString")); 60 60 String[] components = asString.split(separator); 61 if (components.length != 4) {61 if (components.length != 4) 62 62 throw new IllegalArgumentException(tr("Exactly four doubles excpected in string, got {0}", components.length)); 63 }64 63 double[] values = new double[4]; 65 64 for (int i=0; i<4; i++) { … … 73 72 this.max = new LatLon(values[2], values[3]); 74 73 } 75 74 76 75 public Bounds(Bounds other) { 77 76 this.min = new LatLon(other.min); … … 83 82 this.max = new LatLon(rect.getMaxY(), rect.getMaxX()); 84 83 } 85 84 85 /** 86 * Creates new bounds around a coordinate pair <code>center</code>. The 87 * new bounds shall have an extension in latitude direction of <code>latExtent</code>, 88 * and in longitude direction of <code>lonExtent</code>. 89 * 90 * @param center the center coordinate pair. Must not be null. 91 * @param latExtent the latitude extent. > 0 required. 92 * @param lonExtent the longitude extent. > 0 required. 93 * @throws IllegalArgumentException thrown if center is null 94 * @throws IllegalArgumentException thrown if latExtent <= 0 95 * @throws IllegalArgumentException thrown if lonExtent <= 0 96 */ 97 public Bounds(LatLon center, double latExtent, double lonExtent) { 98 if (center == null) 99 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "center")); 100 if (latExtent <= 0.0) 101 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0.0 exptected, got {1}", "latExtent", latExtent)); 102 if (lonExtent <= 0.0) 103 throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0.0 exptected, got {1}", "lonExtent", lonExtent)); 104 105 this.min = new LatLon( 106 center.lat() - latExtent / 2, 107 center.lon() - lonExtent / 2 108 ); 109 this.max = new LatLon( 110 center.lat() + latExtent / 2, 111 center.lon() + lonExtent / 2 112 ); 113 } 114 86 115 @Override public String toString() { 87 116 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; … … 100 129 */ 101 130 public void extend(LatLon ll) { 102 if (ll.lat() < min.lat() || ll.lon() < min.lon()) 131 if (ll.lat() < min.lat() || ll.lon() < min.lon()) { 103 132 min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon())); 104 if (ll.lat() > max.lat() || ll.lon() > max.lon()) 133 } 134 if (ll.lat() > max.lat() || ll.lon() > max.lon()) { 105 135 max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon())); 136 } 106 137 } 107 138 /** … … 123 154 return new Rectangle2D.Double(min.lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat()); 124 155 } 125 156 126 157 public double getArea() { 127 158 return (max.lon() - min.lon()) * (max.lat() - min.lat()); … … 135 166 return sb.toString(); 136 167 } 137 168 138 169 @Override 139 170 public int hashCode() {
Note:
See TracChangeset
for help on using the changeset viewer.