Add a PolyLine function

This commit is contained in:
Sasha Koshka 2023-07-01 11:01:51 -04:00
parent 1003203bb1
commit c8b022f5f1

View File

@ -5,7 +5,7 @@ import "image"
func (this Image[T]) FillPolygon (fill []T, points ...image.Point) { func (this Image[T]) FillPolygon (fill []T, points ...image.Point) {
this.assertWidth(fill) 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 // figure out the bounds of the polygon so we don't test empty space
var area image.Rectangle var area image.Rectangle
@ -88,3 +88,12 @@ func (this Image[T]) StrokePolygon (stroke []T, weight int, points ...image.Poin
prevPoint = point 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
}
}