From c8b022f5f1ea0d0f2344beab5ffb37af1ef0e3f0 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 1 Jul 2023 11:01:51 -0400 Subject: [PATCH] Add a PolyLine function --- polygon.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/polygon.go b/polygon.go index 2ddcf19..56e901c 100644 --- a/polygon.go +++ b/polygon.go @@ -5,7 +5,7 @@ import "image" func (this Image[T]) FillPolygon (fill []T, points ...image.Point) { this.assertWidth(fill) - if len(points) < 2 { return } + if len(points) < 3 { return } // figure out the bounds of the polygon so we don't test empty space var area image.Rectangle @@ -88,3 +88,12 @@ func (this Image[T]) StrokePolygon (stroke []T, weight int, points ...image.Poin prevPoint = point } } + +func (this Image[T]) PolyLine (stroke []T, weight int, points ...image.Point) { + if len(points) < 2 { return } + prevPoint := points[0] + for _, point := range points[1:] { + this.Line(stroke, weight, prevPoint, point) + prevPoint = point + } +}