Class Circle

  • All Implemented Interfaces:
    Shape2D, java.io.Serializable

    public class Circle
    extends java.lang.Object
    implements java.io.Serializable, Shape2D
    A convenient 2D circle class.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      float radius  
      float x  
      float y  
    • Constructor Summary

      Constructors 
      Constructor Description
      Circle()
      Constructs a new circle with all values set to zero
      Circle​(float x, float y, float radius)
      Constructs a new circle with the given X and Y coordinates and the given radius.
      Circle​(Circle circle)
      Copy constructor
      Circle​(Vector2 position, float radius)
      Constructs a new circle using a given Vector2 that contains the desired X and Y coordinates, and a given radius.
      Circle​(Vector2 center, Vector2 edge)
      Creates a new Circle in terms of its center and a point on its edge.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float area()  
      float circumference()  
      boolean contains​(float x, float y)
      Checks whether or not this circle contains a given point.
      boolean contains​(Circle c)  
      boolean contains​(Vector2 point)
      Checks whether or not this circle contains a given point.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean overlaps​(Circle c)  
      void set​(float x, float y, float radius)
      Sets a new location and radius for this circle.
      void set​(Circle circle)
      Sets a new location and radius for this circle, based upon another circle.
      void set​(Vector2 position, float radius)
      Sets a new location and radius for this circle.
      void set​(Vector2 center, Vector2 edge)
      Sets this Circle's values in terms of its center and a point on its edge.
      void setPosition​(float x, float y)
      Sets the x and y-coordinates of circle center
      void setPosition​(Vector2 position)
      Sets the x and y-coordinates of circle center from vector
      void setRadius​(float radius)
      Sets the radius of circle
      void setX​(float x)
      Sets the x-coordinate of circle center
      void setY​(float y)
      Sets the y-coordinate of circle center
      java.lang.String toString()
      Returns a String representation of this Circle of the form x,y,radius.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • x

        public float x
      • y

        public float y
      • radius

        public float radius
    • Constructor Detail

      • Circle

        public Circle()
        Constructs a new circle with all values set to zero
      • Circle

        public Circle​(float x,
                      float y,
                      float radius)
        Constructs a new circle with the given X and Y coordinates and the given radius.
        Parameters:
        x - X coordinate
        y - Y coordinate
        radius - The radius of the circle
      • Circle

        public Circle​(Vector2 position,
                      float radius)
        Constructs a new circle using a given Vector2 that contains the desired X and Y coordinates, and a given radius.
        Parameters:
        position - The position Vector2.
        radius - The radius
      • Circle

        public Circle​(Circle circle)
        Copy constructor
        Parameters:
        circle - The circle to construct a copy of.
      • Circle

        public Circle​(Vector2 center,
                      Vector2 edge)
        Creates a new Circle in terms of its center and a point on its edge.
        Parameters:
        center - The center of the new circle
        edge - Any point on the edge of the given circle
    • Method Detail

      • set

        public void set​(float x,
                        float y,
                        float radius)
        Sets a new location and radius for this circle.
        Parameters:
        x - X coordinate
        y - Y coordinate
        radius - Circle radius
      • set

        public void set​(Vector2 position,
                        float radius)
        Sets a new location and radius for this circle.
        Parameters:
        position - Position Vector2 for this circle.
        radius - Circle radius
      • set

        public void set​(Circle circle)
        Sets a new location and radius for this circle, based upon another circle.
        Parameters:
        circle - The circle to copy the position and radius of.
      • set

        public void set​(Vector2 center,
                        Vector2 edge)
        Sets this Circle's values in terms of its center and a point on its edge.
        Parameters:
        center - The new center of the circle
        edge - Any point on the edge of the given circle
      • setPosition

        public void setPosition​(Vector2 position)
        Sets the x and y-coordinates of circle center from vector
        Parameters:
        position - The position vector
      • setPosition

        public void setPosition​(float x,
                                float y)
        Sets the x and y-coordinates of circle center
        Parameters:
        x - The x-coordinate
        y - The y-coordinate
      • setX

        public void setX​(float x)
        Sets the x-coordinate of circle center
        Parameters:
        x - The x-coordinate
      • setY

        public void setY​(float y)
        Sets the y-coordinate of circle center
        Parameters:
        y - The y-coordinate
      • setRadius

        public void setRadius​(float radius)
        Sets the radius of circle
        Parameters:
        radius - The radius
      • contains

        public boolean contains​(float x,
                                float y)
        Checks whether or not this circle contains a given point.
        Specified by:
        contains in interface Shape2D
        Parameters:
        x - X coordinate
        y - Y coordinate
        Returns:
        true if this circle contains the given point.
      • contains

        public boolean contains​(Vector2 point)
        Checks whether or not this circle contains a given point.
        Specified by:
        contains in interface Shape2D
        Parameters:
        point - The Vector2 that contains the point coordinates.
        Returns:
        true if this circle contains this point; false otherwise.
      • contains

        public boolean contains​(Circle c)
        Parameters:
        c - the other Circle
        Returns:
        whether this circle contains the other circle.
      • overlaps

        public boolean overlaps​(Circle c)
        Parameters:
        c - the other Circle
        Returns:
        whether this circle overlaps the other circle.
      • toString

        public java.lang.String toString()
        Returns a String representation of this Circle of the form x,y,radius.
        Overrides:
        toString in class java.lang.Object
      • circumference

        public float circumference()
        Returns:
        The circumference of this circle (as 2 * MathUtils.PI2) * radius
      • area

        public float area()
        Returns:
        The area of this circle (as MathUtils.PI * radius * radius).
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object