mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
f32,gpu,op/clip: add f32.Rectangle method for converting to image.Rectangle
Creating an image.Rectangle from a f32.Rectangle is used by two packages in Gio and about to be used for a third. Add a Round method to f32.Rectangle to avoid duplicating the implementation. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-23
@@ -157,7 +157,7 @@ func (p *Path) End() PathSpec {
|
||||
return PathSpec{
|
||||
spec: c,
|
||||
hasSegments: p.hasSegments,
|
||||
bounds: boundRectF(p.bounds),
|
||||
bounds: p.bounds.Round(),
|
||||
hash: p.hash.Sum64(),
|
||||
}
|
||||
}
|
||||
@@ -238,28 +238,6 @@ func (p *Path) expand(pt f32.Point) {
|
||||
}
|
||||
}
|
||||
|
||||
// boundRectF returns a bounding image.Rectangle for a f32.Rectangle.
|
||||
func boundRectF(r f32.Rectangle) image.Rectangle {
|
||||
return image.Rectangle{
|
||||
Min: image.Point{
|
||||
X: int(floor(r.Min.X)),
|
||||
Y: int(floor(r.Min.Y)),
|
||||
},
|
||||
Max: image.Point{
|
||||
X: int(ceil(r.Max.X)),
|
||||
Y: int(ceil(r.Max.Y)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ceil(v float32) int {
|
||||
return int(math.Ceil(float64(v)))
|
||||
}
|
||||
|
||||
func floor(v float32) int {
|
||||
return int(math.Floor(float64(v)))
|
||||
}
|
||||
|
||||
// Quad records a quadratic Bézier from the pen to end
|
||||
// with the control point ctrl.
|
||||
func (p *Path) Quad(ctrl, to f32.Point) {
|
||||
|
||||
Reference in New Issue
Block a user