Class Polygon

java.lang.Object
ch.epfl.cs107.play.math.shape.Shape
ch.epfl.cs107.play.math.shape.Polygon

public final class Polygon extends Shape
Represents a polygon, without self-intersection.
  • Constructor Details

    • Polygon

      public Polygon(List<Vector> points)
      Creates a new polygon.
      Parameters:
      points - (List of Vector): sequence of vertices, not null
    • Polygon

      public Polygon(Vector... points)
      Creates a new polygon.
      Parameters:
      points - (Array of points): sequence of vertices, not null
    • Polygon

      public Polygon(float... points)
      Creates a new polygon.
      Parameters:
      points - (Array of float): sequence of vertices (x1, y1, x2, y2, etc.), not null
  • Method Details

    • getPoints

      public List<Vector> getPoints()
      Returns:
      (List of Vector): unmodifiable vertex list, not null
    • getArea

      public float getArea()
      Specified by:
      getArea in class Shape
      Returns:
      shape area
    • getPerimeter

      public float getPerimeter()
      Specified by:
      getPerimeter in class Shape
      Returns:
      shape perimeter
    • sample

      public Vector sample()
      Description copied from class: Shape
      Sample uniform point inside shape, including border.
      Specified by:
      sample in class Shape
      Returns:
      (Vector): a uniform sample, not null
    • toPath

      public Path2D toPath()
      Specified by:
      toPath in class Shape
      Returns:
      (Path2D): AWT path used for drawing