您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
837B

  1. // Package path provides objects to define lines on a sewing pattern.
  2. package path
  3. import (
  4. "git.wtrh.nl/patterns/gopatterns/pkg/pattern/point"
  5. "github.com/tdewolff/canvas"
  6. )
  7. // Path defines a set of straight lines through points.
  8. type Path struct {
  9. points []point.Point
  10. style Style
  11. }
  12. // NewPath returns a new [Path].
  13. func NewPath(points []point.Point, style Style) *Path {
  14. return &Path{points: points, style: style}
  15. }
  16. // WithStyle updates the style of the Path.
  17. func (p *Path) WithStyle(Style Style) *Path {
  18. p.style = Style
  19. return p
  20. }
  21. // Draw the path to the provided [canvas.Canvas].
  22. func (p *Path) Draw(c *canvas.Canvas) error {
  23. polyline := canvas.Polyline{}
  24. for _, next := range p.points {
  25. polyline.Add(next.Vector().Values())
  26. }
  27. c.RenderPath(polyline.ToPath(), p.style.ToCanvas(), canvas.Identity)
  28. return nil
  29. }