source: josm/trunk/src/org/openstreetmap/josm/data/IBounds.java

Last change on this file was 17710, checked in by simon04, 3 years ago

Checkstyle

File size: 3.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import org.openstreetmap.josm.data.coor.ILatLon;
5import org.openstreetmap.josm.data.coor.LatLon;
6
7/**
8 * Represents a "rectangular" area of the world, given in lat/lon min/max values.
9 *
10 * @since 17703
11 */
12public interface IBounds {
13
14 /**
15 * Gets the point that has both the minimal lat and lon coordinate
16 *
17 * @return The point
18 */
19 default ILatLon getMin() {
20 return new LatLon(getMinLat(), getMinLon());
21 }
22
23 /**
24 * Returns min latitude of bounds. Efficient shortcut for {@code getMin().lat()}.
25 *
26 * @return min latitude of bounds.
27 */
28 double getMinLat();
29
30 /**
31 * Returns min longitude of bounds. Efficient shortcut for {@code getMin().lon()}.
32 *
33 * @return min longitude of bounds.
34 */
35 double getMinLon();
36
37 /**
38 * Gets the point that has both the maximum lat and lon coordinate
39 *
40 * @return The point
41 */
42 default ILatLon getMax() {
43 return new LatLon(getMaxLat(), getMaxLon());
44 }
45
46 /**
47 * Returns max latitude of bounds. Efficient shortcut for {@code getMax().lat()}.
48 *
49 * @return max latitude of bounds.
50 */
51 double getMaxLat();
52
53 /**
54 * Returns max longitude of bounds. Efficient shortcut for {@code getMax().lon()}.
55 *
56 * @return max longitude of bounds.
57 */
58 double getMaxLon();
59
60 /**
61 * Returns center of the bounding box.
62 *
63 * @return Center of the bounding box.
64 */
65 ILatLon getCenter();
66
67 /**
68 * Determines if the given point {@code ll} is within these bounds.
69 * <p>
70 * Points with unknown coordinates are always outside the coordinates.
71 *
72 * @param ll The lat/lon to check
73 * @return {@code true} if {@code ll} is within these bounds, {@code false} otherwise
74 */
75 default boolean contains(ILatLon ll) {
76 return getMinLon() <= ll.lon() && ll.lon() <= getMaxLon()
77 && getMinLat() <= ll.lat() && ll.lat() <= getMaxLat();
78 }
79
80 /**
81 * Tests, whether the bbox {@code b} lies completely inside this bbox.
82 *
83 * @param b bounding box
84 * @return {@code true} if {@code b} lies completely inside this bbox
85 */
86 default boolean contains(IBounds b) {
87 return getMinLon() <= b.getMinLon() && getMaxLon() >= b.getMaxLon()
88 && getMinLat() <= b.getMinLat() && getMaxLat() >= b.getMaxLat();
89 }
90
91 /**
92 * The two bounds intersect? Compared to java Shape.intersects, if does not use
93 * the interior but the closure. ("&gt;=" instead of "&gt;")
94 *
95 * @param b other bounds
96 * @return {@code true} if the two bounds intersect
97 */
98 default boolean intersects(IBounds b) {
99 return getMinLon() <= b.getMaxLon() && getMaxLon() >= b.getMinLon()
100 && getMinLat() <= b.getMaxLat() && getMaxLat() >= b.getMinLat();
101 }
102
103 /**
104 * Returns the bounds width.
105 *
106 * @return the bounds width
107 */
108 double getHeight();
109
110 /**
111 * Returns the bounds width.
112 *
113 * @return the bounds width
114 */
115 double getWidth();
116
117 /**
118 * Gets the area of this bounds (in lat/lon space)
119 *
120 * @return The area
121 */
122 default double getArea() {
123 return getWidth() * getHeight();
124 }
125
126 /**
127 * Determines if the bbox covers a part of the planet surface.
128 *
129 * @return true if the bbox covers a part of the planet surface.
130 * Height and width must be non-negative, but may (both) be 0.
131 */
132 default boolean isValid() {
133 return true;
134 }
135
136 /**
137 * Determines if this Bounds object crosses the 180th Meridian.
138 * See http://wiki.openstreetmap.org/wiki/180th_meridian
139 *
140 * @return true if this Bounds object crosses the 180th Meridian.
141 */
142 default boolean crosses180thMeridian() {
143 return false;
144 }
145}
Note: See TracBrowser for help on using the repository browser.