| @@ -16,9 +16,9 @@ type Path struct { | |||||
| } | } | ||||
| // NewPath returns a new [Path]. | // NewPath returns a new [Path]. | ||||
| func NewPath(points ...point.Point) Path { | |||||
| func NewPath(points ...point.Point) *Path { | |||||
| black := canvas.Black | 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. | // 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} | 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]. | // 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{} | polyline := canvas.Polyline{} | ||||
| for _, next := range p.points { | for _, next := range p.points { | ||||
| polyline.Add(next.Vector().Values()) | polyline.Add(next.Vector().Values()) | ||||
| @@ -12,7 +12,7 @@ const resolution = 40 | |||||
| // Spline defines a smooth curved path through points. | // Spline defines a smooth curved path through points. | ||||
| type Spline struct { | type Spline struct { | ||||
| Path | |||||
| *Path | |||||
| start, end point.Point | 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]) | 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) | return fmt.Errorf("draw spline points to canvas: %w", err) | ||||
| } | } | ||||
| @@ -13,6 +13,11 @@ type Lines []Line | |||||
| type Line struct { | type Line struct { | ||||
| Through []point.ID `yaml:"through"` | Through []point.ID `yaml:"through"` | ||||
| Curve *Curve `yaml:"curve,omitempty"` | 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. | // 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: | case l.Curve != nil: | ||||
| startPoint := pat.GetPoint(l.Curve.Start) | startPoint := pat.GetPoint(l.Curve.Start) | ||||
| endPoint := pat.GetPoint(l.Curve.End) | 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: | 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 | return nil | ||||
| @@ -97,6 +97,11 @@ components: | |||||
| $ref: '#/components/schemas/pointID' | $ref: '#/components/schemas/pointID' | ||||
| end: | end: | ||||
| $ref: '#/components/schemas/pointID' | $ref: '#/components/schemas/pointID' | ||||
| style: | |||||
| type: object | |||||
| properties: | |||||
| thickness: | |||||
| type: number | |||||
| pointID: | pointID: | ||||
| oneOf: | oneOf: | ||||
| - type: integer | - type: integer | ||||