Class Polyline

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

public final class Polyline extends Shape
Represents an open or closed sequence of segments. As it has no mass, it can only be used in fixed bodies.
  • Constructor Details

    • Polyline

      public Polyline(boolean closed, List<Vector> points)
      Creates a new polyline.
      Parameters:
      closed - (boolean): whether last point is connected to the first one
      points - (List of Vector): at least two points, not null
    • Polyline

      public Polyline(List<Vector> points)
      Creates a new polyline.
      Parameters:
      points - (List of Vector): at least two points, not null
    • Polyline

      public Polyline(boolean closed, Vector... points)
      Creates a new polyline.
      Parameters:
      closed - (boolean): whether last point is connected to the first one
      points - (Array of Vector): at least two points, not null
    • Polyline

      public Polyline(Vector... points)
      Creates a new polyline.
      Parameters:
      points - (Array of Vector): at least two points, not null
    • Polyline

      public Polyline(boolean closed, float... points)
      Creates a new polyline.
      Parameters:
      closed - (boolean): whether last point is connected to the first one
      points - (Array of float): at least two points (x1, y1, x2, y2, etc.), not null
    • Polyline

      public Polyline(float... points)
      Creates a new polyline.
      Parameters:
      points - at least two points, not null
  • Method Details

    • isClosed

      public boolean isClosed()
      Returns:
      (boolean): whether last point is connected to the first one
    • getPoints

      public List<Vector> getPoints()
      Returns:
      (List of Vector): an immutable list of points, 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