mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/restorable: reduce more duplicated regions
This commit is contained in:
parent
66db13ef74
commit
f3b49e6543
@ -737,13 +737,19 @@ func regionToRectangle(region graphicsdriver.Region) image.Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// removeDuplicatedRegions removes duplicated regions and returns a shrunk slice.
|
// 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 {
|
func removeDuplicatedRegions(regions []image.Rectangle) []image.Rectangle {
|
||||||
for i, r := range regions {
|
for i, r := range regions {
|
||||||
if r.Empty() {
|
if r.Empty() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for j, rr := range regions[:i] {
|
for j, rr := range regions {
|
||||||
|
if i == j {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if rr.Empty() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if rr.In(r) {
|
if rr.In(r) {
|
||||||
regions[j] = image.Rectangle{}
|
regions[j] = image.Rectangle{}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,6 @@ func TestRemoveDuplicatedRegions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Out: []image.Rectangle{
|
Out: []image.Rectangle{
|
||||||
image.Rect(0, 0, 2, 2),
|
image.Rect(0, 0, 2, 2),
|
||||||
image.Rect(0, 0, 1, 1),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -104,7 +103,6 @@ func TestRemoveDuplicatedRegions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Out: []image.Rectangle{
|
Out: []image.Rectangle{
|
||||||
image.Rect(0, 0, 4, 4),
|
image.Rect(0, 0, 4, 4),
|
||||||
image.Rect(1, 1, 2, 2),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user