vector: avoid adding too close points

Rendering a very thick arc caused some glitches. This change should
mitigate this issue.
This commit is contained in:
Hajime Hoshi 2022-10-22 01:16:29 +09:00
parent 6f7b1a81d7
commit fa942c824f

View File

@ -31,6 +31,13 @@ const (
CounterClockwise CounterClockwise
) )
func abs(x float32) float32 {
if x < 0 {
return -x
}
return x
}
type point struct { type point struct {
x float32 x float32
y float32 y float32
@ -63,9 +70,13 @@ func (s *subpath) appendPoint(pt point) {
if s.closed { if s.closed {
panic("vector: a closed subpathment cannot append a new point") 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 return
} }
s.points = append(s.points, pt) s.points = append(s.points, pt)
} }