No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

70 líneas
1.5KB

  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. Style *Style `yaml:"style,omitempty"`
  14. }
  15. type Style struct {
  16. Thickness *float64 `yaml:"thickness,omitempty"`
  17. }
  18. // Curve describes if a Line curves and if it has start and end constraints.
  19. type Curve struct {
  20. Start point.ID `yaml:"start,omitempty"`
  21. End point.ID `yaml:"end,omitempty"`
  22. }
  23. // Build adds the line to the provided [pattern.Pattern].
  24. func (l Line) Build(pat *pattern.Pattern) error {
  25. points := pat.GetPoints(l.Through...)
  26. for _, p := range points {
  27. p.SetDraw()
  28. }
  29. switch {
  30. case l.Curve != nil:
  31. startPoint := pat.GetPoint(l.Curve.Start)
  32. endPoint := pat.GetPoint(l.Curve.End)
  33. spline := path.NewSpline(startPoint, endPoint, points...)
  34. if l.Style != nil && l.Style.Thickness != nil {
  35. spline.SetThickness(*l.Style.Thickness)
  36. }
  37. pat.AddLine(spline)
  38. default:
  39. newPath := path.NewPath(points...)
  40. if l.Style != nil && l.Style.Thickness != nil {
  41. newPath.SetThickness(*l.Style.Thickness)
  42. }
  43. pat.AddLine(newPath)
  44. }
  45. return nil
  46. }
  47. // Build adds all the lines to the provided [pattern.Pattern].
  48. func (l Lines) Build(pat *pattern.Pattern) error {
  49. for _, line := range l {
  50. err := line.Build(pat)
  51. if err != nil {
  52. return err
  53. }
  54. }
  55. return nil
  56. }