forked from joejulian/gio
op/clip: don't accept open Paths for Outline
Outline represents a clipping operations that clips all drawing outside a closed path. Before this change, paths not closed we're patched up by adding an implicit line from the endpoint to the beginning. These fixups are inefficient for a rare case, but acceptable because the old renderer post-processes all paths anyway. However, the new compute renderer don't need post-processing in most cases, making fixups too expensive. Given that clipping to an open path is fundamentally undefined and that implicit fixup with a closing line segment is merely a way to force the clip to be well-defined, this change adds a panic to Outline for Paths that are not closed. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package clip
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
func TestOpenPathOutlinePanic(t *testing.T) {
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Error("Outline of an open path didn't panic")
|
||||
}
|
||||
}()
|
||||
var p Path
|
||||
p.Begin(new(op.Ops))
|
||||
p.Line(f32.Pt(10, 10))
|
||||
Outline{Path: p.End()}.Op()
|
||||
}
|
||||
Reference in New Issue
Block a user