From 4976a25b5e4d14ca4e5e9ab3a451304090c67124 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sun, 21 May 2017 20:59:03 +0200 Subject: [PATCH] Join stroke ends when they coincide --- raster/stroke.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/raster/stroke.go b/raster/stroke.go index bcc66b2..1601bac 100644 --- a/raster/stroke.go +++ b/raster/stroke.go @@ -438,12 +438,19 @@ 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]})) + } 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