internal/restorable: reduce more duplicated regions

This commit is contained in:
Hajime Hoshi 2023-03-09 22:57:01 +09:00
parent 66db13ef74
commit f3b49e6543
2 changed files with 8 additions and 4 deletions

View File

@ -737,13 +737,19 @@ func regionToRectangle(region graphicsdriver.Region) image.Rectangle {
}
// removeDuplicatedRegions removes duplicated regions and returns a shrunk slice.
// If a region covers preceding regions, the covered regions are removed.
// If a region covers other regions, the covered regions are removed.
func removeDuplicatedRegions(regions []image.Rectangle) []image.Rectangle {
for i, r := range regions {
if r.Empty() {
continue
}
for j, rr := range regions[:i] {
for j, rr := range regions {
if i == j {
continue
}
if rr.Empty() {
continue
}
if rr.In(r) {
regions[j] = image.Rectangle{}
}

View File

@ -59,7 +59,6 @@ func TestRemoveDuplicatedRegions(t *testing.T) {
},
Out: []image.Rectangle{
image.Rect(0, 0, 2, 2),
image.Rect(0, 0, 1, 1),
},
},
{
@ -104,7 +103,6 @@ func TestRemoveDuplicatedRegions(t *testing.T) {
},
Out: []image.Rectangle{
image.Rect(0, 0, 4, 4),
image.Rect(1, 1, 2, 2),
},
},
{