Package doodlepad

Class Polygon


public class Polygon extends Shape
A class that implements a general graphical polygon object made up of straight lines
  • Constructor Details

    • Polygon

      public Polygon(int[] xPoints, int[] yPoints)
      Constructor for objects of class Polygon - int arrays
      Parameters:
      xPoints - The array of x-coordinates for all Polygon object points.
      yPoints - The array of y-coordinates for all Polygon object points.
    • Polygon

      public Polygon(double[] xPoints, double[] yPoints)
      Constructor for objects of class Polygon - double arrays
      Parameters:
      xPoints - The array of x-coordinates for all Polygon object points.
      yPoints - The array of y-coordinates for all Polygon object points.
    • Polygon

      public Polygon(double[] xPoints, double[] yPoints, Pad pad)
      Constructor for objects of class Polygon - double arrays and Pad
      Parameters:
      xPoints - The array of x-coordinates for all Polygon object points.
      yPoints - The array of y-coordinates for all Polygon object points.
      pad - The Pad to which the Polygon will be added.
    • Polygon

      public Polygon(double[] xPoints, double[] yPoints, Layer layer)
      Constructor for objects of class Polygon - double arrays and Layer
      Parameters:
      xPoints - The array of x-coordinates for all Polygon object points.
      yPoints - The array of y-coordinates for all Polygon object points.
      layer - The Layer object to which the Polygon will be added, or null if not to add to a Pad.
    • Polygon

      public Polygon(List<Point> points)
      Constructor for objects of class Polygon
      Parameters:
      points - List of Point objects that define coordinate points of Polygon
    • Polygon

      public Polygon(List<Point> points, Pad pad)
      Constructor for objects of class Polygon
      Parameters:
      points - List of Point objects that define coordinate points of Polygon
      pad - The Pad to which the Polygon will be added.
    • Polygon

      public Polygon(List<Point> points, Layer layer)
      Constructor for objects of class Polygon
      Parameters:
      points - List of Point objects that define coordinate points of Polygon
      layer - The Layer object to which the Polygon will be added, or null if not to add to a Pad.
  • Method Details

    • toString

      public String toString()
      Generate a representation of the Polygon object.
      Overrides:
      toString in class Shape
      Returns:
      String representation
    • setLocation

      public void setLocation(double x, double y)
      Set the current position of the polygon and redraw it.
      Overrides:
      setLocation in class Shape
      Parameters:
      x - the x-value of the position
      y - the y-value of the position
    • setSize

      public void setSize(double w, double h)
      Update all polygon points to reflect new size
      Overrides:
      setSize in class Shape
      Parameters:
      w - New width
      h - New height
    • getX

      public double getX(int i)
      Return the x-coordinate of the ith polygon point
      Parameters:
      i - Point number
      Returns:
      x-coordinate of ith point
    • setX

      public void setX(int i, double x)
      Update the x-coordinate of the ith polygon point
      Parameters:
      i - Point number
      x - New x-coordinate value for ith point
    • getY

      public double getY(int i)
      Return the y-coordinate of the ith polygon point
      Parameters:
      i - point number
      Returns:
      y-coordinate of ith point
    • setY

      public void setY(int i, double y)
      Update the y-coordinate of the ith polygon point
      Parameters:
      i - Point number
      y - New y-coordinate value for ith point
    • draw

      public void draw(Graphics2D g)
      Draw the Polygon object
      Specified by:
      draw in class Shape
      Parameters:
      g - The Graphics2D object on which to draw the Polygon