Class Bounds

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double maxLat
      The minimum and maximum coordinates.
      private double maxLon
      The minimum and maximum coordinates.
      private double minLat
      The minimum and maximum coordinates.
      private double minLon
      The minimum and maximum coordinates.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bounds​(double... coords)
      Constructs bounds out of two points.
      Bounds​(double[] coords, boolean roundToOsmPrecision)
      Constructs bounds out of two points.
      Bounds​(double lat, double lon, boolean roundToOsmPrecision)
      Single point Bounds defined by point [lat,lon].
      Bounds​(double minLat, double minLon, double maxLat, double maxLon)
      Constructs bounds out of two points.
      Bounds​(double minLat, double minLon, double maxLat, double maxLon, boolean roundToOsmPrecision)
      Constructs bounds out of two points.
      Bounds​(java.awt.geom.Rectangle2D rect)
      Creates new Bounds from a rectangle.
      Bounds​(java.lang.String asString, java.lang.String separator)
      Bounds​(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod)
      Parse the bounds from a given string and round to OSM precision
      Bounds​(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod, boolean roundToOsmPrecision)
      Parse the bounds from a given string
      Bounds​(Bounds other)
      Creates new Bounds from an existing one.
      Bounds​(LatLon b)
      Constructs bounds out a single point.
      Bounds​(LatLon b, boolean roundToOsmPrecision)
      Single point Bounds defined by lat/lon b.
      Bounds​(LatLon center, double latExtent, double lonExtent)
      Creates new bounds around a coordinate pair center.
      Bounds​(LatLon min, LatLon max)
      Construct bounds out of two points.
      Bounds​(LatLon min, LatLon max, boolean roundToOsmPrecision)
      Constructs bounds out of two points.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.geom.Rectangle2D.Double asRect()
      Converts the lat/lon bounding box to an object of type Rectangle2D.Double
      boolean contains​(ILatLon ll)
      Determines if the given point ll is within these bounds.
      boolean contains​(LatLon ll)
      Determines if the given point ll is within these bounds.
      boolean crosses180thMeridian()
      Determines if this Bounds object crosses the 180th Meridian.
      java.lang.String encodeAsString​(java.lang.String separator)
      Encodes this as a string so that it may be parsed using the Bounds.ParseMethod.MINLAT_MINLON_MAXLAT_MAXLON order
      boolean equals​(java.lang.Object obj)  
      void extend​(double lat, double lon)
      Extend the bounds if necessary to include the given point [lat,lon].
      void extend​(Bounds b)
      Extends this bounds to enclose an other bounding box
      void extend​(LatLon ll)
      Extend the bounds if necessary to include the given point.
      double getArea()
      Gets the area of this bounds (in lat/lon space)
      LatLon getCenter()
      Returns center of the bounding box.
      double getHeight()
      Returns the bounds width.
      LatLon getMax()
      Gets the point that has both the maximum lat and lon coordinate
      double getMaxLat()
      Returns max latitude of bounds.
      double getMaxLon()
      Returns max longitude of bounds.
      LatLon getMin()
      Gets the point that has both the minimal lat and lon coordinate
      double getMinLat()
      Returns min latitude of bounds.
      double getMinLon()
      Returns min longitude of bounds.
      double getWidth()
      Returns the bounds width.
      int hashCode()  
      protected static double initLat​(double value, boolean roundToOsmPrecision)  
      protected static double initLon​(double value, boolean roundToOsmPrecision)  
      boolean intersects​(Bounds b)
      The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure.
      boolean intersects​(IBounds b)
      The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure.
      private static boolean intersectsLonCrossing​(IBounds crossing, IBounds notCrossing)  
      boolean isCollapsed()
      Replies true, if this bounds are collapsed, i.e.
      boolean isOutOfTheWorld()
      Determines if these bounds are out of the world.
      void normalize()
      Clamp the bounds to be inside the world.
      BBox toBBox()
      Creates BBox with same coordinates.
      java.lang.String toShortString​(java.text.DecimalFormat format)
      Converts this bounds to a human readable short string
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • minLat

        private double minLat
        The minimum and maximum coordinates.
      • minLon

        private double minLon
        The minimum and maximum coordinates.
      • maxLat

        private double maxLat
        The minimum and maximum coordinates.
      • maxLon

        private double maxLon
        The minimum and maximum coordinates.
    • Constructor Detail

      • Bounds

        public Bounds​(LatLon min,
                      LatLon max)
        Construct bounds out of two points. Coords will be rounded.
        Parameters:
        min - min lat/lon
        max - max lat/lon
      • Bounds

        public Bounds​(LatLon min,
                      LatLon max,
                      boolean roundToOsmPrecision)
        Constructs bounds out of two points.
        Parameters:
        min - min lat/lon
        max - max lat/lon
        roundToOsmPrecision - defines if lat/lon will be rounded
      • Bounds

        public Bounds​(LatLon b)
        Constructs bounds out a single point. Coords will be rounded.
        Parameters:
        b - lat/lon
      • Bounds

        public Bounds​(LatLon b,
                      boolean roundToOsmPrecision)
        Single point Bounds defined by lat/lon b. Coordinates will be rounded to osm precision if roundToOsmPrecision is true.
        Parameters:
        b - lat/lon of given point.
        roundToOsmPrecision - defines if lat/lon will be rounded.
      • Bounds

        public Bounds​(double lat,
                      double lon,
                      boolean roundToOsmPrecision)
        Single point Bounds defined by point [lat,lon]. Coordinates will be rounded to osm precision if roundToOsmPrecision is true.
        Parameters:
        lat - latitude of given point.
        lon - longitude of given point.
        roundToOsmPrecision - defines if lat/lon will be rounded.
        Since:
        6203
      • Bounds

        public Bounds​(double minLat,
                      double minLon,
                      double maxLat,
                      double maxLon)
        Constructs bounds out of two points. Coords will be rounded.
        Parameters:
        minLat - min lat
        minLon - min lon
        maxLat - max lat
        maxLon - max lon
      • Bounds

        public Bounds​(double minLat,
                      double minLon,
                      double maxLat,
                      double maxLon,
                      boolean roundToOsmPrecision)
        Constructs bounds out of two points.
        Parameters:
        minLat - min lat
        minLon - min lon
        maxLat - max lat
        maxLon - max lon
        roundToOsmPrecision - defines if lat/lon will be rounded
      • Bounds

        public Bounds​(double... coords)
        Constructs bounds out of two points. Coords will be rounded.
        Parameters:
        coords - exactly 4 values: min lat, min lon, max lat, max lon
        Throws:
        java.lang.IllegalArgumentException - if coords does not contain 4 double values
      • Bounds

        public Bounds​(double[] coords,
                      boolean roundToOsmPrecision)
        Constructs bounds out of two points.
        Parameters:
        coords - exactly 4 values: min lat, min lon, max lat, max lon
        roundToOsmPrecision - defines if lat/lon will be rounded
        Throws:
        java.lang.IllegalArgumentException - if coords does not contain 4 double values
      • Bounds

        public Bounds​(java.lang.String asString,
                      java.lang.String separator,
                      Bounds.ParseMethod parseMethod)
        Parse the bounds from a given string and round to OSM precision
        Parameters:
        asString - The string
        separator - The separation regex
        parseMethod - The order of the numbers
      • Bounds

        public Bounds​(java.lang.String asString,
                      java.lang.String separator,
                      Bounds.ParseMethod parseMethod,
                      boolean roundToOsmPrecision)
        Parse the bounds from a given string
        Parameters:
        asString - The string
        separator - The separation regex
        parseMethod - The order of the numbers
        roundToOsmPrecision - Whether to round to OSM precision
      • Bounds

        public Bounds​(Bounds other)
        Creates new Bounds from an existing one.
        Parameters:
        other - The bounds to copy
      • Bounds

        public Bounds​(java.awt.geom.Rectangle2D rect)
        Creates new Bounds from a rectangle.
        Parameters:
        rect - The rectangle
      • Bounds

        public Bounds​(LatLon center,
                      double latExtent,
                      double lonExtent)
        Creates new bounds around a coordinate pair center. The new bounds shall have an extension in latitude direction of latExtent, and in longitude direction of lonExtent.
        Parameters:
        center - the center coordinate pair. Must not be null.
        latExtent - the latitude extent. > 0 required.
        lonExtent - the longitude extent. > 0 required.
        Throws:
        java.lang.IllegalArgumentException - if center is null
        java.lang.IllegalArgumentException - if latExtent <= 0
        java.lang.IllegalArgumentException - if lonExtent <= 0
    • Method Detail

      • getMin

        public LatLon getMin()
        Gets the point that has both the minimal lat and lon coordinate
        Specified by:
        getMin in interface IBounds
        Returns:
        The point
      • getMinLat

        public double getMinLat()
        Returns min latitude of bounds. Efficient shortcut for getMin().lat().
        Specified by:
        getMinLat in interface IBounds
        Returns:
        min latitude of bounds.
        Since:
        6203
      • getMinLon

        public double getMinLon()
        Returns min longitude of bounds. Efficient shortcut for getMin().lon().
        Specified by:
        getMinLon in interface IBounds
        Returns:
        min longitude of bounds.
        Since:
        6203
      • getMax

        public LatLon getMax()
        Gets the point that has both the maximum lat and lon coordinate
        Specified by:
        getMax in interface IBounds
        Returns:
        The point
      • getMaxLat

        public double getMaxLat()
        Returns max latitude of bounds. Efficient shortcut for getMax().lat().
        Specified by:
        getMaxLat in interface IBounds
        Returns:
        max latitude of bounds.
        Since:
        6203
      • getMaxLon

        public double getMaxLon()
        Returns max longitude of bounds. Efficient shortcut for getMax().lon().
        Specified by:
        getMaxLon in interface IBounds
        Returns:
        max longitude of bounds.
        Since:
        6203
      • initLat

        protected static double initLat​(double value,
                                        boolean roundToOsmPrecision)
      • initLon

        protected static double initLon​(double value,
                                        boolean roundToOsmPrecision)
      • toBBox

        public BBox toBBox()
        Creates BBox with same coordinates.
        Returns:
        BBox with same coordinates.
        Since:
        6203
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toShortString

        public java.lang.String toShortString​(java.text.DecimalFormat format)
        Converts this bounds to a human readable short string
        Parameters:
        format - The number format to use
        Returns:
        The string
      • getCenter

        public LatLon getCenter()
        Returns center of the bounding box.
        Specified by:
        getCenter in interface IBounds
        Returns:
        Center of the bounding box.
      • extend

        public void extend​(LatLon ll)
        Extend the bounds if necessary to include the given point.
        Parameters:
        ll - The point to include into these bounds
      • extend

        public void extend​(double lat,
                           double lon)
        Extend the bounds if necessary to include the given point [lat,lon]. Good to use if you know coordinates to avoid creation of LatLon object.
        Parameters:
        lat - Latitude of point to include into these bounds
        lon - Longitude of point to include into these bounds
        Since:
        6203
      • extend

        public void extend​(Bounds b)
        Extends this bounds to enclose an other bounding box
        Parameters:
        b - The other bounds to enclose
      • contains

        public boolean contains​(LatLon ll)
        Determines if the given point ll is within these bounds.

        Points with unknown coordinates are always outside the coordinates.

        Parameters:
        ll - The lat/lon to check
        Returns:
        true if ll is within these bounds, false otherwise
      • contains

        public boolean contains​(ILatLon ll)
        Determines if the given point ll is within these bounds.

        Points with unknown coordinates are always outside the coordinates.

        Specified by:
        contains in interface IBounds
        Parameters:
        ll - The lat/lon to check
        Returns:
        true if ll is within these bounds, false otherwise
        Since:
        12161
      • intersects

        public boolean intersects​(Bounds b)
        The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure. (">=" instead of ">")
        Parameters:
        b - other bounds
        Returns:
        true if the two bounds intersect
      • intersects

        public boolean intersects​(IBounds b)
        Description copied from interface: IBounds
        The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure. (">=" instead of ">")
        Specified by:
        intersects in interface IBounds
        Parameters:
        b - other bounds
        Returns:
        true if the two bounds intersect
      • asRect

        public java.awt.geom.Rectangle2D.Double asRect()
        Converts the lat/lon bounding box to an object of type Rectangle2D.Double
        Returns:
        the bounding box to Rectangle2D.Double
      • getHeight

        public double getHeight()
        Returns the bounds width.
        Specified by:
        getHeight in interface IBounds
        Returns:
        the bounds width
        Since:
        14521
      • getWidth

        public double getWidth()
        Returns the bounds width.
        Specified by:
        getWidth in interface IBounds
        Returns:
        the bounds width
        Since:
        14521
      • getArea

        public double getArea()
        Gets the area of this bounds (in lat/lon space)
        Specified by:
        getArea in interface IBounds
        Returns:
        The area
      • isCollapsed

        public boolean isCollapsed()

        Replies true, if this bounds are collapsed, i.e. if the min and the max corner are equal.

        Returns:
        true, if this bounds are collapsed
      • isOutOfTheWorld

        public boolean isOutOfTheWorld()
        Determines if these bounds are out of the world.
        Returns:
        true if lat outside of range [-90,90] or lon outside of range [-180,180]
      • normalize

        public void normalize()
        Clamp the bounds to be inside the world.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object