Package org.openstreetmap.josm.data.osm
Class BBox
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.BBox
-
- All Implemented Interfaces:
IBounds
- Direct Known Subclasses:
BBox.Immutable,QuadBuckets.QBLevel
public class BBox extends java.lang.Object implements IBounds
A BBox represents an area in lat/lon space. It is used for the quad tree. In contrast to aBoundsobject, a BBox can represent an invalid (empty) area.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBBox.Immutable
-
Constructor Summary
Constructors Constructor Description BBox()Constructs a new (invalid) BBoxBBox(double x, double y)Constructs a newBBoxdefined by a single point.BBox(double x, double y, double r)Creates bbox around the coordinate (x, y).BBox(double ax, double ay, double bx, double by)Create minimal BBox so thatthis.bounds(ax,ay)andthis.bounds(bx,by)will both return trueBBox(ILatLon ll)Create BBox for a given latlon.BBox(LatLon a, LatLon b)Constructs a newBBoxdefined by pointsaandb.BBox(BBox copy)Constructs a newBBoxfrom another one.BBox(INode n)Create BBox for a node.BBox(IWay<?> w)Create BBox for all nodes of the way with known coordinates.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(double x, double y)Extends this bbox to include the point (x, y)voidadd(ILatLon c)Add a point to an existing BBox.voidadd(LatLon c)Add a point to an existing BBox.voidadd(BBox other)Extends this bbox to include the bbox other.voidaddLatLon(LatLon latLon, double extraSpace)Extends this bbox to include the bbox of the primitive extended by extraSpace.voidaddPrimitive(IPrimitive primitive, double extraSpace)Extends this bbox to include the bbox of the primitive extended by extraSpace.voidaddPrimitive(OsmPrimitive primitive, double extraSpace)Extends this bbox to include the bbox of the primitive extended by extraSpace.doublearea()Gets the area of the bbox.static booleanbboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, java.lang.Double maxDifference)Check if bboxes are functionally equalbooleanbboxIsFunctionallyEqual(BBox other, java.lang.Double maxDifference)Check if bboxes are functionally equalbooleanbounds(LatLon c)Tests, whether the Pointclies within the bbox.booleanbounds(BBox b)Tests, whether the bboxblies completely inside this bbox.booleanequals(java.lang.Object o)LatLongetBottomRight()Returns the bottom-right point.doublegetBottomRightLat()Returns the latitude of bottom-right point.doublegetBottomRightLon()Returns the longitude of bottom-right point.LatLongetCenter()Gets the center of this BBox.doublegetHeight()Returns the bounds width.(package private) bytegetIndex(int level)doublegetMaxLat()Returns max latitude of bounds.doublegetMaxLon()Returns max longitude of bounds.doublegetMinLat()Returns min latitude of bounds.doublegetMinLon()Returns min longitude of bounds.LatLongetTopLeft()Returns the top-left point.doublegetTopLeftLat()Returns the latitude of top-left point.doublegetTopLeftLon()Returns the longitude of top-left point.doublegetWidth()Returns the bounds width.inthashCode()doubleheight()Gets the height of the bbox.booleanintersects(BBox b)Tests, whether two BBoxes intersect as an area.booleanisInWorld()Determines if the bbox is valid and covers a part of the planet surface.booleanisValid()Determines if the bbox covers a part of the planet surface.protected voidset(double xmin, double xmax, double ymin, double ymax)BBoxtoImmutable()Returns an immutable version of this bbox, i.e., modifying calls throw anUnsupportedOperationException.java.awt.geom.Rectangle2DtoRectangle()Converts the bounds to a rectanglejava.lang.StringtoString()java.lang.StringtoStringCSV(java.lang.String separator)Creates a CSV string for this bboxdoublewidth()Gets the width of the bbox.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.IBounds
contains, contains, crosses180thMeridian, getArea, getMax, getMin, intersects
-
-
-
-
Constructor Detail
-
BBox
public BBox()
Constructs a new (invalid) BBox
-
BBox
public BBox(double x, double y)
Constructs a newBBoxdefined by a single point.- Parameters:
x- X coordinatey- Y coordinate- Since:
- 6203
-
BBox
public BBox(LatLon a, LatLon b)
Constructs a newBBoxdefined by pointsaandb. Result is minimal BBox containing both points if they are both valid, else undefined- Parameters:
a- first pointb- second point
-
BBox
public BBox(BBox copy)
Constructs a newBBoxfrom another one.- Parameters:
copy- the BBox to copy
-
BBox
public BBox(double x, double y, double r)
Creates bbox around the coordinate (x, y). Coordinate defines center of bbox, its edge will be 2*r.- Parameters:
x- X coordinatey- Y coordinater- size- Since:
- 13140
-
BBox
public BBox(double ax, double ay, double bx, double by)
Create minimal BBox so thatthis.bounds(ax,ay)andthis.bounds(bx,by)will both return true- Parameters:
ax- left or right X value (-180 .. 180)ay- top or bottom Y value (-90 .. 90)bx- left or right X value (-180 .. 180)by- top or bottom Y value (-90 .. 90)
-
BBox
public BBox(IWay<?> w)
Create BBox for all nodes of the way with known coordinates. If no node has a known coordinate, an invalid BBox is returned.- Parameters:
w- the way
-
BBox
public BBox(INode n)
Create BBox for a node. An invalid BBox is returned if the coordinates are not known.- Parameters:
n- the node
-
-
Method Detail
-
add
public final void add(LatLon c)
Add a point to an existing BBox. Extends this bbox if necessary so that this.bounds(c) will return true if c is a valid LatLon instance. Kept for binary compatibility- Parameters:
c- a LatLon point
-
add
public final void add(ILatLon c)
Add a point to an existing BBox. Extends this bbox if necessary so that this.bounds(c) will return true if c is a valid LatLon instance. If it is invalid ornull, this call is ignored.- Parameters:
c- a LatLon point.
-
add
public final void add(double x, double y)
Extends this bbox to include the point (x, y)- Parameters:
x- X coordinatey- Y coordinate
-
add
public final void add(BBox other)
Extends this bbox to include the bbox other. Does nothing if other is not valid.- Parameters:
other- a bbox
-
set
protected void set(double xmin, double xmax, double ymin, double ymax)
-
addPrimitive
public void addPrimitive(OsmPrimitive primitive, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.- Parameters:
primitive- an OSM primitiveextraSpace- the value to extend the primitives bbox. Unit is in LatLon degrees.
-
addPrimitive
public void addPrimitive(IPrimitive primitive, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.- Parameters:
primitive- an primitiveextraSpace- the value to extend the primitives bbox. Unit is in LatLon degrees.- Since:
- 17862
-
addLatLon
public void addLatLon(LatLon latLon, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.- Parameters:
latLon- a LatLonextraSpace- the value to extend the primitives bbox. Unit is in LatLon degrees.- Since:
- 15877
-
height
public double height()
Gets the height of the bbox.- Returns:
- The difference between ymax and ymin. 0 for invalid bboxes.
-
getHeight
public double getHeight()
Description copied from interface:IBoundsReturns the bounds width.
-
width
public double width()
Gets the width of the bbox.- Returns:
- The difference between xmax and xmin. 0 for invalid bboxes.
-
getWidth
public double getWidth()
Description copied from interface:IBoundsReturns the bounds width.
-
area
public double area()
Gets the area of the bbox.
-
bounds
public boolean bounds(BBox b)
Tests, whether the bboxblies completely inside this bbox.- Parameters:
b- bounding box- Returns:
trueifblies completely inside this bbox
-
bounds
public boolean bounds(LatLon c)
Tests, whether the Pointclies within the bbox.- Parameters:
c- point- Returns:
trueifclies within the bbox
-
intersects
public boolean intersects(BBox b)
Tests, whether two BBoxes intersect as an area. I.e. whether there exists a point that lies in both of them.- Parameters:
b- other bounding box- Returns:
trueif this bbox intersects with the other
-
getTopLeft
public LatLon getTopLeft()
Returns the top-left point.- Returns:
- The top-left point
-
getTopLeftLat
public double getTopLeftLat()
Returns the latitude of top-left point.- Returns:
- The latitude of top-left point
- Since:
- 6203
-
getMaxLat
public double getMaxLat()
Description copied from interface:IBoundsReturns max latitude of bounds. Efficient shortcut forgetMax().lat().
-
getTopLeftLon
public double getTopLeftLon()
Returns the longitude of top-left point.- Returns:
- The longitude of top-left point
- Since:
- 6203
-
getMinLon
public double getMinLon()
Description copied from interface:IBoundsReturns min longitude of bounds. Efficient shortcut forgetMin().lon().
-
getBottomRight
public LatLon getBottomRight()
Returns the bottom-right point.- Returns:
- The bottom-right point
-
getBottomRightLat
public double getBottomRightLat()
Returns the latitude of bottom-right point.- Returns:
- The latitude of bottom-right point
- Since:
- 6203
-
getMinLat
public double getMinLat()
Description copied from interface:IBoundsReturns min latitude of bounds. Efficient shortcut forgetMin().lat().
-
getBottomRightLon
public double getBottomRightLon()
Returns the longitude of bottom-right point.- Returns:
- The longitude of bottom-right point
- Since:
- 6203
-
getMaxLon
public double getMaxLon()
Description copied from interface:IBoundsReturns max longitude of bounds. Efficient shortcut forgetMax().lon().
-
getIndex
byte getIndex(int level)
-
toRectangle
public java.awt.geom.Rectangle2D toRectangle()
Converts the bounds to a rectangle- Returns:
- The rectangle in east/north space.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
bboxIsFunctionallyEqual
public boolean bboxIsFunctionallyEqual(BBox other, java.lang.Double maxDifference)
Check if bboxes are functionally equal- Parameters:
other- The other bbox to compare withmaxDifference- The maximum difference (in degrees) between the bboxes. May be null.- Returns:
- true if they are functionally equivalent
- Since:
- 15486
-
bboxesAreFunctionallyEqual
public static boolean bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, java.lang.Double maxDifference)
Check if bboxes are functionally equal- Parameters:
bbox1- A bbox to compare with another bboxbbox2- The other bbox to compare withmaxDifference- The maximum difference (in degrees) between the bboxes. May be null.- Returns:
- true if they are functionally equivalent
- Since:
- 15483
-
isValid
public boolean isValid()
Determines if the bbox covers a part of the planet surface.
-
isInWorld
public boolean isInWorld()
Determines if the bbox is valid and covers a part of the planet surface.- Returns:
- true if the bbox is valid and covers a part of the planet surface
- Since:
- 11269
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toStringCSV
public java.lang.String toStringCSV(java.lang.String separator)
Creates a CSV string for this bbox- Parameters:
separator- The separator to use- Returns:
- A string
-
toImmutable
public BBox toImmutable()
Returns an immutable version of this bbox, i.e., modifying calls throw anUnsupportedOperationException.- Returns:
- an immutable version of this bbox
- Since:
- 17862 (interface)
-
-