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 aBounds
object, a BBox can represent an invalid (empty) area.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BBox.Immutable
-
Constructor Summary
Constructors Constructor Description BBox()
Constructs a new (invalid) BBoxBBox(double x, double y)
Constructs a newBBox
defined 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 newBBox
defined by pointsa
andb
.BBox(BBox copy)
Constructs a newBBox
from 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 void
add(double x, double y)
Extends this bbox to include the point (x, y)void
add(ILatLon c)
Add a point to an existing BBox.void
add(LatLon c)
Add a point to an existing BBox.void
add(BBox other)
Extends this bbox to include the bbox other.void
addLatLon(LatLon latLon, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.void
addPrimitive(IPrimitive primitive, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.void
addPrimitive(OsmPrimitive primitive, double extraSpace)
Extends this bbox to include the bbox of the primitive extended by extraSpace.double
area()
Gets the area of the bbox.static boolean
bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, java.lang.Double maxDifference)
Check if bboxes are functionally equalboolean
bboxIsFunctionallyEqual(BBox other, java.lang.Double maxDifference)
Check if bboxes are functionally equalboolean
bounds(LatLon c)
Tests, whether the Pointc
lies within the bbox.boolean
bounds(BBox b)
Tests, whether the bboxb
lies completely inside this bbox.boolean
equals(java.lang.Object o)
LatLon
getBottomRight()
Returns the bottom-right point.double
getBottomRightLat()
Returns the latitude of bottom-right point.double
getBottomRightLon()
Returns the longitude of bottom-right point.LatLon
getCenter()
Gets the center of this BBox.double
getHeight()
Returns the bounds width.(package private) byte
getIndex(int level)
double
getMaxLat()
Returns max latitude of bounds.double
getMaxLon()
Returns max longitude of bounds.double
getMinLat()
Returns min latitude of bounds.double
getMinLon()
Returns min longitude of bounds.LatLon
getTopLeft()
Returns the top-left point.double
getTopLeftLat()
Returns the latitude of top-left point.double
getTopLeftLon()
Returns the longitude of top-left point.double
getWidth()
Returns the bounds width.int
hashCode()
double
height()
Gets the height of the bbox.boolean
intersects(BBox b)
Tests, whether two BBoxes intersect as an area.boolean
isInWorld()
Determines if the bbox is valid and covers a part of the planet surface.boolean
isValid()
Determines if the bbox covers a part of the planet surface.protected void
set(double xmin, double xmax, double ymin, double ymax)
BBox
toImmutable()
Returns an immutable version of this bbox, i.e., modifying calls throw anUnsupportedOperationException
.java.awt.geom.Rectangle2D
toRectangle()
Converts the bounds to a rectanglejava.lang.String
toString()
java.lang.String
toStringCSV(java.lang.String separator)
Creates a CSV string for this bboxdouble
width()
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 newBBox
defined by a single point.- Parameters:
x
- X coordinatey
- Y coordinate- Since:
- 6203
-
BBox
public BBox(LatLon a, LatLon b)
Constructs a newBBox
defined by pointsa
andb
. 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 newBBox
from 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:IBounds
Returns 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:IBounds
Returns the bounds width.
-
area
public double area()
Gets the area of the bbox.
-
bounds
public boolean bounds(BBox b)
Tests, whether the bboxb
lies completely inside this bbox.- Parameters:
b
- bounding box- Returns:
true
ifb
lies completely inside this bbox
-
bounds
public boolean bounds(LatLon c)
Tests, whether the Pointc
lies within the bbox.- Parameters:
c
- point- Returns:
true
ifc
lies 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:
true
if 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:IBounds
Returns 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:IBounds
Returns 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:IBounds
Returns 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:IBounds
Returns 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:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equals
in 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:
toString
in 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)
-
-