Class Box

java.lang.Object
com.geodesk.geom.Box
All Implemented Interfaces:
Bounds
Direct Known Subclasses:
BoundedItem, RTree.Node

public class Box extends Object implements Bounds
An axis-aligned bounding box. A `Box` represents minimum and maximum X and Y coordinates in a Mercator-projected plane. It can straddle the Antimeridian (in which case `minX` is *larger* than `maxX`). A `Box` can also be empty (in which case `minY` is *larger* than `maxY`)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Box()
    Creates a null Box.
    Box(int x, int y)
     
    Box(int minX, int minY, int maxX, int maxY)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Box
    atLonLat(double lon, double lat)
    Creates a `Box` that covers a single point.
    static Box
    atXY(int x, int y)
    Creates a `Box` that covers a single point.
    void
    buffer(int b)
    Expands or contracts all sides of this bounding box by a specified number of imps.
    void
    bufferMeters(double m)
    Expands or contracts all sides of this bounding box by a specified number of meters.
    boolean
    Returns `true` if this bounding box straddles the Antimeridian.
    boolean
    equals(Object other)
     
    void
    expandToInclude(int[] coords)
     
    void
    expandToInclude(int x, int y)
    Checks if this bounding box includes the given coordinate, and expands it if necessary.
    void
    expandToInclude(int otherMinX, int otherMinY, int otherMaxX, int otherMaxY)
    Checks if this bounding box includes another bounding box, and expands it if necessary.
    void
    Checks if this bounding box includes another bounding box, and expands it if necessary.
    static Box
     
    static Box
    Creates a Box from a string that specifies four coordinates (west, south, east, north), in degrees longitude/latitude.
    int
     
    static Box
    impsAroundXY(int d, int x, int y)
    Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
    Creates a new bounding box that is the result of the intersection between this bounding box and another.
    static Box
     
    boolean
    Returns `true` if this bounding box is empty.
    static boolean
     
    int
     
    int
     
    static Box
    metersAround(double meters, Bounds other)
    Creates a bounding box whose sides are extended by a specific distance relative to another bounding box.
    static Box
    metersAroundLonLat(double meters, double lon, double lat)
    Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
    static Box
    metersAroundXY(double meters, int x, int y)
    Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
    int
     
    int
     
    static Box
    of(Geometry geom)
     
    static Box
     
    static Box
    Creates a bounding box that covers the entire world.
    static Box
    ofWSEN(double west, double south, double east, double north)
     
    static Box
    ofXYWidthHeight(int x, int y, int w, int h)
     
    static Box
    ofXYXY(int x1, int y1, int x2, int y2)
     
    void
     
    static Bounds
     
    Creates a JTS Envelope with the same dimensions as this bounding box.
     
     
    void
    translate(int deltaX, int deltaY)
    Moves the bounding box horizontally and vertically by the specified number of units.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.geodesk.geom.Bounds

    area, centerX, centerY, contains, contains, height, intersects, width
  • Constructor Details

    • Box

      public Box()
      Creates a null Box.
    • Box

      public Box(int minX, int minY, int maxX, int maxY)
    • Box

      public Box(Bounds b)
    • Box

      public Box(int x, int y)
  • Method Details

    • setNull

      public void setNull()
    • crossesAntimeridian

      public boolean crossesAntimeridian()
      Returns `true` if this bounding box straddles the Antimeridian.
      Returns:
      `true` if `minX` and `maxX` lie on different sides of the Antimeridian
    • isNull

      public boolean isNull()
      Returns `true` if this bounding box is empty.
      Returns:
      `true` if this is an empty bounding box (`maxY` is less than `minY`)
    • isNull

      public static boolean isNull(Bounds b)
    • minX

      public int minX()
      Specified by:
      minX in interface Bounds
    • minY

      public int minY()
      Specified by:
      minY in interface Bounds
    • maxX

      public int maxX()
      Specified by:
      maxX in interface Bounds
    • maxY

      public int maxY()
      Specified by:
      maxY in interface Bounds
    • expandToInclude

      public void expandToInclude(int x, int y)
      Checks if this bounding box includes the given coordinate, and expands it if necessary. If this bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).
      Parameters:
      x - X-coordinate
      y - Y-coordinate
    • expandToInclude

      public void expandToInclude(Bounds b)
      Checks if this bounding box includes another bounding box, and expands it if necessary. If either bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).
      Parameters:
      b - the bounding box to include into this
    • expandToInclude

      public void expandToInclude(int otherMinX, int otherMinY, int otherMaxX, int otherMaxY)
      Checks if this bounding box includes another bounding box, and expands it if necessary. If either bounding box straddles the Antimeridian, the results of this method are undefined (as it cannot tell in which direction the box should be expanded).
      Parameters:
      otherMinX - minimum X-coordinate of the other bounding box
      otherMinY - minimum Y-coordinate of the other bounding box
      otherMaxX - maximum X-coordinate of the other bounding box
      otherMaxY - maximum Y-coordinate of the other bounding box
    • expandToInclude

      public void expandToInclude(int[] coords)
    • toEnvelope

      public Envelope toEnvelope()
      Creates a JTS Envelope with the same dimensions as this bounding box.
      Returns:
      a new `Envelope`
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • intersection

      public Box intersection(Bounds o)
      Creates a new bounding box that is the result of the intersection between this bounding box and another.
      Parameters:
      o - the other bounding box
      Returns:
      new Box
    • intersection

      public static Box intersection(Bounds a, Bounds b)
    • smaller

      public static Bounds smaller(Bounds a, Bounds b)
    • buffer

      public void buffer(int b)
      Expands or contracts all sides of this bounding box by a specified number of imps. If the bounding box is empty, the result is undefined.
      Parameters:
      b - the buffer (in imps)
    • bufferMeters

      public void bufferMeters(double m)
      Expands or contracts all sides of this bounding box by a specified number of meters. If the bounding box is empty, the result is undefined.
      Parameters:
      m - the buffer (in meters)
    • translate

      public void translate(int deltaX, int deltaY)
      Moves the bounding box horizontally and vertically by the specified number of units. Attempts to move the box beyond the cut-offs in the polar regions result in the box being trimmed. If the bounding box is empty, the result is undefined.
      Parameters:
      deltaX - X-offset (imps)
      deltaY - Y-offset (imps)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • ofWSEN

      public static Box ofWSEN(double west, double south, double east, double north)
    • atLonLat

      public static Box atLonLat(double lon, double lat)
      Creates a `Box` that covers a single point.
      Parameters:
      lon - the longitude of the point
      lat - the latitude of the point
      Returns:
      a `Box` that is 1 imp wide and 1 imp tall
    • atXY

      public static Box atXY(int x, int y)
      Creates a `Box` that covers a single point.
      Parameters:
      x - X-coordinate (Mercator-projected) of the point
      y - Y-coordinate (Mercator-projected) of the point
      Returns:
      a `Box` that is 1 imp wide and 1 imp tall
    • ofXYXY

      public static Box ofXYXY(int x1, int y1, int x2, int y2)
    • ofXYWidthHeight

      public static Box ofXYWidthHeight(int x, int y, int w, int h)
    • metersAroundXY

      public static Box metersAroundXY(double meters, int x, int y)
      Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
      Parameters:
      meters - the distance (in meters) by which each side of the original bounds are buffered
      x - X-coordinate of the center point (Mercator-projected)
      y - Y-coordinate of the center point (Mercator-projected)
      Returns:
      a new bounding box
    • impsAroundXY

      public static Box impsAroundXY(int d, int x, int y)
      Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
      Parameters:
      d - the distance (in imps) by which each side of the original bounds are buffered
      x - X-coordinate of the center point (Mercator-projected)
      y - Y-coordinate of the center point (Mercator-projected)
      Returns:
      a new bounding box
    • metersAroundLonLat

      public static Box metersAroundLonLat(double meters, double lon, double lat)
      Creates a bounding box whose sides extend by a specific distance relative to a coordinate pair.
      Parameters:
      meters - the distance (in meters) by which each side of the original bounds are buffered
      lon - longitude of the center point
      lat - latitude of the center point
      Returns:
      a new bounding box
    • metersAround

      public static Box metersAround(double meters, Bounds other)
      Creates a bounding box whose sides are extended by a specific distance relative to another bounding box.
      Parameters:
      meters - the distance (in meters) by which each side of the original bounds are buffered
      other - the original bounding box
      Returns:
      a new bounding box
    • fromEnvelope

      public static Box fromEnvelope(Envelope env)
    • of

      public static Box of(Geometry geom)
    • of

      public static Box of(LineSegment seg)
    • fromWSEN

      public static Box fromWSEN(String s)
      Creates a Box from a string that specifies four coordinates (west, south, east, north), in degrees longitude/latitude.
      Parameters:
      s - the string (e.g. `2.2,48.8,2.5,18.9`)
      Returns:
      a new bounding box
    • ofWorld

      public static Box ofWorld()
      Creates a bounding box that covers the entire world.
      Returns:
      a new bounding box
    • toGeometry

      public Geometry toGeometry(GeometryFactory factory)