mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
f32: handle empty rectangles in Union and Intersect
The old renderer depends on the old behaviour of Union, so change that reference to a copy. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -101,11 +101,20 @@ func (r Rectangle) Intersect(s Rectangle) Rectangle {
|
||||
if r.Max.Y > s.Max.Y {
|
||||
r.Max.Y = s.Max.Y
|
||||
}
|
||||
if r.Empty() {
|
||||
return Rectangle{}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Union returns the union of r and s.
|
||||
func (r Rectangle) Union(s Rectangle) Rectangle {
|
||||
if r.Empty() {
|
||||
return s
|
||||
}
|
||||
if s.Empty() {
|
||||
return r
|
||||
}
|
||||
if r.Min.X > s.Min.X {
|
||||
r.Min.X = s.Min.X
|
||||
}
|
||||
|
||||
+18
-1
@@ -93,5 +93,22 @@ func (qs *quadSplitter) splitAndEncode(quad stroke.QuadSegment) {
|
||||
}
|
||||
}
|
||||
|
||||
qs.bounds = qs.bounds.Union(cbnd)
|
||||
qs.bounds = unionRect(qs.bounds, cbnd)
|
||||
}
|
||||
|
||||
// Union is like f32.Rectangle.Union but ignores empty rectangles.
|
||||
func unionRect(r, s f32.Rectangle) f32.Rectangle {
|
||||
if r.Min.X > s.Min.X {
|
||||
r.Min.X = s.Min.X
|
||||
}
|
||||
if r.Min.Y > s.Min.Y {
|
||||
r.Min.Y = s.Min.Y
|
||||
}
|
||||
if r.Max.X < s.Max.X {
|
||||
r.Max.X = s.Max.X
|
||||
}
|
||||
if r.Max.Y < s.Max.Y {
|
||||
r.Max.Y = s.Max.Y
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user