LinePolygon2

public extension LinePolygon2
extension LinePolygon2 where Vector: Vector2Multiplicative
extension LinePolygon2 where Vector: Vector2Multiplicative, Vector.Scalar: DivisibleArithmetic
extension LinePolygon2 where Vector: Vector2Multiplicative & VectorComparable
extension LinePolygon2: VolumetricType where Vector: VectorDivisible & VectorComparable
extension LinePolygon2 where Vector: VectorFloatingPoint
extension LinePolygon2 where Vector: Vector2FloatingPoint
  • Adds a new 2D vertex at the end of this polygon’s vertices list

    Declaration

    Swift

    mutating func addVertex(x: Scalar, y: Scalar)

Available where Vector: Vector2Multiplicative

  • Returns the winding number for this polygon.

    The winding number is the sum of the cross products of each adjacent edge’s slope.

    Positive values indicate clockwise orientation in an (X-Right, Y-Up) space, while negative indicate counter-clockwise.

    If this polygon has less than 3 points, .zero is returned instead.

    Declaration

    Swift

    public func winding() -> Vector.Scalar

Available where Vector: Vector2Multiplicative, Vector.Scalar: DivisibleArithmetic

  • Returns the signed area of this 2D polygon.

    Positive values indicate clockwise orientation in an (X-Right, Y-Up) space, while negative indicate counter-clockwise.

    Declaration

    Swift

    public func area() -> Vector.Scalar
  • Returns the squared perimeter of this 2D polygon.

    Declaration

    Swift

    @inlinable
    public func perimeterSquared() -> Vector.Scalar

Available where Vector: Vector2Multiplicative & VectorComparable

  • Returns true if this polygon is convex.

    A polygon must have at least 3 points to be considered convex.

    If the polygon self-intersects, false is returned.

    Declaration

    Swift

    public func isConvex() -> Bool

Available where Vector: VectorDivisible & VectorComparable

  • Assuming this LinePolygon2 represents a clockwise closed polygon, performs a vector-containment check against the polygon formed by this polygon’s vertices.

    Declaration

    Swift

    @inlinable
    public func contains(_ vector: Vector) -> Bool

Available where Vector: VectorFloatingPoint

  • Returns true if the given point lies within an edge of the polygon represented by self, up to a given toleranceSquared value.

    Points lie within the edges of the polygon if the distance between the point and any two adjacent vertices is equal to the distance of the adjacent vertices, up to √(toleranceSquared).

    Declaration

    Swift

    @inlinable
    public func isPointOnEdge(_ point: Vector, toleranceSquared: Scalar) -> Bool

Available where Vector: Vector2FloatingPoint

  • Returns the perimeter of this 2D polygon.

    Declaration

    Swift

    public func perimeter() -> Vector.Scalar