Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Join strokes when the first and last points coincide, instead of capping both #50

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions raster/stroke.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,20 @@ func (k *stroker) stroke(q Path) {
if len(k.r) == 0 {
return
}
// TODO(nigeltao): if q is a closed curve then we should join the first and
// last segments instead of capping them.
k.cr.Cap(k.p, k.u, q.lastPoint(), pNeg(k.anorm))

closed := q.firstPoint() == q.lastPoint()
if !closed {
k.cr.Cap(k.p, k.u, q.lastPoint(), pNeg(k.anorm))
} else {
pivot := q.firstPoint()
k.jr.Join(k.p, &k.r, k.u, pivot, k.anorm, pivot.Sub(fixed.Point26_6{k.r[1], k.r[2]}))
k.p.Start(fixed.Point26_6{k.r[len(k.r)-3], k.r[len(k.r)-2]}) // reverse path is now separate
}
addPathReversed(k.p, k.r)
pivot := q.firstPoint()
k.cr.Cap(k.p, k.u, pivot, pivot.Sub(fixed.Point26_6{k.r[1], k.r[2]}))
if !closed {
pivot := q.firstPoint()
k.cr.Cap(k.p, k.u, pivot, pivot.Sub(fixed.Point26_6{k.r[1], k.r[2]}))
}
}

// Stroke adds q stroked with the given width to p. The result is typically
Expand Down