Class CircleImpl

java.lang.Object
org.locationtech.spatial4j.shape.BaseShape<SpatialContext>
org.locationtech.spatial4j.shape.impl.CircleImpl
All Implemented Interfaces:
Circle, Shape
Direct Known Subclasses:
GeoCircle

public class CircleImpl extends BaseShape<SpatialContext> implements Circle
A circle, also known as a point-radius, based on a DistanceCalculator which does all the work. This implementation should work for both cartesian 2D and geodetic sphere surfaces.
  • Field Details

    • point

      protected final Point point
    • radiusDEG

      protected double radiusDEG
    • enclosingBox

      protected Rectangle enclosingBox
  • Constructor Details

  • Method Details

    • reset

      public void reset(double x, double y, double radiusDEG)
      Description copied from interface: Circle
      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 Circle
    • 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
    • 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
    • getRadius

      public double getRadius()
      Description copied from interface: Circle
      The distance from the point's center to its edge, measured in the same units as x & y (e.g. degrees if WGS84).
      Specified by:
      getRadius in interface Circle
    • 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
    • getBuffered

      public Circle 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.
    • contains

      public boolean contains(double x, double y)
    • 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
    • getBoundingBox

      public Rectangle getBoundingBox()
      Note that the bounding box might contain a minX that is > maxX, due to WGS84 anti-meridian.
      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
    • relate

      public SpatialRelation relate(Point point)
    • relate

      public SpatialRelation relate(Rectangle r)
    • relateRectanglePhase2

      protected SpatialRelation relateRectanglePhase2(Rectangle r, SpatialRelation bboxSect)
    • getYAxis

      protected double getYAxis()
      The Y coordinate of where the circle axis intersect.
    • getXAxis

      protected double getXAxis()
      The X coordinate of where the circle axis intersect.
    • relate

      public SpatialRelation relate(Circle circle)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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
    • equals

      public static boolean equals(Circle thiz, Object o)
      All Circle implementations should use this definition of Object.equals(Object).
    • hashCode

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

      public static int hashCode(Circle thiz)
      All Circle implementations should use this definition of Object.hashCode().