mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-14 04:50:05 +02:00
normalize before projection to improve rotated crop region drag
This commit is contained in:
@@ -456,7 +456,7 @@ import {
|
|||||||
vectorFromPoint,
|
vectorFromPoint,
|
||||||
vectorSubtract,
|
vectorSubtract,
|
||||||
vectorDot,
|
vectorDot,
|
||||||
vectorMagnitude,
|
vectorNormalize,
|
||||||
} from "../../math";
|
} from "../../math";
|
||||||
import { cropElement } from "../element/cropElement";
|
import { cropElement } from "../element/cropElement";
|
||||||
|
|
||||||
@@ -7969,34 +7969,20 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
croppingElement.angle,
|
croppingElement.angle,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const topEdge = vectorSubtract(topRight, topLeft);
|
const topEdge = vectorNormalize(
|
||||||
const leftEdge = vectorSubtract(bottomLeft, topLeft);
|
vectorSubtract(topRight, topLeft),
|
||||||
|
);
|
||||||
|
const leftEdge = vectorNormalize(
|
||||||
|
vectorSubtract(bottomLeft, topLeft),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* project instantDrafOffset onto leftEdge to find out the y scalar
|
* project instantDrafOffset onto leftEdge and topEdge to decompose
|
||||||
* topEdge to find out the x scalar
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const scaleY =
|
instantDragOffset = vector(
|
||||||
vectorDot(instantDragOffset, leftEdge) /
|
vectorDot(instantDragOffset, topEdge),
|
||||||
vectorDot(leftEdge, leftEdge);
|
vectorDot(instantDragOffset, leftEdge),
|
||||||
const scaleX =
|
|
||||||
vectorDot(instantDragOffset, topEdge) /
|
|
||||||
vectorDot(topEdge, topEdge);
|
|
||||||
|
|
||||||
instantDragOffset = vectorScale(
|
|
||||||
vector(scaleX, scaleY),
|
|
||||||
/**
|
|
||||||
* projection results in small x and y scalars
|
|
||||||
* scale to account for this
|
|
||||||
*/
|
|
||||||
Math.min(
|
|
||||||
Math.max(
|
|
||||||
vectorMagnitude(topEdge),
|
|
||||||
vectorMagnitude(leftEdge),
|
|
||||||
),
|
|
||||||
100,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user