|
- package template
-
- import (
- "git.wtrh.nl/wouter/gopatterns/pkg/pattern"
- "git.wtrh.nl/wouter/gopatterns/pkg/pattern/path"
- "git.wtrh.nl/wouter/gopatterns/pkg/pattern/point"
- )
-
- // Lines contains one Line or more in a slice.
- type Lines []Line
-
- // Line describes a pattern line.
- type Line struct {
- Through []point.ID `yaml:"through"`
- Curve *Curve `yaml:"curve,omitempty"`
- }
-
- // Curve describes if a Line curves and if it has start and end constraints.
- type Curve struct {
- Start point.ID `yaml:"start,omitempty"`
- End point.ID `yaml:"end,omitempty"`
- }
-
- // Build adds the line to the provided [pattern.Pattern].
- func (l Line) Build(pat *pattern.Pattern) error {
- points := pat.GetPoints(l.Through...)
- for _, p := range points {
- p.SetDraw()
- }
-
- switch {
- case l.Curve != nil:
- startPoint := pat.GetPoint(l.Curve.Start)
- endPoint := pat.GetPoint(l.Curve.End)
- pat.AddLine(path.NewSpline(startPoint, endPoint, points...))
- default:
- pat.AddLine(path.NewPath(points...))
- }
-
- return nil
- }
-
- // Build adds all the lines to the provided [pattern.Pattern].
- func (l Lines) Build(pat *pattern.Pattern) error {
- for _, line := range l {
- err := line.Build(pat)
- if err != nil {
- return err
- }
- }
-
- return nil
- }
|