From b860d58e3d034387d873fc28d07b7b57c80ff4d9 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Tue, 31 Dec 2024 01:14:54 -0500 Subject: [PATCH] Fix transform handles not working correctly on rotated objects --- src/main.js | 10 +++++----- src/utils.js | 7 +------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main.js b/src/main.js index caa54c2..78cf28f 100644 --- a/src/main.js +++ b/src/main.js @@ -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} } diff --git a/src/utils.js b/src/utils.js index 8db7017..448fdc6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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));