Package com.geodesk.geom
Class Box
java.lang.Object
com.geodesk.geom.Box
- All Implemented Interfaces:
Bounds
- Direct Known Subclasses:
BoundedItem
,RTree.Node
An axis-aligned bounding box. A `Box` represents minimum and maximum
X and Y coordinates in a Mercator-projected plane. It can straddle the
Antimeridian (in which case `minX` is *larger* than `maxX`). A `Box` can
also be empty (in which case `minY` is *larger* than `maxY`)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Box
atLonLat
(double lon, double lat) Creates a `Box` that covers a single point.static Box
atXY
(int x, int y) Creates a `Box` that covers a single point.void
buffer
(int b) Expands or contracts all sides of this bounding box by a specified number of imps.void
bufferMeters
(double m) Expands or contracts all sides of this bounding box by a specified number of meters.boolean
Returns `true` if this bounding box straddles the Antimeridian.boolean
void
expandToInclude
(int[] coords) void
expandToInclude
(int x, int y) Checks if this bounding box includes the given coordinate, and expands it if necessary.void
expandToInclude
(int otherMinX, int otherMinY, int otherMaxX, int otherMaxY) Checks if this bounding box includes another bounding box, and expands it if necessary.void
Checks if this bounding box includes another bounding box, and expands it if necessary.static Box
fromEnvelope
(Envelope env) static Box
Creates a Box from a string that specifies four coordinates (west, south, east, north), in degrees longitude/latitude.int
hashCode()
static Box
impsAroundXY
(int d, int x, int y) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.Creates a new bounding box that is the result of the intersection between this bounding box and another.static Box
intersection
(Bounds a, Bounds b) boolean
isNull()
Returns `true` if this bounding box is empty.static boolean
int
maxX()
int
maxY()
static Box
metersAround
(double meters, Bounds other) Creates a bounding box whose sides are extended by a specific distance relative to another bounding box.static Box
metersAroundLonLat
(double meters, double lon, double lat) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.static Box
metersAroundXY
(double meters, int x, int y) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.int
minX()
int
minY()
static Box
static Box
of
(LineSegment seg) static Box
ofWorld()
Creates a bounding box that covers the entire world.static Box
ofWSEN
(double west, double south, double east, double north) static Box
ofXYWidthHeight
(int x, int y, int w, int h) static Box
ofXYXY
(int x1, int y1, int x2, int y2) void
setNull()
static Bounds
Creates a JTSEnvelope
with the same dimensions as this bounding box.toGeometry
(GeometryFactory factory) toString()
void
translate
(int deltaX, int deltaY) Moves the bounding box horizontally and vertically by the specified number of units.
-
Constructor Details
-
Box
public Box()Creates a null Box. -
Box
public Box(int minX, int minY, int maxX, int maxY) -
Box
-
Box
public Box(int x, int y)
-
-
Method Details
-
setNull
public void setNull() -
crossesAntimeridian
public boolean crossesAntimeridian()Returns `true` if this bounding box straddles the Antimeridian.- Returns:
- `true` if `minX` and `maxX` lie on different sides of the Antimeridian
-
isNull
public boolean isNull()Returns `true` if this bounding box is empty.- Returns:
- `true` if this is an empty bounding box (`maxY` is less than `minY`)
-
isNull
-
minX
public int minX() -
minY
public int minY() -
maxX
public int maxX() -
maxY
public int maxY() -
expandToInclude
public void expandToInclude(int x, int y) Checks if this bounding box includes the given coordinate, and expands it if necessary. If this bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).- Parameters:
x
- X-coordinatey
- Y-coordinate
-
expandToInclude
Checks if this bounding box includes another bounding box, and expands it if necessary. If either bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).- Parameters:
b
- the bounding box to include into this
-
expandToInclude
public void expandToInclude(int otherMinX, int otherMinY, int otherMaxX, int otherMaxY) Checks if this bounding box includes another bounding box, and expands it if necessary. If either bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).- Parameters:
otherMinX
- minimum X-coordinate of the other bounding boxotherMinY
- minimum Y-coordinate of the other bounding boxotherMaxX
- maximum X-coordinate of the other bounding boxotherMaxY
- maximum Y-coordinate of the other bounding box
-
expandToInclude
public void expandToInclude(int[] coords) -
toEnvelope
Creates a JTSEnvelope
with the same dimensions as this bounding box.- Returns:
- a new `Envelope`
-
equals
-
hashCode
public int hashCode() -
intersection
Creates a new bounding box that is the result of the intersection between this bounding box and another.- Parameters:
o
- the other bounding box- Returns:
- new Box
-
intersection
-
smaller
-
buffer
public void buffer(int b) Expands or contracts all sides of this bounding box by a specified number of imps. If the bounding box is empty, the result is undefined.- Parameters:
b
- the buffer (in imps)
-
bufferMeters
public void bufferMeters(double m) Expands or contracts all sides of this bounding box by a specified number of meters. If the bounding box is empty, the result is undefined.- Parameters:
m
- the buffer (in meters)
-
translate
public void translate(int deltaX, int deltaY) Moves the bounding box horizontally and vertically by the specified number of units. Attempts to move the box beyond the cut-offs in the polar regions result in the box being trimmed. If the bounding box is empty, the result is undefined.- Parameters:
deltaX
- X-offset (imps)deltaY
- Y-offset (imps)
-
toString
-
ofWSEN
-
atLonLat
Creates a `Box` that covers a single point.- Parameters:
lon
- the longitude of the pointlat
- the latitude of the point- Returns:
- a `Box` that is 1 imp wide and 1 imp tall
-
atXY
Creates a `Box` that covers a single point.- Parameters:
x
- X-coordinate (Mercator-projected) of the pointy
- Y-coordinate (Mercator-projected) of the point- Returns:
- a `Box` that is 1 imp wide and 1 imp tall
-
ofXYXY
-
ofXYWidthHeight
-
metersAroundXY
Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.- Parameters:
meters
- the distance (in meters) by which each side of the original bounds are bufferedx
- X-coordinate of the center point (Mercator-projected)y
- Y-coordinate of the center point (Mercator-projected)- Returns:
- a new bounding box
-
impsAroundXY
Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.- Parameters:
d
- the distance (in imps) by which each side of the original bounds are bufferedx
- X-coordinate of the center point (Mercator-projected)y
- Y-coordinate of the center point (Mercator-projected)- Returns:
- a new bounding box
-
metersAroundLonLat
Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.- Parameters:
meters
- the distance (in meters) by which each side of the original bounds are bufferedlon
- longitude of the center pointlat
- latitude of the center point- Returns:
- a new bounding box
-
metersAround
Creates a bounding box whose sides are extended by a specific distance relative to another bounding box.- Parameters:
meters
- the distance (in meters) by which each side of the original bounds are bufferedother
- the original bounding box- Returns:
- a new bounding box
-
fromEnvelope
-
of
-
of
-
fromWSEN
Creates a Box from a string that specifies four coordinates (west, south, east, north), in degrees longitude/latitude.- Parameters:
s
- the string (e.g. `2.2,48.8,2.5,18.9`)- Returns:
- a new bounding box
-
ofWorld
Creates a bounding box that covers the entire world.- Returns:
- a new bounding box
-
toGeometry
-