mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-11-21 05:24:15 +03:00
* fix(editor): route elbow arrows with a single corner where one fits Elbow arrows keep a padding around the elements they connect, and enter the end element from the edge of it. When the end element is closer to the start's side than that (e.g. just below it), the route stepped aside to that edge first, with a few pixels' jog. When the elements can be connected with a single corner instead (leaving the start and entering the end the way they head, both legs clear of both elements, the legs with arrowheads long enough to fit them), that route is used, before (and instead of) routing on the grid. As a leg without an arrowhead can be short now, changing the arrowheads of an elbow arrow (from the picker, by flipping it, or by pasting styles) routes it again, to make room for them. Claude Opus 5.5 (xhigh) * fix(editor): route elbow arrows with two corners where they fit When the arrow leaves the start element and enters the end one heading the same way (e.g. from the bottom of one to the top of another below and to the side of it), and they're closer than the padding the arrow keeps around them, the route had a few pixels' jog between the two paddings. Such arrows are now routed with two corners, the same way as with a single one: turning halfway, as on the grid when there's room. When only one end has an arrowhead, and halfway would leave it a shorter leg than the padding, the turn moves toward the other end (keeping enough of that leg to round its corner). Claude Opus 5.5 (xhigh) * fix(editor): keep elbow arrows' simple routes when their fixed segments go When an element moves so that an elbow arrow's segment lines up with its fixed one (e.g. moving the start element a grid step, onto the fixed segment's level), they're merged and the fixed segment dropped, and the arrow re-routed, as when a fixed segment is released. That re-route went straight to the grid, without trying the one or two corner route first, which left the jog that route avoids until the arrow was routed again. Any route on the grid now tries the simple route first. Claude Opus 5.5 (xhigh) * refactor(editor): route and clean elbow arrows in one place routeElbowArrow() now tries the one or two corner route, falls back to the grid, and removes short segments and points between collinear ones, so its three callers don't repeat that. They also pass getElbowArrowData()'s result through, rather than destructuring and rebuilding it. Claude Opus 5.5 (xhigh) * refactor(editor): name elbow arrow route getters and updates apart routeElbowArrow() returns a route's points, and rerouteElbowArrow() an element update routing the arrow again, so they're getElbowArrowRoute() and updateElbowArrowRoute() now (and the grid routing getElbowArrowGridRoute()). Claude Opus 5.5 (xhigh) * fix(editor): draw elbow arrows' jogs too short to see straight While an element bound to an elbow arrow is moved so that a fixed segment lines up with the ones around it, the arrow keeps a zero-length jog between them until it's released, and rough.js drew the jog's two corners as a knot. A segment shorter than 1px between two longer ones heading the same way is now drawn straight. Corners of short segments in a row, and short U-turns, keep their corners. Claude Opus 5.5 (xhigh) * fix(editor): keep elbow arrows' simple route legs long enough to round A leg of the one or two corner route without an arrowhead only had to outlast the cleanup of short segments (1px), so the route could leave stubs a few pixels long (e.g. from the side of one element to the facing side of another just below and beside it, with no arrowheads). Their corners lost their rounding, and the arrow looked like a line hugging the element, coming from the wrong side. Every leg is now longer than half the corner radius, keeping at least a quarter of the rounding, and one with an arrowhead also fits it. Shorter legs go to the grid routing instead. Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix(editor): keep elbow arrows' simple routes clear by the binding gap The one or two corner route kept a fixed 5px from the elements it connects, rather than the binding gap the arrow keeps at its ends (which grows with the element's stroke). Where an element's bounds reach past the point the arrow binds to (e.g. an ellipse or a diamond entered below its top), a leg could pass closer to it than that, and over a thick stroke. The route now keeps clear of each element by its binding gap. Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * refactor(editor): check elbow arrow route legs with doBoundsIntersect() segmentCrossesBounds() repeated doBoundsIntersect()'s overlap check, so it now passes it the segment's bounds instead. Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * refactor(editor): tidy up the elbow arrow route getters getSimpleRoute() worked out the last leg of a one corner route also for two corner ones, which then replaced it, and took a Pick<> of the data its only caller passes whole. getElbowArrowGridRoute()'s doc listed parameters it doesn't take. Signed-off-by: Mark Tolmacs <mark@lazycat.hu> --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: Mark Tolmacs <mark@lazycat.hu>
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
|
import { pointFrom } from "@excalidraw/math";
|
|
|
|
import type { LocalPoint } from "@excalidraw/math";
|
|
|
|
import {
|
|
ELBOW_ARROW_CORNER_RADIUS,
|
|
generateElbowArrowShape,
|
|
ShapeCache,
|
|
} from "../src/shape";
|
|
|
|
import type { Op } from "roughjs/bin/core";
|
|
|
|
describe("arrowhead shapes", () => {
|
|
it.each(["triangle", "diamond_outline", "circle"] as const)(
|
|
"fills %s arrowheads along their outline",
|
|
(arrowhead) => {
|
|
const arrow = API.createElement({
|
|
type: "arrow",
|
|
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(100, 0)],
|
|
endArrowhead: arrowhead,
|
|
roughness: 2,
|
|
});
|
|
const [, head] = ShapeCache.generateElementShape(arrow, null);
|
|
const [fill, outline] = head.sets;
|
|
const getCurves = (ops: Op[]) =>
|
|
ops.filter((op) => op.op === "bcurveTo").map((op) => op.data);
|
|
|
|
expect(fill.type).toBe("fillPath");
|
|
expect(outline.type).toBe("path");
|
|
// the fill only joins up the outline's curves
|
|
expect(getCurves(fill.ops)).toEqual(getCurves(outline.ops));
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("elbow arrow shapes", () => {
|
|
const getCorners = (points: [number, number][]) =>
|
|
generateElbowArrowShape(
|
|
points.map(([x, y]) => pointFrom<LocalPoint>(x, y)),
|
|
ELBOW_ARROW_CORNER_RADIUS,
|
|
).match(/Q/g)?.length ?? 0;
|
|
|
|
it("draws a jog too short to see straight", () => {
|
|
// a fixed segment lined up with the first one, while dragging
|
|
expect(
|
|
getCorners([
|
|
[0, 0],
|
|
[44, 0],
|
|
[44, -1e-12],
|
|
[195, -1e-12],
|
|
[195, 34],
|
|
]),
|
|
).toBe(1);
|
|
});
|
|
|
|
it("keeps the corners of short segments in a row", () => {
|
|
expect(
|
|
getCorners([
|
|
[0, 0],
|
|
[100, 0],
|
|
[100, 0.5],
|
|
[100.5, 0.5],
|
|
[100.5, 100],
|
|
]),
|
|
).toBe(3);
|
|
});
|
|
|
|
it("keeps a short U-turn", () => {
|
|
expect(
|
|
getCorners([
|
|
[0, 0],
|
|
[100, 0],
|
|
[100, 0.5],
|
|
[0, 0.5],
|
|
[0, 50],
|
|
]),
|
|
).toBe(3);
|
|
});
|
|
});
|