mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix non-normalized radians in heading calc
This commit is contained in:
parent
637cb82c9c
commit
06daae0f18
1 changed files with 4 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
normalizeRadians,
|
||||||
pointFrom,
|
pointFrom,
|
||||||
pointRotateRads,
|
pointRotateRads,
|
||||||
pointScaleFromOrigin,
|
pointScaleFromOrigin,
|
||||||
|
@ -30,8 +31,9 @@ export const headingForDiamond = <Point extends GlobalPoint | LocalPoint>(
|
||||||
b: Point,
|
b: Point,
|
||||||
) => {
|
) => {
|
||||||
const angle = radiansToDegrees(
|
const angle = radiansToDegrees(
|
||||||
Math.atan2(b[1] - a[1], b[0] - a[0]) as Radians,
|
normalizeRadians(Math.atan2(b[1] - a[1], b[0] - a[0]) as Radians),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (angle >= 315 || angle < 45) {
|
if (angle >= 315 || angle < 45) {
|
||||||
return HEADING_UP;
|
return HEADING_UP;
|
||||||
} else if (angle >= 45 && angle < 135) {
|
} else if (angle >= 45 && angle < 135) {
|
||||||
|
@ -77,9 +79,7 @@ export const headingIsVertical = (a: Heading) => !headingIsHorizontal(a);
|
||||||
// Gets the heading for the point by creating a bounding box around the rotated
|
// Gets the heading for the point by creating a bounding box around the rotated
|
||||||
// close fitting bounding box, then creating 4 search cones around the center of
|
// close fitting bounding box, then creating 4 search cones around the center of
|
||||||
// the external bbox.
|
// the external bbox.
|
||||||
export const headingForPointFromElement = <
|
export const headingForPointFromElement = <Point extends GlobalPoint>(
|
||||||
Point extends GlobalPoint | LocalPoint,
|
|
||||||
>(
|
|
||||||
element: Readonly<ExcalidrawBindableElement>,
|
element: Readonly<ExcalidrawBindableElement>,
|
||||||
aabb: Readonly<Bounds>,
|
aabb: Readonly<Bounds>,
|
||||||
p: Readonly<Point>,
|
p: Readonly<Point>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue