mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Compare commits
No commits in common. "aa91a3d61065f55ecd765f3323b2978b4211e734" and "eaa869620e130b08bea372dd00ce2f56297d83a0" have entirely different histories.
aa91a3d610
...
eaa869620e
2 changed files with 15 additions and 28 deletions
|
@ -107,10 +107,7 @@ type ElbowArrowData = {
|
||||||
hoveredEndElement: ExcalidrawBindableElement | null;
|
hoveredEndElement: ExcalidrawBindableElement | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateDedupTreshhold = <Point extends GlobalPoint | LocalPoint>(
|
const DEDUP_TRESHOLD = 1;
|
||||||
a: Point,
|
|
||||||
b: Point,
|
|
||||||
) => 1 + pointDistance(a, b) / 100;
|
|
||||||
|
|
||||||
const calculatePadding = (
|
const calculatePadding = (
|
||||||
aabb: Bounds,
|
aabb: Bounds,
|
||||||
|
@ -120,8 +117,8 @@ const calculatePadding = (
|
||||||
const width = aabb[2] - aabb[0];
|
const width = aabb[2] - aabb[0];
|
||||||
const height = aabb[3] - aabb[1];
|
const height = aabb[3] - aabb[1];
|
||||||
const size = Math.max(width, height);
|
const size = Math.max(width, height);
|
||||||
|
// || compareHeading(startHeading, flipHeading(endHeading))
|
||||||
return size > 75
|
return size > 55
|
||||||
? 40
|
? 40
|
||||||
: Math.min(
|
: Math.min(
|
||||||
Math.max(
|
Math.max(
|
||||||
|
@ -210,11 +207,7 @@ const handleSegmentRenormalization = (
|
||||||
|
|
||||||
if (
|
if (
|
||||||
// Remove segments that are too short
|
// Remove segments that are too short
|
||||||
pointDistance(points[i - 2], points[i - 1]) <
|
pointDistance(points[i - 2], points[i - 1]) < DEDUP_TRESHOLD
|
||||||
calculateDedupTreshhold(
|
|
||||||
points[i - 3] ?? points[i - 3],
|
|
||||||
points[i] ?? points[i - 1],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
const prevPrevSegmentIdx =
|
const prevPrevSegmentIdx =
|
||||||
nextFixedSegments?.findIndex((segment) => segment.index === i - 2) ??
|
nextFixedSegments?.findIndex((segment) => segment.index === i - 2) ??
|
||||||
|
@ -2235,10 +2228,7 @@ const removeElbowArrowShortSegments = (
|
||||||
|
|
||||||
const prev = points[idx - 1];
|
const prev = points[idx - 1];
|
||||||
const prevDist = pointDistance(prev, p);
|
const prevDist = pointDistance(prev, p);
|
||||||
return (
|
return prevDist > DEDUP_TRESHOLD;
|
||||||
prevDist >
|
|
||||||
calculateDedupTreshhold(points[idx - 2] ?? prev, points[idx + 1] ?? p)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2343,16 +2333,13 @@ const gridAddressesEqual = (a: GridAddress, b: GridAddress): boolean =>
|
||||||
|
|
||||||
export const validateElbowPoints = <P extends GlobalPoint | LocalPoint>(
|
export const validateElbowPoints = <P extends GlobalPoint | LocalPoint>(
|
||||||
points: readonly P[],
|
points: readonly P[],
|
||||||
tolerance?: number,
|
tolerance: number = DEDUP_TRESHOLD,
|
||||||
) =>
|
) =>
|
||||||
points
|
points
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.map((p, i) => {
|
.map(
|
||||||
const t =
|
(p, i) =>
|
||||||
tolerance ??
|
Math.abs(p[0] - points[i][0]) < tolerance ||
|
||||||
calculateDedupTreshhold(points[i - 1] ?? points[i], points[i + 2] ?? p);
|
Math.abs(p[1] - points[i][1]) < tolerance,
|
||||||
return (
|
)
|
||||||
Math.abs(p[0] - points[i][0]) < t || Math.abs(p[1] - points[i][1]) < t
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.every(Boolean);
|
.every(Boolean);
|
||||||
|
|
|
@ -294,11 +294,11 @@ describe("elbow arrow ui", () => {
|
||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
UI.updateInput(inputAngle, String("40"));
|
UI.updateInput(inputAngle, String("40"));
|
||||||
|
|
||||||
expect(arrow.points).toCloselyEqualPoints([
|
expect(arrow.points.map((point) => point.map(Math.round))).toEqual([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[34.9292, 0],
|
[34, 0],
|
||||||
[34.48768, 164.6246],
|
[34, 165],
|
||||||
[104.333, 164.6246],
|
[104, 165],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue