apply projection to angle 0 drag move as well

pull/8613/head
Ryan Di 5 months ago
parent da0481683a
commit 741c8dec31

@ -7938,8 +7938,7 @@ class App extends React.Component<AppProps, AppState> {
this.imageCache.get(croppingElement.fileId)?.image; this.imageCache.get(croppingElement.fileId)?.image;
if (image && !(image instanceof Promise)) { if (image && !(image instanceof Promise)) {
// scale the offset by at least a factor of 2 to improve ux const instantDragOffset = vectorScale(
let instantDragOffset = vectorScale(
vector( vector(
pointerCoords.x - lastPointerCoords.x, pointerCoords.x - lastPointerCoords.x,
pointerCoords.y - lastPointerCoords.y, pointerCoords.y - lastPointerCoords.y,
@ -7947,7 +7946,6 @@ class App extends React.Component<AppProps, AppState> {
Math.max(this.state.zoom.value, 2), Math.max(this.state.zoom.value, 2),
); );
if (croppingElement.angle !== 0) {
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords( const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(
croppingElement, croppingElement,
elementsMap, elementsMap,
@ -7981,29 +7979,23 @@ class App extends React.Component<AppProps, AppState> {
vectorSubtract(bottomLeft, topLeft), vectorSubtract(bottomLeft, topLeft),
); );
/** // project instantDrafOffset onto leftEdge and topEdge to decompose
* project instantDrafOffset onto leftEdge and topEdge to decompose const offsetVector = vector(
*/
instantDragOffset = vector(
vectorDot(instantDragOffset, topEdge), vectorDot(instantDragOffset, topEdge),
vectorDot(instantDragOffset, leftEdge), vectorDot(instantDragOffset, leftEdge),
); );
}
const nextCrop = { const nextCrop = {
...crop, ...crop,
x: clamp( x: clamp(
crop.x - crop.x -
instantDragOffset[0] * offsetVector[0] * Math.sign(croppingElement.scale[0]),
Math.sign(croppingElement.scale[0]),
0, 0,
image.naturalWidth - crop.width, image.naturalWidth - crop.width,
), ),
y: clamp( y: clamp(
crop.y - crop.y -
instantDragOffset[1] * offsetVector[1] * Math.sign(croppingElement.scale[1]),
Math.sign(croppingElement.scale[1]),
0, 0,
image.naturalHeight - crop.height, image.naturalHeight - crop.height,
), ),

Loading…
Cancel
Save