From ac800a9d8f26b1a2ec107ed5ba834d63c1ff07cb Mon Sep 17 00:00:00 2001 From: pierre Date: Tue, 16 Mar 2021 17:52:13 +0100 Subject: [PATCH] op/clip: optimize zero corner radius in RRect if pixel-aligned Signed-off-by: pierre --- op/clip/shapes.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/op/clip/shapes.go b/op/clip/shapes.go index c1a1d599..a3862063 100644 --- a/op/clip/shapes.go +++ b/op/clip/shapes.go @@ -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), + } +}