source: josm/trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java@ 9171

Last change on this file since 9171 was 8927, checked in by Don-vip, 8 years ago

fix #11998 - add two new protected boolean members to simplify customization of OSM download task for plugins + fix some javadoc/sonar issues

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
5import 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 */
13public 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. ("&gt;=" instead of "&gt;")
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 /**
92 * Determines if the bounds area is not null
93 * @return {@code true} if the area is not null
94 */
95 public boolean hasExtend() {
96 return !Utils.equalsEpsilon(minEast, maxEast) || !Utils.equalsEpsilon(minNorth, maxNorth);
97 }
98}
Note: See TracBrowser for help on using the repository browser.