mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
op/clip: don't panic when stroking empty path
Fixes: https://todo.sr.ht/~eliasnaur/gio/367 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+15
-11
@@ -49,18 +49,22 @@ func (p Op) add(o *op.Ops) {
|
|||||||
path := p.path
|
path := p.path
|
||||||
|
|
||||||
if !path.hasSegments && p.width > 0 {
|
if !path.hasSegments && p.width > 0 {
|
||||||
if p.path.shape != ops.Rect {
|
switch p.path.shape {
|
||||||
panic("only rects have empty paths")
|
case ops.Rect:
|
||||||
|
b := frect(path.bounds)
|
||||||
|
var rect Path
|
||||||
|
rect.Begin(o)
|
||||||
|
rect.MoveTo(b.Min)
|
||||||
|
rect.LineTo(f32.Pt(b.Max.X, b.Min.Y))
|
||||||
|
rect.LineTo(b.Max)
|
||||||
|
rect.LineTo(f32.Pt(b.Min.X, b.Max.Y))
|
||||||
|
rect.Close()
|
||||||
|
path = rect.End()
|
||||||
|
case ops.Path:
|
||||||
|
// Nothing to do.
|
||||||
|
default:
|
||||||
|
panic("invalid empty path for shape")
|
||||||
}
|
}
|
||||||
b := frect(path.bounds)
|
|
||||||
var rect Path
|
|
||||||
rect.Begin(o)
|
|
||||||
rect.MoveTo(b.Min)
|
|
||||||
rect.LineTo(f32.Pt(b.Max.X, b.Min.Y))
|
|
||||||
rect.LineTo(b.Max)
|
|
||||||
rect.LineTo(f32.Pt(b.Min.X, b.Max.Y))
|
|
||||||
rect.Close()
|
|
||||||
path = rect.End()
|
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
if path.hasSegments {
|
if path.hasSegments {
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ func TestTransformChecks(t *testing.T) {
|
|||||||
st.Pop()
|
st.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyPath(t *testing.T) {
|
||||||
|
var ops op.Ops
|
||||||
|
p := clip.Path{}
|
||||||
|
p.Begin(&ops)
|
||||||
|
defer clip.Stroke{
|
||||||
|
Path: p.End(),
|
||||||
|
Width: 3,
|
||||||
|
}.Op().Push(&ops).Pop()
|
||||||
|
}
|
||||||
|
|
||||||
func newWindow(t testing.TB, width, height int) *headless.Window {
|
func newWindow(t testing.TB, width, height int) *headless.Window {
|
||||||
w, err := headless.NewWindow(width, height)
|
w, err := headless.NewWindow(width, height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user