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

Last change on this file since 11788 was 11774, checked in by Don-vip, 7 years ago

fix #13922 - zoom only once when downloading several data types

  • Property svn:eol-style set to native
File size: 4.7 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[1722]2package org.openstreetmap.josm.data;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
[8384]5import 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 */
13public class ProjectionBounds {
14 /**
[9243]15 * The minimum east coordinate.
[1722]16 */
[9243]17 public double minEast;
18 /**
19 * The minimum north coordinate.
20 */
21 public double minNorth;
22 /**
23 * The maximum east coordinate.
24 */
25 public double maxEast;
26 /**
27 * The minimum north coordinate.
28 */
29 public double maxNorth;
[1722]30
31 /**
[5670]32 * Construct bounds out of two points.
[9243]33 * @param min min east/north
34 * @param max max east/north
[1722]35 */
36 public ProjectionBounds(EastNorth min, EastNorth max) {
[4065]37 this.minEast = min.east();
38 this.minNorth = min.north();
39 this.maxEast = max.east();
40 this.maxNorth = max.north();
[1722]41 }
[8384]42
[9243]43 /**
44 * Construct bounds out of a single point.
45 * @param p east/north
46 */
[1724]47 public ProjectionBounds(EastNorth p) {
[4065]48 this.minEast = this.maxEast = p.east();
49 this.minNorth = this.maxNorth = p.north();
[1724]50 }
[8384]51
[9243]52 /**
53 * Construct bounds out of a center point and east/north dimensions.
54 * @param center center east/north
55 * @param east east dimension
56 * @param north north dimension
57 */
[1722]58 public ProjectionBounds(EastNorth center, double east, double north) {
[4065]59 this.minEast = center.east()-east/2.0;
60 this.minNorth = center.north()-north/2.0;
61 this.maxEast = center.east()+east/2.0;
62 this.maxNorth = center.north()+north/2.0;
[1722]63 }
[8384]64
[9243]65 /**
66 * Construct bounds out of two points.
67 * @param minEast min east
68 * @param minNorth min north
69 * @param maxEast max east
70 * @param maxNorth max north
71 */
[4065]72 public ProjectionBounds(double minEast, double minNorth, double maxEast, double maxNorth) {
73 this.minEast = minEast;
74 this.minNorth = minNorth;
75 this.maxEast = maxEast;
76 this.maxNorth = maxNorth;
77 }
[8384]78
[9243]79 /**
80 * Extends bounds to include point {@code e}.
81 * @param e east/north to include
82 */
[8384]83 public void extend(EastNorth e) {
[4065]84 if (e.east() < minEast) {
85 minEast = e.east();
86 }
87 if (e.east() > maxEast) {
88 maxEast = e.east();
89 }
90 if (e.north() < minNorth) {
91 minNorth = e.north();
92 }
93 if (e.north() > maxNorth) {
94 maxNorth = e.north();
95 }
[1722]96 }
[8384]97
[9243]98 /**
[11774]99 * Extends bounds to include bounds {@code b}.
100 * @param b bounds to include
101 * @since 11774
102 */
103 public void extend(ProjectionBounds b) {
104 if (b.minEast < minEast) {
105 minEast = b.minEast;
106 }
107 if (b.maxEast > maxEast) {
108 maxEast = b.maxEast;
109 }
110 if (b.minNorth < minNorth) {
111 minNorth = b.minNorth;
112 }
113 if (b.maxNorth > maxNorth) {
114 maxNorth = b.maxNorth;
115 }
116 }
117
118 /**
[9243]119 * Returns the center east/north.
120 * @return the center east/north
121 */
[8384]122 public EastNorth getCenter() {
[4065]123 return new EastNorth((minEast + maxEast) / 2.0, (minNorth + maxNorth) / 2.0);
[1722]124 }
[1724]125
[8384]126 @Override
127 public String toString() {
[10300]128 return "ProjectionBounds["+minEast+','+minNorth+','+maxEast+','+maxNorth+']';
[1724]129 }
[4065]130
131 /**
132 * The two bounds intersect? Compared to java Shape.intersects, if does not use
[6830]133 * the interior but the closure. ("&gt;=" instead of "&gt;")
[9243]134 * @param b projection bounds
135 * @return {@code true} if the two bounds intersect
[4065]136 */
137 public boolean intersects(ProjectionBounds b) {
138 return b.maxEast >= minEast &&
139 b.maxNorth >= minNorth &&
140 b.minEast <= maxEast &&
141 b.minNorth <= maxNorth;
142 }
143
[9243]144 /**
[9419]145 * Check, if a point is within the bounds.
146 * @param en the point
147 * @return true, if <code>en</code> is within the bounds
148 */
149 public boolean contains(EastNorth en) {
150 return minEast <= en.east() && en.east() <= maxEast &&
151 minNorth <= en.north() && en.north() <= maxNorth;
152 }
153
154 /**
[9243]155 * Returns the min east/north.
156 * @return the min east/north
157 */
[4065]158 public EastNorth getMin() {
159 return new EastNorth(minEast, minNorth);
160 }
161
[9243]162 /**
163 * Returns the max east/north.
164 * @return the max east/north
165 */
[4065]166 public EastNorth getMax() {
167 return new EastNorth(maxEast, maxNorth);
168 }
169
[8927]170 /**
171 * Determines if the bounds area is not null
172 * @return {@code true} if the area is not null
173 */
[7816]174 public boolean hasExtend() {
[8384]175 return !Utils.equalsEpsilon(minEast, maxEast) || !Utils.equalsEpsilon(minNorth, maxNorth);
[7816]176 }
[1722]177}
Note: See TracBrowser for help on using the repository browser.