瀏覽代碼

Add line thickness option for templates

undefined
Wouter Horlings 4 月之前
父節點
當前提交
be2fd4227c
共有 3 個檔案被更改,包括 27 行新增6 行删除
  1. +8
    -3
      pkg/pattern/path/path.go
  2. +1
    -1
      pkg/pattern/path/splines.go
  3. +18
    -2
      pkg/pattern/template/line.go

+ 8
- 3
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())


+ 1
- 1
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
}



+ 18
- 2
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


Loading…
取消
儲存