1 | package org.openstreetmap.josm.data;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * This is a simple data class for "rectangular" areas of the world, given in lat/lon/min/max
|
---|
5 | * values.
|
---|
6 | *
|
---|
7 | * Do not confuse this with "Area", which is an OSM-primitive for a vector of nodes,
|
---|
8 | * describing some area (like a sea).
|
---|
9 | *
|
---|
10 | * @author imi
|
---|
11 | */
|
---|
12 | public class Bounds {
|
---|
13 | /**
|
---|
14 | * The minimum and maximum coordinates.
|
---|
15 | */
|
---|
16 | public GeoPoint min, max;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Return the center point based on the lat/lon values.
|
---|
20 | *
|
---|
21 | * @return The center of these bounds.
|
---|
22 | */
|
---|
23 | public GeoPoint centerLatLon() {
|
---|
24 | GeoPoint p = new GeoPoint((min.lat+max.lat) / 2, (min.lon+max.lon) / 2);
|
---|
25 | return p;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Return the center point based on the x/y values.
|
---|
30 | *
|
---|
31 | * @return The center of these bounds.
|
---|
32 | */
|
---|
33 | public GeoPoint centerXY() {
|
---|
34 | GeoPoint p = new GeoPoint();
|
---|
35 | p.x = (min.x+max.x) / 2;
|
---|
36 | p.y = (min.y+max.y) / 2;
|
---|
37 | return p;
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Construct bounds out of two geopoints
|
---|
42 | */
|
---|
43 | public Bounds(GeoPoint min, GeoPoint max) {
|
---|
44 | this.min = min;
|
---|
45 | this.max = max;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * @return The bounding rectangle that covers <code>this</code> and
|
---|
50 | * the <code>other</code> bounds, regarding the x/y values.
|
---|
51 | */
|
---|
52 | public Bounds mergeXY(Bounds other) {
|
---|
53 | GeoPoint nmin = new GeoPoint();
|
---|
54 | nmin.x = Math.min(min.x, other.min.x);
|
---|
55 | nmin.y = Math.min(min.y, other.min.y);
|
---|
56 | GeoPoint nmax = new GeoPoint();
|
---|
57 | nmax.x = Math.max(max.x, other.max.x);
|
---|
58 | nmax.y = Math.max(max.y, other.max.y);
|
---|
59 | return new Bounds(nmin, nmax);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * @return The bounding rectangle that covers <code>this</code> and
|
---|
64 | * the <code>other</code> bounds, regarding the lat/lon values.
|
---|
65 | */
|
---|
66 | public Bounds mergeLatLon(Bounds other) {
|
---|
67 | GeoPoint nmin = new GeoPoint(
|
---|
68 | Math.min(min.lat, other.min.lat),
|
---|
69 | Math.min(min.lon, other.min.lon));
|
---|
70 | GeoPoint nmax = new GeoPoint(
|
---|
71 | Math.max(max.lat, other.max.lat),
|
---|
72 | Math.max(max.lon, other.max.lon));
|
---|
73 | return new Bounds(nmin, nmax);
|
---|
74 | }
|
---|
75 | }
|
---|