diff --git a/pkg/pattern/path/path.go b/pkg/pattern/path/path.go index 156b690..36b2d7b 100644 --- a/pkg/pattern/path/path.go +++ b/pkg/pattern/path/path.go @@ -16,9 +16,9 @@ type Path struct { } // NewPath returns a new [Path]. -func NewPath(points ...point.Point) Path { +func NewPath(points ...point.Point) *Path { black := canvas.Black - return Path{points: points, color: black, thickness: 0.2} + return &Path{points: points, color: black, thickness: 0.2} } // NewPathWithStyle returns a new [Path] with the specified thickness and color. @@ -26,8 +26,13 @@ func NewPathWithStyle(thickness float64, color color.RGBA, points ...point.Point return Path{points: points, color: color, thickness: thickness} } +// SetThickness updates the tickness of the line +func (p *Path) SetThickness(thickness float64) { + p.thickness = thickness +} + // Draw the path to the provided [canvas.Canvas]. -func (p Path) Draw(c *canvas.Canvas) error { +func (p *Path) Draw(c *canvas.Canvas) error { polyline := canvas.Polyline{} for _, next := range p.points { polyline.Add(next.Vector().Values()) diff --git a/pkg/pattern/path/splines.go b/pkg/pattern/path/splines.go index 2eb81a1..92cf81c 100644 --- a/pkg/pattern/path/splines.go +++ b/pkg/pattern/path/splines.go @@ -12,7 +12,7 @@ const resolution = 40 // Spline defines a smooth curved path through points. type Spline struct { - Path + *Path start, end point.Point } @@ -78,8 +78,10 @@ func (p Spline) Draw(c *canvas.Canvas) error { points = append(points, p.points[len(p.points)-1]) - err = NewPath(points...).Draw(c) - if err != nil { + path := NewPath(points...) + path.SetThickness(p.thickness) + + if err = path.Draw(c); err != nil { return fmt.Errorf("draw spline points to canvas: %w", err) } diff --git a/pkg/pattern/template/line.go b/pkg/pattern/template/line.go index 6f20d68..1a10083 100644 --- a/pkg/pattern/template/line.go +++ b/pkg/pattern/template/line.go @@ -13,6 +13,11 @@ type Lines []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. @@ -32,9 +37,20 @@ func (l Line) Build(pat *pattern.Pattern) error { case l.Curve != nil: startPoint := pat.GetPoint(l.Curve.Start) endPoint := pat.GetPoint(l.Curve.End) - pat.AddLine(path.NewSpline(startPoint, endPoint, points...)) + spline := path.NewSpline(startPoint, endPoint, points...) + + if l.Style != nil && l.Style.Thickness != nil { + spline.SetThickness(*l.Style.Thickness) + } + + pat.AddLine(spline) default: - pat.AddLine(path.NewPath(points...)) + newPath := path.NewPath(points...) + if l.Style != nil && l.Style.Thickness != nil { + newPath.SetThickness(*l.Style.Thickness) + } + + pat.AddLine(newPath) } return nil diff --git a/spec/pattern.yaml b/spec/pattern.yaml index 0614216..0737295 100644 --- a/spec/pattern.yaml +++ b/spec/pattern.yaml @@ -97,6 +97,11 @@ components: $ref: '#/components/schemas/pointID' end: $ref: '#/components/schemas/pointID' + style: + type: object + properties: + thickness: + type: number pointID: oneOf: - type: integer