Class GCircle

All Implemented Interfaces:
Cloneable

public class GCircle extends GFillableE
Author:
Federico Vera <[email protected]>
  • Field Summary

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    double
    Calculates the area of this circle
     
    boolean
    contains(int x, int y)
    Tells if a given point is contained in the circle
    boolean
    Tells if a given circle is contained on this circle, that means that every point in the circle is contained in this one.
    boolean
    Tells if a given line segment is contained in the circle, that means that both ends are contained in the circle
    boolean
    Tells if a given point is contained in the circle
    void
    Draws the component on the given graphics
    boolean
     
    int
    Returns the radius of the circle
    This method should return a Area that represents the GFillableE.
    int
     
    boolean
    Tells if this circle intersects with another one
    boolean
    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
    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 com.dkt.graphics.elements.GFillableE

    fill, getFillPaint, setFill, setFillPaint

    Methods inherited from class com.dkt.graphics.elements.GraphicE

    getPaint, getStroke, setPaint, setStroke

    Methods inherited from class java.lang.Object

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

    • GCircle

      public GCircle(GCircle e)
      Copy constructor
      Parameters:
      e - GCircle to copy
      Throws:
      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 Details

    • 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:
      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:
      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:
      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:
      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:
      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(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
    • clone

      public GCircle clone()
      Specified by:
      clone in class GFillableE
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GFillableE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GFillableE
    • getShape

      public 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