Package com.geodesk.core
Class Box
java.lang.Object
com.geodesk.core.Box
- All Implemented Interfaces:
com.geodesk.geom.Bounds
An axis-aligned bounding box. A `Box` represents minimum and maximum
X and Y coordinates in a Mercator-projected plane. It can straddle the
Antimeriaian (in which case `minX` is *larger* than `maxX`). A `Box` can
also be empty (in which case `minY` is *larger* than `maxY`)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BoxatLonLat(double lon, double lat) Creates a `Box` that covers a single point.static BoxatXY(int x, int y) Creates a `Box` that covers a single point.voidbuffer(int b) Expands or contracts all sides of this bounding box by a specified number of imps.voidbufferMeters(double m) Expands or contracts all sides of this bounding box by a specified number of meters.booleanReturns `true` if this bounding box straddles the Antimeridian.booleanvoidexpandToInclude(int[] coords) voidexpandToInclude(int x, int y) Checks if this bounding box includes the given coordinate, and expands it if necessary.voidexpandToInclude(int otherMinX, int otherMinY, int otherMaxX, int otherMaxY) Checks if this bounding box includes another bounding box, and expands it if necessary.voidexpandToInclude(com.geodesk.geom.Bounds b) Checks if this bounding box includes another bounding box, and expands it if necessary.static BoxfromEnvelope(Envelope env) static BoxCreates a Box from a string that specifies four coordinates (west, south, east, north), in degrees longitude/latitude.inthashCode()static BoximpsAroundXY(int d, int x, int y) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.intersection(com.geodesk.geom.Bounds o) Creates a new bounding box that is the result of the intersection between this bounding box and another.booleanisNull()Returns `true` if this bounding box is empty.intmaxX()intmaxY()static BoxmetersAround(double meters, com.geodesk.geom.Bounds other) Creates a bounding box whose sides are extended by a specific distance relative to another bounding box.static BoxmetersAroundLonLat(double meters, double lon, double lat) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.static BoxmetersAroundXY(double meters, int x, int y) Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.intminX()intminY()static Boxstatic Boxof(LineSegment seg) static BoxofWorld()Creates a bounding box that covers the entire world.static BoxofWSEN(double west, double south, double east, double north) static BoxofXYWidthHeight(int x, int y, int w, int h) static BoxofXYXY(int x1, int y1, int x2, int y2) voidsetNull()Creates a JTSEnvelopewith the same dimensions as this bounding box.toGeometry(GeometryFactory factory) toString()voidtranslate(int deltaX, int deltaY) Moves the bounding box horizontally and vertically by the specified number of units.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.geodesk.geom.Bounds
area, centerX, centerY, contains, contains, height, intersects, width
-
Constructor Details
-
Box
public Box()Creates a null Box. -
Box
public Box(int minX, int minY, int maxX, int maxY) -
Box
public Box(com.geodesk.geom.Bounds b) -
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`)
-
minX
public int minX()- Specified by:
minXin interfacecom.geodesk.geom.Bounds
-
minY
public int minY()- Specified by:
minYin interfacecom.geodesk.geom.Bounds
-
maxX
public int maxX()- Specified by:
maxXin interfacecom.geodesk.geom.Bounds
-
maxY
public int maxY()- Specified by:
maxYin interfacecom.geodesk.geom.Bounds
-
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
public void expandToInclude(com.geodesk.geom.Bounds b) 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 JTSEnvelopewith 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
-
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
-