mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
op/clip: fix Path open state
If a Move/MoveTo did not move the pen, the Path was still set as open. Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -154,6 +154,9 @@ func (p *Path) Move(delta f32.Point) {
|
|||||||
|
|
||||||
// MoveTo moves the pen to the specified absolute coordinate.
|
// MoveTo moves the pen to the specified absolute coordinate.
|
||||||
func (p *Path) MoveTo(to f32.Point) {
|
func (p *Path) MoveTo(to f32.Point) {
|
||||||
|
if p.pen == to {
|
||||||
|
return
|
||||||
|
}
|
||||||
p.open = p.open || p.pen != p.start
|
p.open = p.open || p.pen != p.start
|
||||||
p.end()
|
p.end()
|
||||||
p.pen = to
|
p.pen = to
|
||||||
|
|||||||
+20
-1
@@ -4,6 +4,7 @@ package clip_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
@@ -13,7 +14,8 @@ import (
|
|||||||
"gioui.org/op/paint"
|
"gioui.org/op/paint"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOpenPathOutlinePanic(t *testing.T) {
|
func TestPathOutline(t *testing.T) {
|
||||||
|
t.Run("unclosed path", func(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err == nil {
|
if err := recover(); err == nil {
|
||||||
t.Error("Outline of an open path didn't panic")
|
t.Error("Outline of an open path didn't panic")
|
||||||
@@ -23,6 +25,23 @@ func TestOpenPathOutlinePanic(t *testing.T) {
|
|||||||
p.Begin(new(op.Ops))
|
p.Begin(new(op.Ops))
|
||||||
p.Line(f32.Pt(10, 10))
|
p.Line(f32.Pt(10, 10))
|
||||||
clip.Outline{Path: p.End()}.Op()
|
clip.Outline{Path: p.End()}.Op()
|
||||||
|
})
|
||||||
|
t.Run("closed path", func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
t.Error("Outline of a closed path did panic")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
var p clip.Path
|
||||||
|
p.Begin(new(op.Ops))
|
||||||
|
p.MoveTo(f32.Pt(300, 200))
|
||||||
|
p.LineTo(f32.Pt(150, 200))
|
||||||
|
p.MoveTo(f32.Pt(150, 200))
|
||||||
|
p.ArcTo(f32.Pt(300, 200), f32.Pt(300, 200), 3*math.Pi/4)
|
||||||
|
p.LineTo(f32.Pt(300, 200))
|
||||||
|
p.Close()
|
||||||
|
clip.Outline{Path: p.End()}.Op()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPathBegin(t *testing.T) {
|
func TestPathBegin(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user