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 <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-11-13 17:58:23 +01:00
committed by Elias Naur
parent 40bc2e1f88
commit 6bfd980044
2 changed files with 23 additions and 1 deletions
+5 -1
View File
@@ -158,10 +158,14 @@ func (e Ellipse) Push(ops *op.Ops) Stack {
// path constructs a path for the ellipse.
func (e Ellipse) path(o *op.Ops) PathSpec {
bounds := f32.Rectangle(e)
if bounds.Dx() == 0 || bounds.Dy() == 0 {
return PathSpec{shape: ops.Rect}
}
var p Path
p.Begin(o)
bounds := f32.Rectangle(e)
center := bounds.Max.Add(bounds.Min).Mul(.5)
diam := bounds.Dx()
r := diam * .5
+18
View File
@@ -0,0 +1,18 @@
package clip_test
import (
"image/color"
"testing"
"gioui.org/f32"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
func TestZeroEllipse(t *testing.T) {
p := f32.Pt(1.0, 2.0)
e := clip.Ellipse{Min: p, Max: p}
ops := new(op.Ops)
paint.FillShape(ops, color.NRGBA{R: 255, A: 255}, e.Op(ops))
}