From fa942c824f507d9289650ba991428a3605b32d33 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 22 Oct 2022 01:16:29 +0900 Subject: [PATCH] vector: avoid adding too close points Rendering a very thick arc caused some glitches. This change should mitigate this issue. --- vector/path.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vector/path.go b/vector/path.go index 8394a84c5..610e11a08 100644 --- a/vector/path.go +++ b/vector/path.go @@ -31,6 +31,13 @@ const ( CounterClockwise ) +func abs(x float32) float32 { + if x < 0 { + return -x + } + return x +} + type point struct { x float32 y float32 @@ -63,9 +70,13 @@ func (s *subpath) appendPoint(pt point) { if s.closed { panic("vector: a closed subpathment cannot append a new point") } - if s.lastPoint() == pt { + + // Do not add a too close point to the last point. + // This can cause unexpected rendering results. + if lp := s.lastPoint(); abs(lp.x-pt.x) < 1e-2 && abs(lp.y-pt.y) < 1e-2 { return } + s.points = append(s.points, pt) }