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 Object implements IBounds
A BBox represents an area in lat/lon space. It is used for the quad tree. In contrast to a Bounds object, a BBox can represent an invalid (empty) area.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double
     
    protected double
     
    protected double
     
    protected double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new (invalid) BBox
    BBox(double x, double y)
    Constructs a new BBox 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 that this.bounds(ax,ay) and this.bounds(bx,by) will both return true
    Create BBox for a given latlon.
    Constructs a new BBox defined by points a and b.
    BBox(BBox copy)
    Constructs a new BBox from another one.
    Create BBox for a node.
    BBox(IWay<?> w)
    Create BBox for all nodes of the way with known coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    add(double x, double y)
    Extends this bbox to include the point (x, y)
    final void
    Add a point to an existing BBox.
    final void
    Add a point to an existing BBox.
    final 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
    Gets the area of the bbox.
    static boolean
    bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, Double maxDifference)
    Check if bboxes are functionally equal
    boolean
    bboxIsFunctionallyEqual(BBox other, Double maxDifference)
    Check if bboxes are functionally equal
    boolean
    Tests, whether the Point c lies within the bbox.
    boolean
    Tests, whether the bbox b lies completely inside this bbox.
    final boolean
     
    Returns the bottom-right point.
    double
    Returns the latitude of bottom-right point.
    double
    Returns the longitude of bottom-right point.
    Gets the center of this BBox.
    double
    Returns the bounds width.
    (package private) byte
    getIndex(int level)
     
    double
    Returns max latitude of bounds.
    double
    Returns max longitude of bounds.
    double
    Returns min latitude of bounds.
    double
    Returns min longitude of bounds.
    Returns the top-left point.
    double
    Returns the latitude of top-left point.
    double
    Returns the longitude of top-left point.
    double
    Returns the bounds width.
    final int
     
    double
    Gets the height of the bbox.
    boolean
    Tests, whether two BBoxes intersect as an area.
    boolean
    Determines if the bbox is valid and covers a part of the planet surface.
    boolean
    Determines if the bbox covers a part of the planet surface.
    protected void
    set(double xmin, double xmax, double ymin, double ymax)
     
    Returns an immutable version of this bbox, i.e., modifying calls throw an UnsupportedOperationException.
    Converts the bounds to a rectangle
     
    toStringCSV(String separator)
    Creates a CSV string for this bbox
    double
    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
  • Field Details

    • xmin

      protected double xmin
    • xmax

      protected double xmax
    • ymin

      protected double ymin
    • ymax

      protected double ymax
  • Constructor Details

    • BBox

      public BBox()
      Constructs a new (invalid) BBox
    • BBox

      public BBox(double x, double y)
      Constructs a new BBox defined by a single point.
      Parameters:
      x - X coordinate
      y - Y coordinate
      Since:
      6203
    • BBox

      public BBox(LatLon a, LatLon b)
      Constructs a new BBox defined by points a and b. Result is minimal BBox containing both points if they are both valid, else undefined
      Parameters:
      a - first point
      b - second point
    • BBox

      public BBox(BBox copy)
      Constructs a new BBox 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 coordinate
      y - Y coordinate
      r - size
      Since:
      13140
    • BBox

      public BBox(double ax, double ay, double bx, double by)
      Create minimal BBox so that this.bounds(ax,ay) and this.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
    • BBox

      public BBox(ILatLon ll)
      Create BBox for a given latlon. An invalid BBox is returned if the coordinates are not known.
      Parameters:
      ll - The lat lon position
  • Method Details

    • 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 or null, 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 coordinate
      y - 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 primitive
      extraSpace - 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 primitive
      extraSpace - 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 LatLon
      extraSpace - 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.
      Specified by:
      getHeight in 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.
      Specified by:
      getWidth in interface IBounds
      Returns:
      the bounds width
    • area

      public double area()
      Gets the area of the bbox.
      Returns:
      the area computed from width() and height()
    • bounds

      public boolean bounds(BBox b)
      Tests, whether the bbox b lies completely inside this bbox.
      Parameters:
      b - bounding box
      Returns:
      true if b lies completely inside this bbox
    • bounds

      public boolean bounds(LatLon c)
      Tests, whether the Point c lies within the bbox.
      Parameters:
      c - point
      Returns:
      true if c 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 for getMax().lat().
      Specified by:
      getMaxLat in interface IBounds
      Returns:
      max latitude of bounds.
    • 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 for getMin().lon().
      Specified by:
      getMinLon in interface IBounds
      Returns:
      min longitude of bounds.
    • 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 for getMin().lat().
      Specified by:
      getMinLat in interface IBounds
      Returns:
      min latitude of bounds.
    • 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 for getMax().lon().
      Specified by:
      getMaxLon in interface IBounds
      Returns:
      max longitude of bounds.
    • getCenter

      public LatLon getCenter()
      Gets the center of this BBox.
      Specified by:
      getCenter in interface IBounds
      Returns:
      The center.
    • getIndex

      byte getIndex(int level)
    • toRectangle

      Converts the bounds to a rectangle
      Returns:
      The rectangle in east/north space.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • bboxIsFunctionallyEqual

      public boolean bboxIsFunctionallyEqual(BBox other, Double maxDifference)
      Check if bboxes are functionally equal
      Parameters:
      other - The other bbox to compare with
      maxDifference - 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, Double maxDifference)
      Check if bboxes are functionally equal
      Parameters:
      bbox1 - A bbox to compare with another bbox
      bbox2 - The other bbox to compare with
      maxDifference - 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.
      Specified by:
      isValid in interface IBounds
      Returns:
      true if the bbox covers a part of the planet surface. Height and width must be non-negative, but may (both) be 0.
      Since:
      11269
    • 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 String toString()
      Overrides:
      toString in class Object
    • toStringCSV

      public String toStringCSV(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 an UnsupportedOperationException.
      Returns:
      an immutable version of this bbox
      Since:
      17862 (interface)