|
- package template
-
- import (
- "git.wtrh.nl/patterns/gopatterns/pkg/pattern"
- "git.wtrh.nl/patterns/gopatterns/pkg/pattern/path"
- "git.wtrh.nl/patterns/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"`
- Style *Style `yaml:"style,omitempty"`
- }
-
- type Style struct {
- Thickness *float64 `yaml:"thickness,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)
- spline := path.NewSpline(startPoint, endPoint, points...)
-
- if l.Style != nil && l.Style.Thickness != nil {
- spline.SetThickness(*l.Style.Thickness)
- }
-
- pat.AddLine(spline)
- default:
- newPath := path.NewPath(points...)
- if l.Style != nil && l.Style.Thickness != nil {
- newPath.SetThickness(*l.Style.Thickness)
- }
-
- pat.AddLine(newPath)
- }
-
- 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
- }
|