fix: slice
This commit is contained in:
parent
2d02462263
commit
775ba3e84c
|
@ -138,21 +138,30 @@ export default (latus) => {
|
|||
}
|
||||
}
|
||||
|
||||
/* eslint-disable no-param-reassign */
|
||||
slice([x, y, w, h]) {
|
||||
if (w <= 0 || h <= 0) {
|
||||
return [];
|
||||
}
|
||||
const [fw, fh] = this.size;
|
||||
const n = fw - w;
|
||||
const slice = new Array(w * h);
|
||||
let i = y * this.width + x;
|
||||
let i = y * fw + x;
|
||||
let j = 0;
|
||||
for (let l = 0; l < h; ++l) {
|
||||
for (let k = 0; k < w; ++k) {
|
||||
slice[j] = k < 0 || k >= w || l < 0 || l >= h ? 0 : this.data[i];
|
||||
slice[j] = x < 0 || x >= fw || y < 0 || y >= fh ? 0 : this.data[i];
|
||||
x += 1;
|
||||
i += 1;
|
||||
j += 1;
|
||||
}
|
||||
i -= w;
|
||||
i += this.width;
|
||||
x -= w;
|
||||
y += 1;
|
||||
i += n;
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
/* eslint-enable no-param-reassign */
|
||||
|
||||
stampAt([x, y, w, h], tiles) {
|
||||
if (0 === w || 0 === h || 0 === tiles.length) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user