P.cleanPathObject = function () {
this.dirtyPathObject = false;
if (!this.noPathUpdates || !this.pathObject) {
const p = this.pathObject = new Path2D(),
rowLines = new Path2D(),
colLines = new Path2D();
const handle = this.currentStampHandlePosition,
scale = this.currentScale,
dims = this.currentDimensions;
const x = -handle[0] * scale,
y = -handle[1] * scale,
w = dims[0] * scale,
h = dims[1] * scale;
p.rect(x, y, w, h);
const cols = this.columns,
rows = this.rows,
colWidth = w / cols,
rowHeight = h / rows,
paths = this.tilePaths,
real = this.tileRealCoordinates,
virtual = this.tileVirtualCoordinates;
let i, j, cx, cy;
rowLines.moveTo(x, y);
rowLines.lineTo(x + w, y);
for (i = 1; i <= rows; i++) {
const ry = y + (i * rowHeight);
rowLines.moveTo(x, ry);
rowLines.lineTo(x + w, ry);
}
this.rowLines = rowLines;
colLines.moveTo(x, y);
colLines.lineTo(x, y + h);
for (j = 1; j <= cols; j++) {
cx = x + (j * colWidth);
colLines.moveTo(cx, y);
colLines.lineTo(cx, y + h);
}
this.columnLines = colLines;
paths.length = 0;
real.length = 0;
virtual.length = 0;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
const path = new Path2D();
cx = j * colWidth;
cy = i * rowHeight;
path.rect(x + cx, y + cy, colWidth, rowHeight);
paths.push(path);
virtual.push([cx, cy]);
real.push([x + cx, y + cy]);
}
}
this.currentTileWidth = colWidth;
this.currentTileHeight = rowHeight;
}
};
P.getTilePivotCoordsAt = function (index) {
if (_isFinite(index) && index >= 0) {
const tiles = this.tileRealCoordinates;
if (index < tiles.length) {
const start = this.currentStampPosition,
offset = [...tiles[index]],
angle = this.currentRotation,
horizontalPivotPosition = this.horizontalPivotPosition,
verticalPivotPosition = this.verticalPivotPosition,
width = this.currentTileWidth,
height = this.currentTileHeight;
if (horizontalPivotPosition === RIGHT) offset[0] += width;
else if (horizontalPivotPosition === CENTER) offset[0] += width / 2;
if (verticalPivotPosition === BOTTOM) offset[1] += height;
else if (verticalPivotPosition === CENTER) offset[1] += height / 2;
if (this.flipReverse) offset[0] = -offset[0];
if (this.flipUpend) offset[1] = -offset[1];
const coord = requestCoordinate();
coord.setFromArray(offset).rotate(angle).add(start);
const res = [...coord];
releaseCoordinate(coord);
return res;
}
}
return [...this.currentStampPosition];
};