Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

54 строки
1.2KB

  1. package template
  2. import (
  3. "git.wtrh.nl/patterns/gopatterns/pkg/pattern"
  4. "git.wtrh.nl/patterns/gopatterns/pkg/pattern/path"
  5. "git.wtrh.nl/patterns/gopatterns/pkg/pattern/point"
  6. )
  7. // Lines contains one Line or more in a slice.
  8. type Lines []Line
  9. // Line describes a pattern line.
  10. type Line struct {
  11. Through []point.ID `yaml:"through"`
  12. Curve *Curve `yaml:"curve,omitempty"`
  13. }
  14. // Curve describes if a Line curves and if it has start and end constraints.
  15. type Curve struct {
  16. Start point.ID `yaml:"start,omitempty"`
  17. End point.ID `yaml:"end,omitempty"`
  18. }
  19. // Build adds the line to the provided [pattern.Pattern].
  20. func (l Line) Build(pat *pattern.Pattern) error {
  21. points := pat.GetPoints(l.Through...)
  22. for _, p := range points {
  23. p.SetDraw()
  24. }
  25. switch {
  26. case l.Curve != nil:
  27. startPoint := pat.GetPoint(l.Curve.Start)
  28. endPoint := pat.GetPoint(l.Curve.End)
  29. pat.AddLine(path.NewSpline(startPoint, endPoint, points...))
  30. default:
  31. pat.AddLine(path.NewPath(points...))
  32. }
  33. return nil
  34. }
  35. // Build adds all the lines to the provided [pattern.Pattern].
  36. func (l Lines) Build(pat *pattern.Pattern) error {
  37. for _, line := range l {
  38. err := line.Build(pat)
  39. if err != nil {
  40. return err
  41. }
  42. }
  43. return nil
  44. }