Class BBox

    • Nested Class Summary

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

      Fields 
      Modifier and Type Field Description
      protected double xmax  
      protected double xmin  
      protected double ymax  
      protected double ymin  
    • Constructor Summary

      Constructors 
      Constructor Description
      BBox()
      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
      BBox​(ILatLon ll)
      Create BBox for a given latlon.
      BBox​(LatLon a, LatLon b)
      Constructs a new BBox defined by points a and b.
      BBox​(BBox copy)
      Constructs a new BBox 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.
    • Field Detail

      • xmin

        protected double xmin
      • xmax

        protected double xmax
      • ymin

        protected double ymin
      • ymax

        protected double ymax
    • Constructor Detail

      • 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 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 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

        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 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.
      • getIndex

        byte getIndex​(int level)
      • toRectangle

        public Rectangle2D toRectangle()
        Converts the bounds to a rectangle
        Returns:
        The rectangle in east/north space.
      • 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
      • toStringCSV

        public String toStringCSV​(String separator)
        Creates a CSV string for this bbox
        Parameters:
        separator - The separator to use
        Returns:
        A string