Class RectangleImpl
- java.lang.Object
-
- org.locationtech.spatial4j.shape.BaseShape<SpatialContext>
-
- org.locationtech.spatial4j.shape.impl.RectangleImpl
-
public class RectangleImpl extends BaseShape<SpatialContext> implements Rectangle
A simple Rectangle implementation that also supports a longitudinal wrap-around. When minX > maxX, this will assume it is world coordinates that cross the date line using degrees. Immutable & threadsafe.
-
-
Constructor Summary
Constructors Constructor Description RectangleImpl(double minX, double maxX, double minY, double maxY, SpatialContext ctx)
A simple constructor without normalization / validation.RectangleImpl(Point lowerLeft, Point upperRight, SpatialContext ctx)
A convenience constructor which pulls out the coordinates.RectangleImpl(Rectangle r, SpatialContext ctx)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
The sub-classes of Shape generally implement the same contract forObject.equals(Object)
andObject.hashCode()
amongst the same sub-interface type.static boolean
equals(Rectangle thiz, java.lang.Object o)
AllRectangle
implementations should use this definition ofObject.equals(Object)
.double
getArea(SpatialContext ctx)
Calculates the area of the shape, in square-degrees.Rectangle
getBoundingBox()
Get the bounding box for this Shape.Rectangle
getBuffered(double distance, SpatialContext ctx)
Returns a buffered version of this shape.Point
getCenter()
Returns the center point of this shape.boolean
getCrossesDateLine()
Only meaningful for geospatial contexts.double
getHeight()
The height.double
getMaxX()
The right edge of the X coordinate.double
getMaxY()
The top edge of the Y coordinate.double
getMinX()
The left edge of the X coordinate.double
getMinY()
The bottom edge of the Y coordinate.double
getWidth()
The width.boolean
hasArea()
Does the shape have area? This will be false for points and lines.int
hashCode()
static int
hashCode(Rectangle thiz)
AllRectangle
implementations should use this definition ofObject.hashCode()
.boolean
isEmpty()
Shapes can be "empty", which is to say it exists nowhere.SpatialRelation
relate(Point point)
SpatialRelation
relate(Rectangle rect)
SpatialRelation
relate(Shape other)
Describe the relationship between the two objects.private static SpatialRelation
relate_range(double int_min, double int_max, double ext_min, double ext_max)
SpatialRelation
relateXRange(double ext_minX, double ext_maxX)
A specialization ofShape.relate(Shape)
for a horizontal line.SpatialRelation
relateYRange(double ext_minY, double ext_maxY)
A specialization ofShape.relate(Shape)
for a vertical line.void
reset(double minX, double maxX, double minY, double maxY)
Expert: Resets the state of this shape given the arguments.java.lang.String
toString()
private static boolean
verticalAtDateline(RectangleImpl rect1, Rectangle rect2)
-
Methods inherited from class org.locationtech.spatial4j.shape.BaseShape
getContext
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.locationtech.spatial4j.shape.Shape
getContext
-
-
-
-
Constructor Detail
-
RectangleImpl
public RectangleImpl(double minX, double maxX, double minY, double maxY, SpatialContext ctx)
A simple constructor without normalization / validation.
-
RectangleImpl
public RectangleImpl(Point lowerLeft, Point upperRight, SpatialContext ctx)
A convenience constructor which pulls out the coordinates.
-
RectangleImpl
public RectangleImpl(Rectangle r, SpatialContext ctx)
Copy constructor.
-
-
Method Detail
-
reset
public void reset(double minX, double maxX, double minY, double maxY)
Description copied from interface:Rectangle
Expert: Resets the state of this shape given the arguments. This is a performance feature to avoid excessive Shape object allocation as well as some argument error checking. Mutable shapes is error-prone so use with care.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Shape
Shapes can be "empty", which is to say it exists nowhere. The underlying coordinates are typically NaN.
-
getBuffered
public Rectangle getBuffered(double distance, SpatialContext ctx)
Description copied from interface:Shape
Returns a buffered version of this shape. The buffer is usually a rounded-corner buffer, although some shapes might buffer differently. This is an optional operation.- Specified by:
getBuffered
in interfaceShape
- Returns:
- Not null, and the returned shape should contain the current shape.
-
hasArea
public boolean hasArea()
Description copied from interface:Shape
Does the shape have area? This will be false for points and lines. It will also be false for shapes that normally have area but are constructed in a degenerate case as to not have area (e.g. a circle with 0 radius or rectangle with no height or no width).
-
getArea
public double getArea(SpatialContext ctx)
Description copied from interface:Shape
Calculates the area of the shape, in square-degrees. If ctx is null then simple Euclidean calculations will be used. This figure can be an estimate.
-
getCrossesDateLine
public boolean getCrossesDateLine()
Description copied from interface:Rectangle
Only meaningful for geospatial contexts.- Specified by:
getCrossesDateLine
in interfaceRectangle
-
getHeight
public double getHeight()
Description copied from interface:Rectangle
The height. In geospatial contexts, this is in degrees latitude. It will always be >= 0.
-
getWidth
public double getWidth()
Description copied from interface:Rectangle
The width. In geospatial contexts, this is generally in degrees longitude and is aware of the dateline (aka anti-meridian). It will always be >= 0.
-
getMaxX
public double getMaxX()
Description copied from interface:Rectangle
The right edge of the X coordinate.
-
getMaxY
public double getMaxY()
Description copied from interface:Rectangle
The top edge of the Y coordinate.
-
getMinX
public double getMinX()
Description copied from interface:Rectangle
The left edge of the X coordinate.
-
getMinY
public double getMinY()
Description copied from interface:Rectangle
The bottom edge of the Y coordinate.
-
getBoundingBox
public Rectangle getBoundingBox()
Description copied from interface:Shape
Get the bounding box for this Shape. This means the shape is within the bounding box and that it touches each side of the rectangle.Postcondition:
this.getBoundingBox().relate(this) == CONTAINS
- Specified by:
getBoundingBox
in interfaceShape
-
relate
public SpatialRelation relate(Shape other)
Description copied from interface:Shape
Describe the relationship between the two objects. For example- this is WITHIN other
- this CONTAINS other
- this is DISJOINT other
- this INTERSECTS other
If the shapes are equal then the result is CONTAINS (preferred) or WITHIN.
-
relate
public SpatialRelation relate(Point point)
-
relate
public SpatialRelation relate(Rectangle rect)
-
verticalAtDateline
private static boolean verticalAtDateline(RectangleImpl rect1, Rectangle rect2)
-
relate_range
private static SpatialRelation relate_range(double int_min, double int_max, double ext_min, double ext_max)
-
relateYRange
public SpatialRelation relateYRange(double ext_minY, double ext_maxY)
Description copied from interface:Rectangle
A specialization ofShape.relate(Shape)
for a vertical line.- Specified by:
relateYRange
in interfaceRectangle
-
relateXRange
public SpatialRelation relateXRange(double ext_minX, double ext_maxX)
Description copied from interface:Rectangle
A specialization ofShape.relate(Shape)
for a horizontal line.- Specified by:
relateXRange
in interfaceRectangle
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCenter
public Point getCenter()
Description copied from interface:Shape
Returns the center point of this shape. This is usually the same asgetBoundingBox().getCenter()
but it doesn't have to be.Postcondition:
this.relate(this.getCenter()) == CONTAINS
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:Shape
The sub-classes of Shape generally implement the same contract forObject.equals(Object)
andObject.hashCode()
amongst the same sub-interface type. This means, for example, that multiple Point implementations of different classes are equal if they share the same x & y.
-
equals
public static boolean equals(Rectangle thiz, java.lang.Object o)
AllRectangle
implementations should use this definition ofObject.equals(Object)
.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-