fix: clamp subimage
This commit is contained in:
parent
d8a2fb8b92
commit
ef4655bbe8
|
@ -1,3 +1,4 @@
|
||||||
|
import {Rectangle} from '@avocado/math';
|
||||||
import {Resource} from '@avocado/resource';
|
import {Resource} from '@avocado/resource';
|
||||||
import {imageSize} from 'image-size';
|
import {imageSize} from 'image-size';
|
||||||
import LRU from 'lru-cache';
|
import LRU from 'lru-cache';
|
||||||
|
@ -116,16 +117,22 @@ export default class Image extends Resource {
|
||||||
[, , subimage.texture.width, subimage.texture.height] = rectangle;
|
[, , subimage.texture.width, subimage.texture.height] = rectangle;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const intersection = Rectangle.intersection(
|
||||||
|
Rectangle.compose([0, 0], this.size),
|
||||||
|
rectangle,
|
||||||
|
);
|
||||||
|
if (!Rectangle.isNull(intersection)) {
|
||||||
const frame = {
|
const frame = {
|
||||||
x: rectangle[0],
|
x: intersection[0],
|
||||||
y: rectangle[1],
|
y: intersection[1],
|
||||||
width: rectangle[2],
|
width: intersection[2],
|
||||||
height: rectangle[3],
|
height: intersection[3],
|
||||||
};
|
};
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
const {Texture} = require('@pixi/core');
|
const {Texture} = require('@pixi/core');
|
||||||
subimage.texture = new Texture(this.texture, frame);
|
subimage.texture = new Texture(this.texture, frame);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return subimage;
|
return subimage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user