forked from joejulian/gio
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:
+5
-1
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user