Rectangle (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.geo, class: Rectangle

Package org.apache.lucene.geo

# Class Rectangle

java.lang.Object
org.apache.lucene.geo.Geometry
org.apache.lucene.geo.LatLonGeometry
org.apache.lucene.geo.Rectangle

public class Rectangle extends LatLonGeometry
Represents a rectangular bounding box on Earth's surface.

A rectangle is defined by its minimum and maximum latitude/longitude coordinates. It can cross the dateline, in which case minLon > maxLon.

Key Features:

- Handles dateline crossing automatically
- Supports point-in-box testing
- Can be used to create spatial queries
- Useful for creating bounding boxes around other shapes

Example usage:

     // Create a rectangle covering central London
     Rectangle bbox = new Rectangle(51.4, 51.6, -0.2, 0.0);

     // Create a rectangle crossing the dateline
     Rectangle datelineBox = new Rectangle(20, 30, 170, -170);

     // Create a bounding box around a point with given radius
     Rectangle circle = Rectangle.fromPointDistance(lat, lon, radiusMeters);

Note: When working with areas near poles, consider that rectangles become highly distorted and may not provide accurate representation of the actual area.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final double`
  `AXISLAT_ERROR`
  maximum error from `axisLat(double, double)`.
  `final double`
  `maxLat`
  Maximum latitude in degrees (-90 to 90)
  `final double`
  `maxLon`
  Maximum longitude in degrees (-180 to 180)
  `final double`
  `minLat`
  Minimum latitude in degrees (-90 to 90)
  `final double`
  `minLon`
  Minimum longitude in degrees (-180 to 180).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Rectangle(double minLat, double maxLat, double minLon, double maxLon)`
  Constructs a bounding box by first validating the provided latitude and longitude coordinates

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static double`
  `axisLat(double centerLat, double radiusMeters)`
  Calculate the latitude of a circle's intersections with its bbox meridians.
  `static boolean`
  `containsPoint(double lat, double lon, double minLat, double maxLat, double minLon, double maxLon)`
  returns true if rectangle (defined by minLat, maxLat, minLon, maxLon) contains the lat lon point
  `boolean`
  `crossesDateline()`
  Returns true if this bounding box crosses the dateline
  `boolean`
  `equals(Object o)`
  `static Rectangle`
  `fromPointDistance(double centerLat, double centerLon, double radiusMeters)`
  Compute Bounding Box for a circle using WGS-84 parameters
  `static Rectangle`
  `fromPolygon(Polygon[] polygons)`
  Returns the bounding box over an array of polygons
  `int`
  `hashCode()`
  `protected Component2D`
  `toComponent2D()`
  get a Component2D from the geometry object
  `String`
  `toString()`

  ### Methods inherited from class org.apache.lucene.geo.LatLonGeometry

  `create`

  ### Methods inherited from class java.lang.Object

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

- ## Field Details

  - ### minLat

    public final double minLat
    Minimum latitude in degrees (-90 to 90)

  - ### maxLat

    public final double maxLat
    Maximum latitude in degrees (-90 to 90)

  - ### minLon

    public final double minLon
    Minimum longitude in degrees (-180 to 180). May be greater than maxLon when crossing the dateline.

  - ### maxLon

    public final double maxLon
    Maximum longitude in degrees (-180 to 180)

  - ### AXISLAT_ERROR

    public static final double AXISLAT_ERROR
    maximum error from `axisLat(double, double)`. logic must be prepared to handle this

- ## Constructor Details

  - ### Rectangle

    public Rectangle(double minLat, double maxLat, double minLon, double maxLon)
    Constructs a bounding box by first validating the provided latitude and longitude coordinates

- ## Method Details

  - ### toComponent2D

    protected Component2D toComponent2D()
    Description copied from class: `Geometry`
    get a Component2D from the geometry object
    Specified by:
      `toComponent2D` in class `Geometry`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### crossesDateline

    public boolean crossesDateline()
    Returns true if this bounding box crosses the dateline

  - ### containsPoint

    public static boolean containsPoint(double lat, double lon, double minLat, double maxLat, double minLon, double maxLon)
    returns true if rectangle (defined by minLat, maxLat, minLon, maxLon) contains the lat lon point

  - ### fromPointDistance

    public static Rectangle fromPointDistance(double centerLat, double centerLon, double radiusMeters)
    Compute Bounding Box for a circle using WGS-84 parameters

  - ### axisLat

    public static double axisLat(double centerLat, double radiusMeters)
    Calculate the latitude of a circle's intersections with its bbox meridians.

    NOTE: the returned value will be +/- `AXISLAT_ERROR` of the actual value.

    Parameters:
      `centerLat` - The latitude of the circle center
      `radiusMeters` - The radius of the circle in meters
    Returns:
      A latitude

  - ### fromPolygon

    public static Rectangle fromPolygon(Polygon[] polygons)
    Returns the bounding box over an array of polygons

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`