Fix transform handles not working correctly on rotated objects

This commit is contained in:
Skyler Lehmkuhl 2024-12-31 01:14:54 -05:00
parent f610ef733d
commit b860d58e3d
2 changed files with 6 additions and 11 deletions

View File

@ -2733,7 +2733,7 @@ class GraphicsObject {
ctx.strokeStyle = "#00ffff"
ctx.lineWidth = 1;
ctx.beginPath()
let bbox = item.bbox()
let bbox = getRotatedBoundingBox(item)
ctx.rect(bbox.x.min, bbox.y.min, bbox.x.max - bbox.x.min, bbox.y.max - bbox.y.min)
ctx.stroke()
ctx.restore()
@ -2756,9 +2756,9 @@ class GraphicsObject {
let bbox = undefined;
for (let item of context.selection) {
if (bbox==undefined) {
bbox = getRotatedBoundingBox(item, debugPoints)
bbox = getRotatedBoundingBox(item)
} else {
growBoundingBox(bbox, getRotatedBoundingBox(item, debugPoints))
growBoundingBox(bbox, getRotatedBoundingBox(item))
}
}
if (bbox != undefined) {
@ -3802,9 +3802,9 @@ function stage() {
selection = {}
for (let item of context.selection) {
if (bbox==undefined) {
bbox = structuredClone(item.bbox())
bbox = getRotatedBoundingBox(item)
} else {
growBoundingBox(bbox, item.bbox())
growBoundingBox(bbox, getRotatedBoundingBox(item))
}
selection[item.idx] = {x: item.x, y: item.y, scale_x: item.scale_x, scale_y: item.scale_y, rotation: item.rotation}
}

View File

@ -600,7 +600,7 @@ function rotateAroundPoint(x, y, point, angle) {
return { x: rotatedX, y: rotatedY };
}
function getRotatedBoundingBox(object, debugPoints=[]) {
function getRotatedBoundingBox(object) {
const bbox = object.bbox(); // Get the bounding box of the object without transformation
const { x: { min: xMin, max: xMax }, y: { min: yMin, max: yMax } } = bbox;
@ -622,11 +622,6 @@ function getRotatedBoundingBox(object, debugPoints=[]) {
let rotatedCorners = corners.map(corner => {
return rotateAroundPoint(corner.x, corner.y, center, object.rotation);
});
debugPoints.length = 0
for (let corner of rotatedCorners) {
debugPoints.push(corner)
}
// Find the new bounding box after rotation
let rotatedXMin = Math.min(...rotatedCorners.map(corner => corner.x));