mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
shift locking 22.5 degree and move to constants (#1216)
* shift locking 22.5 degree and move to constants #1171 * review SHIFT_LOCKING_ANGLE
This commit is contained in:
parent
44f871de71
commit
030954badb
4 changed files with 62 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
import { ExcalidrawElement } from "./types";
|
||||
import { mutateElement } from "./mutateElement";
|
||||
import { isLinearElement } from "./typeChecks";
|
||||
import { SHIFT_LOCKING_ANGLE } from "../constants";
|
||||
|
||||
export function isInvisiblySmallElement(element: ExcalidrawElement): boolean {
|
||||
if (isLinearElement(element)) {
|
||||
|
@ -21,17 +22,21 @@ export function getPerfectElementSize(
|
|||
const absHeight = Math.abs(height);
|
||||
|
||||
if (elementType === "line" || elementType === "arrow") {
|
||||
if (absHeight < absWidth / 2) {
|
||||
const lockedAngle =
|
||||
Math.round(Math.atan(absHeight / absWidth) / SHIFT_LOCKING_ANGLE) *
|
||||
SHIFT_LOCKING_ANGLE;
|
||||
if (lockedAngle === 0) {
|
||||
height = 0;
|
||||
} else if (absWidth < absHeight / 2) {
|
||||
} else if (lockedAngle === Math.PI / 2) {
|
||||
width = 0;
|
||||
} else {
|
||||
height = absWidth * Math.sign(height);
|
||||
height =
|
||||
Math.round(absWidth * Math.tan(lockedAngle)) * Math.sign(height) ||
|
||||
height;
|
||||
}
|
||||
} else if (elementType !== "selection") {
|
||||
height = absWidth * Math.sign(height);
|
||||
}
|
||||
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue