mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
internal/stroke: don't draw round join if angle is NaN
References: https://todo.sr.ht/~eliasnaur/gio/331 Signed-off-by: Andy Balholm <andy@balholm.com>
This commit is contained in:
@@ -207,6 +207,32 @@ func TestStrokedPathCoincidentControlPoint(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStrokedPathBalloon(t *testing.T) {
|
||||||
|
run(t, func(o *op.Ops) {
|
||||||
|
// This shape is based on the one drawn by the Bubble function in
|
||||||
|
// github.com/llgcode/draw2d/samples/geometry/geometry.go.
|
||||||
|
p := new(clip.Path)
|
||||||
|
p.Begin(o)
|
||||||
|
p.MoveTo(f32.Pt(42.69375, 10.5))
|
||||||
|
p.CubeTo(f32.Pt(42.69375, 10.5), f32.Pt(14.85, 10.5), f32.Pt(14.85, 31.5))
|
||||||
|
p.CubeTo(f32.Pt(14.85, 31.5), f32.Pt(14.85, 52.5), f32.Pt(28.771875, 52.5))
|
||||||
|
p.CubeTo(f32.Pt(28.771875, 52.5), f32.Pt(28.771875, 63.7), f32.Pt(17.634375, 66.5))
|
||||||
|
p.CubeTo(f32.Pt(17.634375, 66.5), f32.Pt(34.340626, 63.7), f32.Pt(37.125, 52.5))
|
||||||
|
p.CubeTo(f32.Pt(37.125, 52.5), f32.Pt(70.5375, 52.5), f32.Pt(70.5375, 31.5))
|
||||||
|
p.CubeTo(f32.Pt(70.5375, 31.5), f32.Pt(70.5375, 10.5), f32.Pt(42.69375, 10.5))
|
||||||
|
cl := clip.Stroke{
|
||||||
|
Path: p.End(),
|
||||||
|
Width: 2.83,
|
||||||
|
}.Op().Push(o)
|
||||||
|
paint.Fill(o, black)
|
||||||
|
cl.Pop()
|
||||||
|
}, func(r result) {
|
||||||
|
r.expect(0, 0, transparent)
|
||||||
|
r.expect(70, 52, colornames.Black)
|
||||||
|
r.expect(70, 90, transparent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestPathReuse(t *testing.T) {
|
func TestPathReuse(t *testing.T) {
|
||||||
run(t, func(o *op.Ops) {
|
run(t, func(o *op.Ops) {
|
||||||
var path clip.Path
|
var path clip.Path
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -510,14 +510,18 @@ func strokePathRoundJoin(rhs, lhs *StrokeQuads, hw float32, pivot, n0, n1 f32.Po
|
|||||||
// Path bends to the right, ie. CW (or 180 degree turn).
|
// Path bends to the right, ie. CW (or 180 degree turn).
|
||||||
c := pivot.Sub(lhs.pen())
|
c := pivot.Sub(lhs.pen())
|
||||||
angle := -math.Acos(float64(cosPt(n0, n1)))
|
angle := -math.Acos(float64(cosPt(n0, n1)))
|
||||||
lhs.arc(c, c, float32(angle))
|
if !math.IsNaN(angle) {
|
||||||
|
lhs.arc(c, c, float32(angle))
|
||||||
|
}
|
||||||
lhs.lineTo(lp) // Add a line to accommodate for rounding errors.
|
lhs.lineTo(lp) // Add a line to accommodate for rounding errors.
|
||||||
rhs.lineTo(rp)
|
rhs.lineTo(rp)
|
||||||
default:
|
default:
|
||||||
// Path bends to the left, ie. CCW.
|
// Path bends to the left, ie. CCW.
|
||||||
angle := math.Acos(float64(cosPt(n0, n1)))
|
angle := math.Acos(float64(cosPt(n0, n1)))
|
||||||
c := pivot.Sub(rhs.pen())
|
c := pivot.Sub(rhs.pen())
|
||||||
rhs.arc(c, c, float32(angle))
|
if !math.IsNaN(angle) {
|
||||||
|
rhs.arc(c, c, float32(angle))
|
||||||
|
}
|
||||||
rhs.lineTo(rp) // Add a line to accommodate for rounding errors.
|
rhs.lineTo(rp) // Add a line to accommodate for rounding errors.
|
||||||
lhs.lineTo(lp)
|
lhs.lineTo(lp)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user