Add ellipse changes no angle

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2024-09-27 11:34:02 +02:00
parent d9ea7190ec
commit 7b4e989d65
No known key found for this signature in database
12 changed files with 97 additions and 357 deletions

View file

@ -705,11 +705,7 @@ export const getHeadingForElbowArrowSnap = (
return otherPointHeading;
}
const distance = getDistanceForBinding(
origPoint,
bindableElement,
elementsMap,
);
const distance = getDistanceForBinding(origPoint, bindableElement);
if (!distance) {
return vectorToHeading(
@ -731,7 +727,6 @@ export const getHeadingForElbowArrowSnap = (
const getDistanceForBinding = (
point: Readonly<GlobalPoint>,
bindableElement: ExcalidrawBindableElement,
elementsMap: ElementsMap,
) => {
const distance = distanceToBindableElement(bindableElement, point);
const bindDistance = maxBindingGap(

View file

@ -123,8 +123,8 @@ const roundedCutoffSegment = (
const t = (4 * r) / Math.sqrt(2);
return segment(
ellipseSegmentInterceptPoints(ellipse(s[0], radians(0), t, t), s)[0],
ellipseSegmentInterceptPoints(ellipse(s[1], radians(0), t, t), s)[0],
ellipseSegmentInterceptPoints(ellipse(s[0], t, t), s)[0],
ellipseSegmentInterceptPoints(ellipse(s[1], t, t), s)[0],
);
};
@ -198,13 +198,12 @@ export const distanceToEllipseElement = (
element: ExcalidrawEllipseElement,
p: GlobalPoint,
): number => {
const center = point(
element.x + element.width / 2,
element.y + element.height / 2,
);
return ellipseDistanceFromPoint(
p,
ellipse(
point(element.x + element.width / 2, element.y + element.height / 2),
element.angle,
element.width / 2,
element.height / 2,
),
pointRotateRads(p, center, radians(-element.angle)),
ellipse(center, element.width / 2, element.height / 2),
);
};

View file

@ -17,7 +17,6 @@ import { aabbForElement, pointInsideBounds } from "../shapes";
import { isAnyTrue, toBrandedType } from "../utils";
import {
bindPointToSnapToElementOutline,
distanceToBindableElement,
avoidRectangularCorner,
getHoveredElementForBinding,
FIXED_BINDING_DISTANCE,
@ -26,6 +25,7 @@ import {
snapToMid,
} from "./binding";
import type { Bounds } from "./bounds";
import { distanceToBindableElement } from "./distance";
import type { Heading } from "./heading";
import {
compareHeading,
@ -1023,7 +1023,7 @@ const getGlobalPoint = (
// NOTE: Resize scales the binding position point too, so we need to update it
return Math.abs(
distanceToBindableElement(boundElement, fixedGlobalPoint, elementsMap) -
distanceToBindableElement(boundElement, fixedGlobalPoint) -
FIXED_BINDING_DISTANCE,
) > 0.01
? getSnapPoint(initialPoint, otherPoint, boundElement, elementsMap)
@ -1060,9 +1060,12 @@ const getBindPointHeading = (
hoveredElement &&
aabbForElement(
hoveredElement,
Array(4).fill(
distanceToBindableElement(hoveredElement, p, elementsMap),
) as [number, number, number, number],
Array(4).fill(distanceToBindableElement(hoveredElement, p)) as [
number,
number,
number,
number,
],
),
elementsMap,
origPoint,