vector: improve quality of lines by removing holes

This commit is contained in:
Hajime Hoshi 2022-10-11 00:12:35 +09:00
parent 69c8fd745b
commit ccfedeea1d

View File

@ -396,25 +396,16 @@ func (p *Path) AppendVerticesAndIndicesForStroke(vertices []ebiten.Vertex, indic
// Note that the Y direction and the angle direction are opposite from math's. // Note that the Y direction and the angle direction are opposite from math's.
a0 := float32(math.Atan2(float64(rect[1].y-c.y), float64(rect[1].x-c.x))) a0 := float32(math.Atan2(float64(rect[1].y-c.y), float64(rect[1].x-c.x)))
a1 := float32(math.Atan2(float64(nextRect[0].y-c.y), float64(nextRect[0].x-c.x))) a1 := float32(math.Atan2(float64(nextRect[0].y-c.y), float64(nextRect[0].x-c.x)))
da := a1 - a0 if a0 == a1 {
for da < 0 {
da += 2 * math.Pi
}
if da == 0 {
continue continue
} }
var arc Path // Rendering a small pie might cause unexpected holes due to some errors.
arc.MoveTo(c.x, c.y) // Instead, render a full circle.
if da < math.Pi { var circle Path
arc.LineTo(rect[1].x, rect[1].y) circle.MoveTo(rect[1].x, rect[1].y)
arc.Arc(c.x, c.y, op.Width/2, a0, a1, Clockwise) circle.Arc(c.x, c.y, op.Width/2, 0, 2*math.Pi, Clockwise)
} else { vertices, indices = circle.AppendVerticesAndIndicesForFilling(vertices, indices)
arc.LineTo(rect[3].x, rect[3].y)
arc.Arc(c.x, c.y, op.Width/2, a0+math.Pi, a1+math.Pi, CounterClockwise)
}
arc.MoveTo(c.x, c.y)
vertices, indices = arc.AppendVerticesAndIndicesForFilling(vertices, indices)
} }
} }
return vertices, indices return vertices, indices