[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[1722] | 2 | package org.openstreetmap.josm.data;
|
---|
| 3 |
|
---|
| 4 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
[8384] | 5 | import org.openstreetmap.josm.tools.Utils;
|
---|
[1722] | 6 |
|
---|
| 7 | /**
|
---|
| 8 | * This is a simple data class for "rectangular" areas of the world, given in
|
---|
[4065] | 9 | * east/north min/max values.
|
---|
[1722] | 10 | *
|
---|
| 11 | * @author imi
|
---|
| 12 | */
|
---|
| 13 | public class ProjectionBounds {
|
---|
| 14 | /**
|
---|
| 15 | * The minimum and maximum coordinates.
|
---|
| 16 | */
|
---|
[4065] | 17 | public double minEast, minNorth, maxEast, maxNorth;
|
---|
[1722] | 18 |
|
---|
| 19 | /**
|
---|
[5670] | 20 | * Construct bounds out of two points.
|
---|
[1722] | 21 | */
|
---|
| 22 | public ProjectionBounds(EastNorth min, EastNorth max) {
|
---|
[4065] | 23 | this.minEast = min.east();
|
---|
| 24 | this.minNorth = min.north();
|
---|
| 25 | this.maxEast = max.east();
|
---|
| 26 | this.maxNorth = max.north();
|
---|
[1722] | 27 | }
|
---|
[8384] | 28 |
|
---|
[1724] | 29 | public ProjectionBounds(EastNorth p) {
|
---|
[4065] | 30 | this.minEast = this.maxEast = p.east();
|
---|
| 31 | this.minNorth = this.maxNorth = p.north();
|
---|
[1724] | 32 | }
|
---|
[8384] | 33 |
|
---|
[1722] | 34 | public ProjectionBounds(EastNorth center, double east, double north) {
|
---|
[4065] | 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;
|
---|
[1722] | 39 | }
|
---|
[8384] | 40 |
|
---|
[4065] | 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 | }
|
---|
[8384] | 47 |
|
---|
| 48 | public void extend(EastNorth e) {
|
---|
[4065] | 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 | }
|
---|
[1722] | 61 | }
|
---|
[8384] | 62 |
|
---|
| 63 | public EastNorth getCenter() {
|
---|
[4065] | 64 | return new EastNorth((minEast + maxEast) / 2.0, (minNorth + maxNorth) / 2.0);
|
---|
[1722] | 65 | }
|
---|
[1724] | 66 |
|
---|
[8384] | 67 | @Override
|
---|
| 68 | public String toString() {
|
---|
[8846] | 69 | return "ProjectionBounds["+minEast+","+minNorth+","+maxEast+","+maxNorth+']';
|
---|
[1724] | 70 | }
|
---|
[4065] | 71 |
|
---|
| 72 | /**
|
---|
| 73 | * The two bounds intersect? Compared to java Shape.intersects, if does not use
|
---|
[6830] | 74 | * the interior but the closure. (">=" instead of ">")
|
---|
[4065] | 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 |
|
---|
[8927] | 91 | /**
|
---|
| 92 | * Determines if the bounds area is not null
|
---|
| 93 | * @return {@code true} if the area is not null
|
---|
| 94 | */
|
---|
[7816] | 95 | public boolean hasExtend() {
|
---|
[8384] | 96 | return !Utils.equalsEpsilon(minEast, maxEast) || !Utils.equalsEpsilon(minNorth, maxNorth);
|
---|
[7816] | 97 | }
|
---|
[1722] | 98 | }
|
---|