// Package path provides objects to define lines on a sewing pattern. package path import ( "git.wtrh.nl/patterns/gopatterns/pkg/pattern/point" "github.com/tdewolff/canvas" ) // Path defines a set of straight lines through points. type Path struct { points []point.Point style Style } // NewPath returns a new [Path]. func NewPath(points []point.Point, style Style) *Path { return &Path{points: points, style: style} } // WithStyle updates the style of the Path. func (p *Path) WithStyle(Style Style) *Path { p.style = Style return p } // Draw the path to the provided [canvas.Canvas]. func (p *Path) Draw(c *canvas.Canvas) error { polyline := canvas.Polyline{} for _, next := range p.points { polyline.Add(next.Vector().Values()) } c.RenderPath(polyline.ToPath(), p.style.ToCanvas(), canvas.Identity) return nil }