Skip to content

Commit 2787d7c

Browse files
committed
Add a failable initializer taking an array of points which returns nil if points doesn't have enough points.
1 parent b7e46ca commit 2787d7c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/SwiftPlot/Renderer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ public struct Polygon {
211211
public init() {
212212
self.init(.zero, .zero, .zero)
213213
}
214+
215+
public init?(points: [Point]) {
216+
guard points.count >= 3 else { return nil }
217+
218+
self.init(points[0], points[1], points[2], tail: points[3...])
219+
}
214220
}
215221

216222
extension Polygon: Sequence {

0 commit comments

Comments
 (0)