1 | package org.openstreetmap.josm.data;
|
---|
2 |
|
---|
3 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
4 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * This is a simple data class for "rectangular" areas of the world, given in
|
---|
8 | * lat/lon min/max values.
|
---|
9 | *
|
---|
10 | * Do not confuse this with "Area", which is an OSM-primitive for a vector of nodes,
|
---|
11 | * describing some area (like a sea).
|
---|
12 | *
|
---|
13 | * @author imi
|
---|
14 | */
|
---|
15 | public class Bounds {
|
---|
16 | /**
|
---|
17 | * The minimum and maximum coordinates.
|
---|
18 | */
|
---|
19 | public LatLon min, max;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Construct bounds out of two points
|
---|
23 | */
|
---|
24 | public Bounds(LatLon min, LatLon max) {
|
---|
25 | this.min = min;
|
---|
26 | this.max = max;
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Construct bounds that span the whole world.
|
---|
31 | */
|
---|
32 | public Bounds() {
|
---|
33 | min = new LatLon(-Projection.MAX_LAT, -Projection.MAX_LON);
|
---|
34 | max = new LatLon(Projection.MAX_LAT, Projection.MAX_LON);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public String toString() {
|
---|
39 | return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]";
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Extend the bounds if necessary to include the given point.
|
---|
44 | */
|
---|
45 | public void extend(LatLon ll) {
|
---|
46 | if (ll.lat() < min.lat() || ll.lon() < min.lon())
|
---|
47 | min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon()));
|
---|
48 | if (ll.lat() > max.lat() || ll.lon() > max.lon())
|
---|
49 | max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon()));
|
---|
50 | }
|
---|
51 | }
|
---|