fix(studio): a sealed resize of a scaled layer keeps its corner on the pointer at rest (#8562)

* test(studio): a sealed resize moves its box by the rounding remainder an unsealed one measures

* fix(studio): a sealed resize keeps the dragged corner on the pointer at fractional sizes

* test(studio): a sealed resize's remainder matches on a box with its own scale

* fix(studio): a sealed resize of a scaled layer keeps its corner on the pointer at rest
This commit is contained in:
Miguel Ángel
2026-11-23 06:31:19 +00:00
committed by GitHub
parent 4f5bfc24c8
commit 75d35bbd89
2 changed files with 10 additions and 3 deletions
@@ -9,6 +9,7 @@ const gesture = (resizeGrow?: GestureState["resizeGrow"]) =>
actualHeight: 160,
editScaleX: 0.5,
editScaleY: 0.5,
...{ contentScaleX: 1, contentScaleY: 1 },
...{ actualRotation: 0, centerX: 0, centerY: 0, startX: 60, startY: 40 },
resizeGrow,
}) as GestureState;
@@ -29,11 +30,16 @@ describe("a sealed resize's centre pin", () => {
// fails without the fix: the sealed pin ignored the wanted size, so the grabbed corner sat up to half a px short of the
// pointer where an unsealed draft, which measures the corners, shifts the box by half the rounding remainder.
it("moves a sealed box by the same rounding remainder an unsealed draft measures", () => {
// A box drawn 1.5x on screen, all of it Studio's zoom or most of it the element's own scale.
it.each([
[1.5, 1],
[0.5, 3],
])("moves a sealed box by the same rounding remainder an unsealed draft measures", (edit, own) => {
const angle = 30 * (Math.PI / 180);
const g = {
...gesture(),
...{ actualWidth: 300, actualHeight: 150, editScaleX: 1.5, editScaleY: 1.5 },
...{ actualWidth: 300, actualHeight: 150, editScaleX: edit, editScaleY: edit },
...{ contentScaleX: own, contentScaleY: own },
...{ actualRotation: 30, centerX: 400, centerY: 300, startX: 680, startY: 500 },
} as GestureState;
const sizes = { wanted: { width: 300.6, height: 150.3 }, written: { width: 301, height: 150 } };
@@ -92,7 +92,8 @@ function gestureCorners(
written: { width: number; height: number },
): NonNullable<Corners> {
const rad = (g.actualRotation * Math.PI) / 180;
const [w, h] = [(written.width * g.editScaleX) / 2, (written.height * g.editScaleY) / 2];
const [sx, sy] = [g.editScaleX * g.contentScaleX, g.editScaleY * g.contentScaleY];
const [w, h] = [(written.width * sx) / 2, (written.height * sy) / 2];
const at = (u: number, v: number) => ({
x: g.centerX + u * Math.cos(rad) - v * Math.sin(rad),
y: g.centerY + u * Math.sin(rad) + v * Math.cos(rad),