Polygon

public class Polygon: Shape

Polygon is a concrete subclass of Shape that has a special initialzer that creates a non-uniform shape made up of 3 or more points.

  • Returns the array of points that make up the polygon.

    Assigning an array of Point values to this object will cause the receiver to update itself.

    let p = Polygon()
    let a = Point()
    let b = Point(100,100)
    let c = Point(200,0)
    p.points = [a,b,c]
    p.center = canvas.center
    canvas.add(p)
    

    Declaration

    Swift

    public var points: [Point]
  • Initializes a default Polygon.

    Declaration

    Swift

    public override init()
  • Initializes a new Polygon using the specified array of points.

    Protects against trying to create a polygon with only 1 point (i.e. requires 2 or more points).

    let a = Point()
    let b = Point(100,100)
    let c = Point(200,0)
    let p = Polygon([a,b,c])
    p.center = canvas.center
    canvas.add(p)
    

    Declaration

    Swift

    public init(_ points: [Point])

    Parameters

    points

    An array of Point structs.

  • Initializes a new Polygon from data in a given unarchiver. - parameter coder: An unarchiver object.

    Declaration

    Swift

    required public init(coder: NSCoder)

    Parameters

    coder

    An unarchiver object.

  • Closes the shape.

    This method appends a line between the shape’s last point and its first point.

    Declaration

    Swift

    public func close()