diff --git a/op/clip/clip.go b/op/clip/clip.go index a8510794..d251d7a0 100644 --- a/op/clip/clip.go +++ b/op/clip/clip.go @@ -49,18 +49,22 @@ func (p Op) add(o *op.Ops) { path := p.path if !path.hasSegments && p.width > 0 { - if p.path.shape != ops.Rect { - panic("only rects have empty paths") + switch p.path.shape { + 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 if path.hasSegments { diff --git a/op/clip/clip_test.go b/op/clip/clip_test.go index 4d32b98e..30fdef0e 100644 --- a/op/clip/clip_test.go +++ b/op/clip/clip_test.go @@ -62,6 +62,16 @@ func TestTransformChecks(t *testing.T) { 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 { w, err := headless.NewWindow(width, height) if err != nil {