Class Ellipse

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

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

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

      Constructors 
      Constructor Description
      Ellipse()
      Construct a new ellipse with all values set to zero
      Ellipse​(float x, float y, float width, float height)
      Constructs a new ellipse
      Ellipse​(Circle circle)
      Constructs a new Ellipse from the position and radius of a Circle (since circles are special cases of ellipses).
      Ellipse​(Ellipse ellipse)
      Copy constructor
      Ellipse​(Vector2 position, float width, float height)
      Constructs a new ellipse
      Ellipse​(Vector2 position, Vector2 size)
      Constructs a new ellipse
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float area()  
      float circumference()
      Approximates the circumference of this Ellipse.
      boolean contains​(float x, float y)
      Checks whether or not this ellipse contains the given point.
      boolean contains​(Vector2 point)
      Checks whether or not this ellipse contains the given point.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      void set​(float x, float y, float width, float height)
      Sets a new position and size for this ellipse.
      void set​(Circle circle)  
      void set​(Ellipse ellipse)
      Sets a new position and size for this ellipse based upon another ellipse.
      void set​(Vector2 position, Vector2 size)  
      Ellipse setPosition​(float x, float y)
      Sets the x and y-coordinates of ellipse center
      Ellipse setPosition​(Vector2 position)
      Sets the x and y-coordinates of ellipse center from a Vector2.
      Ellipse setSize​(float width, float height)
      Sets the width and height of this ellipse
      • Methods inherited from class java.lang.Object

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

      • x

        public float x
      • y

        public float y
      • width

        public float width
      • height

        public float height
    • Constructor Detail

      • Ellipse

        public Ellipse()
        Construct a new ellipse with all values set to zero
      • Ellipse

        public Ellipse​(Ellipse ellipse)
        Copy constructor
        Parameters:
        ellipse - Ellipse to construct a copy of.
      • Ellipse

        public Ellipse​(float x,
                       float y,
                       float width,
                       float height)
        Constructs a new ellipse
        Parameters:
        x - X coordinate
        y - Y coordinate
        width - the width of the ellipse
        height - the height of the ellipse
      • Ellipse

        public Ellipse​(Vector2 position,
                       float width,
                       float height)
        Constructs a new ellipse
        Parameters:
        position - Position vector
        width - the width of the ellipse
        height - the height of the ellipse
      • Ellipse

        public Ellipse​(Vector2 position,
                       Vector2 size)
        Constructs a new ellipse
        Parameters:
        position - Position vector
        size - Size vector
      • Ellipse

        public Ellipse​(Circle circle)
        Constructs a new Ellipse from the position and radius of a Circle (since circles are special cases of ellipses).
        Parameters:
        circle - The circle to take the values of
    • Method Detail

      • contains

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

        public boolean contains​(Vector2 point)
        Checks whether or not this ellipse contains the given point.
        Specified by:
        contains in interface Shape2D
        Parameters:
        point - Position vector
        Returns:
        true if this ellipse contains the given point; false otherwise.
      • set

        public void set​(float x,
                        float y,
                        float width,
                        float height)
        Sets a new position and size for this ellipse.
        Parameters:
        x - X coordinate
        y - Y coordinate
        width - the width of the ellipse
        height - the height of the ellipse
      • set

        public void set​(Ellipse ellipse)
        Sets a new position and size for this ellipse based upon another ellipse.
        Parameters:
        ellipse - The ellipse to copy the position and size of.
      • set

        public void set​(Circle circle)
      • setPosition

        public Ellipse setPosition​(Vector2 position)
        Sets the x and y-coordinates of ellipse center from a Vector2.
        Parameters:
        position - The position vector
        Returns:
        this ellipse for chaining
      • setPosition

        public Ellipse setPosition​(float x,
                                   float y)
        Sets the x and y-coordinates of ellipse center
        Parameters:
        x - The x-coordinate
        y - The y-coordinate
        Returns:
        this ellipse for chaining
      • setSize

        public Ellipse setSize​(float width,
                               float height)
        Sets the width and height of this ellipse
        Parameters:
        width - The width
        height - The height
        Returns:
        this ellipse for chaining
      • circumference

        public float circumference()
        Approximates the circumference of this Ellipse. Oddly enough, the circumference of an ellipse is actually difficult to compute exactly.
        Returns:
        The Ramanujan approximation to the circumference of an ellipse if one dimension is at least three times longer than the other, else the simpler approximation
      • 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