internal/restorable: refactoring

This commit is contained in:
Hajime Hoshi 2023-03-10 01:57:07 +09:00
parent 8f2097d55e
commit 46173ffec6

View File

@ -697,37 +697,18 @@ func (i *Image) InternalSize() (int, int) {
} }
func (i *Image) appendRegionsForDrawTriangles(regions []image.Rectangle) []image.Rectangle { func (i *Image) appendRegionsForDrawTriangles(regions []image.Rectangle) []image.Rectangle {
origIndex := len(regions) n := len(regions)
for _, d := range i.drawTrianglesHistory { for _, d := range i.drawTrianglesHistory {
r := regionToRectangle(d.dstRegion) r := regionToRectangle(d.dstRegion)
if r.Empty() { if r.Empty() {
continue continue
} }
// Replace duplicated regions with empty regions.
for i, rr := range regions[origIndex:] {
if rr.Empty() {
continue
}
if rr.In(r) {
regions[origIndex+i] = image.Rectangle{}
}
}
regions = append(regions, r) regions = append(regions, r)
} }
// Remove empty regions. origRegions := regions[:n]
n := origIndex newRegions := removeDuplicatedRegions(regions[n:])
for _, r := range regions[origIndex:] { return append(origRegions, newRegions...)
if r.Empty() {
continue
}
regions[n] = r
n++
}
return regions[:n]
} }
func regionToRectangle(region graphicsdriver.Region) image.Rectangle { func regionToRectangle(region graphicsdriver.Region) image.Rectangle {