1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
5 | import org.openstreetmap.josm.tools.Utils;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This is a simple data class for "rectangular" areas of the world, given in
|
---|
9 | * east/north min/max values.
|
---|
10 | *
|
---|
11 | * @author imi
|
---|
12 | */
|
---|
13 | public class ProjectionBounds {
|
---|
14 | /**
|
---|
15 | * The minimum and maximum coordinates.
|
---|
16 | */
|
---|
17 | public double minEast, minNorth, maxEast, maxNorth;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Construct bounds out of two points.
|
---|
21 | */
|
---|
22 | public ProjectionBounds(EastNorth min, EastNorth max) {
|
---|
23 | this.minEast = min.east();
|
---|
24 | this.minNorth = min.north();
|
---|
25 | this.maxEast = max.east();
|
---|
26 | this.maxNorth = max.north();
|
---|
27 | }
|
---|
28 |
|
---|
29 | public ProjectionBounds(EastNorth p) {
|
---|
30 | this.minEast = this.maxEast = p.east();
|
---|
31 | this.minNorth = this.maxNorth = p.north();
|
---|
32 | }
|
---|
33 |
|
---|
34 | public ProjectionBounds(EastNorth center, double east, double north) {
|
---|
35 | this.minEast = center.east()-east/2.0;
|
---|
36 | this.minNorth = center.north()-north/2.0;
|
---|
37 | this.maxEast = center.east()+east/2.0;
|
---|
38 | this.maxNorth = center.north()+north/2.0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public ProjectionBounds(double minEast, double minNorth, double maxEast, double maxNorth) {
|
---|
42 | this.minEast = minEast;
|
---|
43 | this.minNorth = minNorth;
|
---|
44 | this.maxEast = maxEast;
|
---|
45 | this.maxNorth = maxNorth;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void extend(EastNorth e) {
|
---|
49 | if (e.east() < minEast) {
|
---|
50 | minEast = e.east();
|
---|
51 | }
|
---|
52 | if (e.east() > maxEast) {
|
---|
53 | maxEast = e.east();
|
---|
54 | }
|
---|
55 | if (e.north() < minNorth) {
|
---|
56 | minNorth = e.north();
|
---|
57 | }
|
---|
58 | if (e.north() > maxNorth) {
|
---|
59 | maxNorth = e.north();
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public EastNorth getCenter() {
|
---|
64 | return new EastNorth((minEast + maxEast) / 2.0, (minNorth + maxNorth) / 2.0);
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | public String toString() {
|
---|
69 | return "ProjectionBounds["+minEast+","+minNorth+","+maxEast+","+maxNorth+"]";
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * The two bounds intersect? Compared to java Shape.intersects, if does not use
|
---|
74 | * the interior but the closure. (">=" instead of ">")
|
---|
75 | */
|
---|
76 | public boolean intersects(ProjectionBounds b) {
|
---|
77 | return b.maxEast >= minEast &&
|
---|
78 | b.maxNorth >= minNorth &&
|
---|
79 | b.minEast <= maxEast &&
|
---|
80 | b.minNorth <= maxNorth;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public EastNorth getMin() {
|
---|
84 | return new EastNorth(minEast, minNorth);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public EastNorth getMax() {
|
---|
88 | return new EastNorth(maxEast, maxNorth);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public boolean hasExtend() {
|
---|
92 | return !Utils.equalsEpsilon(minEast, maxEast) || !Utils.equalsEpsilon(minNorth, maxNorth);
|
---|
93 | }
|
---|
94 | }
|
---|