simplify
This commit is contained in:
parent
9519ed0f74
commit
d0100e1c66
|
|
@ -413,41 +413,38 @@ export class FolkShape extends HTMLElement {
|
||||||
|
|
||||||
if (handle.includes('resize')) {
|
if (handle.includes('resize')) {
|
||||||
const mouse = { x: event.clientX, y: event.clientY };
|
const mouse = { x: event.clientX, y: event.clientY };
|
||||||
const [topLeft, topRight, bottomRight, bottomLeft] = this.getClientRect().corners();
|
const corners = this.getClientRect().corners();
|
||||||
|
|
||||||
if (handle.endsWith('nw')) {
|
const handleEnd = handle.slice(-2); // 'nw', 'ne', 'se', 'sw'
|
||||||
const newCenter = Vector.lerp(bottomRight, mouse, 0.5);
|
let thisCornerIndex: number;
|
||||||
const newTopLeft = Vector.rotateAround(mouse, newCenter, -this.rotation);
|
let oppositeCornerIndex: number;
|
||||||
const newBottomRight = Vector.rotateAround(bottomRight, newCenter, -this.rotation);
|
|
||||||
this.x = newTopLeft.x;
|
if (handleEnd === 'nw') {
|
||||||
this.y = newTopLeft.y;
|
thisCornerIndex = 0; // topLeft
|
||||||
this.width = newBottomRight.x - newTopLeft.x;
|
oppositeCornerIndex = 2; // bottomRight
|
||||||
this.height = newBottomRight.y - newTopLeft.y;
|
} else if (handleEnd === 'ne') {
|
||||||
} else if (handle.endsWith('ne')) {
|
thisCornerIndex = 1; // topRight
|
||||||
const newCenter = Vector.lerp(bottomLeft, mouse, 0.5);
|
oppositeCornerIndex = 3; // bottomLeft
|
||||||
const newBottomLeft = Vector.rotateAround(bottomLeft, newCenter, -this.rotation);
|
} else if (handleEnd === 'se') {
|
||||||
const newTopRight = Vector.rotateAround(mouse, newCenter, -this.rotation);
|
thisCornerIndex = 2; // bottomRight
|
||||||
this.x = newBottomLeft.x;
|
oppositeCornerIndex = 0; // topLeft
|
||||||
this.y = newTopRight.y;
|
} else if (handleEnd === 'sw') {
|
||||||
this.width = newTopRight.x - newBottomLeft.x;
|
thisCornerIndex = 3; // bottomLeft
|
||||||
this.height = newBottomLeft.y - newTopRight.y;
|
oppositeCornerIndex = 1; // topRight
|
||||||
} else if (handle.endsWith('se')) {
|
|
||||||
const newCenter = Vector.lerp(topLeft, mouse, 0.5);
|
|
||||||
const newTopLeft = Vector.rotateAround(topLeft, newCenter, -this.rotation);
|
|
||||||
const newBottomRight = Vector.rotateAround(mouse, newCenter, -this.rotation);
|
|
||||||
this.x = newTopLeft.x;
|
|
||||||
this.y = newTopLeft.y;
|
|
||||||
this.width = newBottomRight.x - newTopLeft.x;
|
|
||||||
this.height = newBottomRight.y - newTopLeft.y;
|
|
||||||
} else {
|
} else {
|
||||||
const newCenter = Vector.lerp(topRight, mouse, 0.5);
|
return;
|
||||||
const newBottomLeft = Vector.rotateAround(mouse, newCenter, -this.rotation);
|
|
||||||
const newTopRight = Vector.rotateAround(topRight, newCenter, -this.rotation);
|
|
||||||
this.x = newBottomLeft.x;
|
|
||||||
this.y = newTopRight.y;
|
|
||||||
this.width = newTopRight.x - newBottomLeft.x;
|
|
||||||
this.height = newBottomLeft.y - newTopRight.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const oppositeCorner = corners[oppositeCornerIndex];
|
||||||
|
const newCenter = Vector.lerp(oppositeCorner, mouse, 0.5);
|
||||||
|
const newThisCorner = Vector.rotateAround(mouse, newCenter, -this.rotation);
|
||||||
|
const newOppositeCorner = Vector.rotateAround(oppositeCorner, newCenter, -this.rotation);
|
||||||
|
|
||||||
|
this.x = Math.min(newThisCorner.x, newOppositeCorner.x);
|
||||||
|
this.y = Math.min(newThisCorner.y, newOppositeCorner.y);
|
||||||
|
this.width = Math.abs(newOppositeCorner.x - newThisCorner.x);
|
||||||
|
this.height = Math.abs(newOppositeCorner.y - newThisCorner.y);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue