Skip to content

Commit 6bfd980

Browse files
pierreceliasnaur
authored andcommitted
op/clip: don't panic on zero-sized Ellipse
When the rectangle used in an Ellipse has no width or height, the path would panic with "path not closed". Use an empty rectangle path in that case instead. Signed-off-by: Pierre Curto <[email protected]>
1 parent 40bc2e1 commit 6bfd980

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

op/clip/shapes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,14 @@ func (e Ellipse) Push(ops *op.Ops) Stack {
158158

159159
// path constructs a path for the ellipse.
160160
func (e Ellipse) path(o *op.Ops) PathSpec {
161+
bounds := f32.Rectangle(e)
162+
if bounds.Dx() == 0 || bounds.Dy() == 0 {
163+
return PathSpec{shape: ops.Rect}
164+
}
165+
161166
var p Path
162167
p.Begin(o)
163168

164-
bounds := f32.Rectangle(e)
165169
center := bounds.Max.Add(bounds.Min).Mul(.5)
166170
diam := bounds.Dx()
167171
r := diam * .5

op/clip/shapes_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package clip_test
2+
3+
import (
4+
"image/color"
5+
"testing"
6+
7+
"gioui.org/f32"
8+
"gioui.org/op"
9+
"gioui.org/op/clip"
10+
"gioui.org/op/paint"
11+
)
12+
13+
func TestZeroEllipse(t *testing.T) {
14+
p := f32.Pt(1.0, 2.0)
15+
e := clip.Ellipse{Min: p, Max: p}
16+
ops := new(op.Ops)
17+
paint.FillShape(ops, color.NRGBA{R: 255, A: 255}, e.Op(ops))
18+
}

0 commit comments

Comments
 (0)