Class GCircle

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class GCircle
    extends GFillableE
    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor Description
      GCircle​(int x, int y, int r)  
      GCircle​(GCircle e)
      Copy constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double area()
      Calculates the area of this circle
      GCircle clone()  
      boolean contains​(int x, int y)
      Tells if a given point is contained in the circle
      boolean contains​(GCircle c)
      Tells if a given circle is contained on this circle, that means that every point in the circle is contained in this one.
      boolean contains​(GLine line)
      Tells if a given line segment is contained in the circle, that means that both ends are contained in the circle
      boolean contains​(GPoint point)
      Tells if a given point is contained in the circle
      void draw​(java.awt.Graphics2D g)
      Draws the component on the given graphics
      boolean equals​(java.lang.Object obj)  
      int getRadius()
      Returns the radius of the circle
      java.awt.geom.Area getShape()
      This method should return a Area that represents the GFillableE.
      int hashCode()  
      boolean intersects​(GCircle c)
      Tells if this circle intersects with another one
      boolean intersects​(GLine line)
      Tells if this circle intersects with a line.
      Note: This will tell if the line intersects the circle NOT the line segment!!!
      void move​(int x, int y)
      Moves the center of this circle to the given coordinates
      double perimeter()
      Calculated the perimeter of this circle
      void traslate​(int x, int y)
      Traslates this element on X and Y
      int x()
      Retrieves the X coordinate of the center of the circle
      int y()
      Retrieves the Y coordinate of the center of the circle
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GCircle

        public GCircle​(GCircle e)
        Copy constructor
        Parameters:
        e - GCircle to copy
        Throws:
        java.lang.IllegalArgumentException - if e is null
      • GCircle

        public GCircle​(int x,
                       int y,
                       int r)
        Parameters:
        x - X coordinate of the center
        y - Y coordinate of the center
        r - radius
    • Method Detail

      • x

        public int x()
        Retrieves the X coordinate of the center of the circle
        Returns:
        x coordinate of the center
      • y

        public int y()
        Retrieves the Y coordinate of the center of the circle
        Returns:
        y coordinate of the center
      • getRadius

        public int getRadius()
        Returns the radius of the circle
        Returns:
        radius
      • contains

        public boolean contains​(GCircle c)
        Tells if a given circle is contained on this circle, that means that every point in the circle is contained in this one.
        Parameters:
        c - the line to check
        Returns:
        true if the circle is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if circle is null
      • contains

        public boolean contains​(GLine line)
        Tells if a given line segment is contained in the circle, that means that both ends are contained in the circle
        Parameters:
        line - the line to check
        Returns:
        true if the line is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if line is null
      • contains

        public boolean contains​(GPoint point)
        Tells if a given point is contained in the circle
        Parameters:
        point - the point to check
        Returns:
        true if the point is contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if point is null
      • contains

        public boolean contains​(int x,
                                int y)
        Tells if a given point is contained in the circle
        Parameters:
        x - x coordinate of the point
        y - y coordinate of the point
        Returns:
        true if the point is contained and false otherwise
      • intersects

        public boolean intersects​(GCircle c)
        Tells if this circle intersects with another one
        Parameters:
        c - The circle to check
        Returns:
        true if the circles intersect and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if circle is null
      • intersects

        public boolean intersects​(GLine line)
        Tells if this circle intersects with a line.
        Note: This will tell if the line intersects the circle NOT the line segment!!!
        Parameters:
        line - The line to check
        Returns:
        true if they intersect and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if line is null
      • area

        public double area()
        Calculates the area of this circle
        Returns:
        area
      • perimeter

        public double perimeter()
        Calculated the perimeter of this circle
        Returns:
        perimeter
      • draw

        public void draw​(java.awt.Graphics2D g)
        Description copied from class: GraphicE
        Draws the component on the given graphics
        Specified by:
        draw in class GraphicE
        Parameters:
        g - where to draw
      • traslate

        public void traslate​(int x,
                             int y)
        Description copied from class: GraphicE
        Traslates this element on X and Y
        Specified by:
        traslate in class GraphicE
        Parameters:
        x - size in px of the horizontal translation
        y - size in px of the vertical translation
      • move

        public void move​(int x,
                         int y)
        Moves the center of this circle to the given coordinates
        Parameters:
        x - new x coordinate
        y - new y coordinate
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GFillableE
      • getShape

        public java.awt.geom.Area getShape()
        Description copied from class: GFillableE
        This method should return a Area that represents the GFillableE. Since this is not always possible, and the implementation of Area isn't always easy, it should return null otherwise.
        In jDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips for Graphic objects
        Specified by:
        getShape in class GFillableE
        Returns:
        Shape