Skip to content

Commit

Permalink
fix: Omit elbow body when the line forms a straight line
Browse files Browse the repository at this point in the history
- It lets other lines jump over the vertices of the body that used to exist.
  • Loading branch information
miyanokomiya committed Sep 24, 2024
1 parent 3d22e5d commit eb0178d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/utils/elbowLine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ describe("getOptimalElbowBody", () => {
]);
});

test("should return empty when they have y margin and the same x value", () => {
expect(
getOptimalElbowBody(
{ x: 5, y: 10 },
{ x: 5, y: 20 },
{ x: 0, y: 0, width: 10, height: 10 },
{ x: 0, y: 20, width: 10, height: 10 },
),
).toEqual([]);
});

test("when they don't have y margin but have x margin", () => {
expect(
getOptimalElbowBody(
Expand Down
2 changes: 2 additions & 0 deletions src/utils/elbowLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function getOptimalElbowBody_2_8(
const [qt, qr, , ql] = [qBounds.y, qBounds.x + qBounds.width, qBounds.y + qBounds.height, qBounds.x];

if (pb < qt) {
if (p.x === q.x) return [];

const y = (qt + pb) / 2;
return [
{ x: p.x, y },
Expand Down

0 comments on commit eb0178d

Please sign in to comment.