Class RectangleImpl

  • All Implemented Interfaces:
    Rectangle, Shape

    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 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.
    • 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.
        Specified by:
        reset in interface Rectangle
      • 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.
        Specified by:
        isEmpty in interface Shape
      • 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 interface Shape
        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).
        Specified by:
        hasArea in interface Shape
      • 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.
        Specified by:
        getArea in interface Shape
      • getCrossesDateLine

        public boolean getCrossesDateLine()
        Description copied from interface: Rectangle
        Only meaningful for geospatial contexts.
        Specified by:
        getCrossesDateLine in interface Rectangle
      • getHeight

        public double getHeight()
        Description copied from interface: Rectangle
        The height. In geospatial contexts, this is in degrees latitude. It will always be >= 0.
        Specified by:
        getHeight in interface Rectangle
      • 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.
        Specified by:
        getWidth in interface Rectangle
      • getMaxX

        public double getMaxX()
        Description copied from interface: Rectangle
        The right edge of the X coordinate.
        Specified by:
        getMaxX in interface Rectangle
      • getMaxY

        public double getMaxY()
        Description copied from interface: Rectangle
        The top edge of the Y coordinate.
        Specified by:
        getMaxY in interface Rectangle
      • getMinX

        public double getMinX()
        Description copied from interface: Rectangle
        The left edge of the X coordinate.
        Specified by:
        getMinX in interface Rectangle
      • getMinY

        public double getMinY()
        Description copied from interface: Rectangle
        The bottom edge of the Y coordinate.
        Specified by:
        getMinY in interface Rectangle
      • 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 interface Shape
      • 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
        Note that a Shape implementation may choose to return INTERSECTS when the true answer is WITHIN or CONTAINS for performance reasons. If a shape does this then it must document when it does. Ideally the shape will not do this approximation in all circumstances, just sometimes.

        If the shapes are equal then the result is CONTAINS (preferred) or WITHIN.

        Specified by:
        relate in interface Shape
      • getCenter

        public Point getCenter()
        Description copied from interface: Shape
        Returns the center point of this shape. This is usually the same as getBoundingBox().getCenter() but it doesn't have to be.

        Postcondition: this.relate(this.getCenter()) == CONTAINS

        Specified by:
        getCenter in interface Shape
      • equals

        public boolean equals​(Object obj)
        Description copied from interface: Shape
        The sub-classes of Shape generally implement the same contract for Object.equals(Object) and Object.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.
        Specified by:
        equals in interface Shape
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object