op/clip: optimize zero corner radius in RRect if pixel-aligned

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-03-16 17:52:13 +01:00
committed by Elias Naur
parent eeb045c59f
commit ac800a9d8f
+16
View File
@@ -51,6 +51,16 @@ type RRect struct {
// Op returns the op for the rounded rectangle.
func (rr RRect) Op(ops *op.Ops) Op {
if rr.SE == 0 && rr.SW == 0 && rr.NW == 0 && rr.NE == 0 {
r := image.Rectangle{
Min: image.Point{X: int(rr.Rect.Min.X), Y: int(rr.Rect.Min.Y)},
Max: image.Point{X: int(rr.Rect.Max.X), Y: int(rr.Rect.Max.Y)},
}
// Only use Rect if rr is pixel-aligned, as Rect is guaranteed to be.
if fPt(r.Min) == rr.Rect.Min && fPt(r.Max) == rr.Rect.Max {
return Rect(r).Op()
}
}
return Outline{Path: rr.Path(ops)}.Op()
}
@@ -149,3 +159,9 @@ func (c Circle) Path(ops *op.Ops) PathSpec {
)
return p.End()
}
func fPt(p image.Point) f32.Point {
return f32.Point{
X: float32(p.X), Y: float32(p.Y),
}
}