|
- 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()
- }
-
- style := path.NewDefaultStyle()
-
- if l.Style != nil && l.Style.Thickness != nil {
- style.Thickness = *l.Style.Thickness
- }
-
- switch {
- case l.Curve != nil:
- pat.AddLine(
- path.NewSpline(path.SplineOpts{
- Start: pat.GetPoint(l.Curve.Start),
- End: pat.GetPoint(l.Curve.End),
- Points: points,
- Style: style,
- }),
- )
- default:
- pat.AddLine(path.NewPath(points, style))
- }
-
- 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
- }
|