fix: clamp subimage

This commit is contained in:
cha0s 2022-04-12 09:20:25 -05:00
parent d8a2fb8b92
commit ef4655bbe8

View File

@ -1,3 +1,4 @@
import {Rectangle} from '@avocado/math';
import {Resource} from '@avocado/resource';
import {imageSize} from 'image-size';
import LRU from 'lru-cache';
@ -116,15 +117,21 @@ export default class Image extends Resource {
[, , subimage.texture.width, subimage.texture.height] = rectangle;
}
else {
const frame = {
x: rectangle[0],
y: rectangle[1],
width: rectangle[2],
height: rectangle[3],
};
// eslint-disable-next-line global-require
const {Texture} = require('@pixi/core');
subimage.texture = new Texture(this.texture, frame);
const intersection = Rectangle.intersection(
Rectangle.compose([0, 0], this.size),
rectangle,
);
if (!Rectangle.isNull(intersection)) {
const frame = {
x: intersection[0],
y: intersection[1],
width: intersection[2],
height: intersection[3],
};
// eslint-disable-next-line global-require
const {Texture} = require('@pixi/core');
subimage.texture = new Texture(this.texture, frame);
}
}
return subimage;
}