Skip to content

layout: add shape: cycle with circular border-trimmed arc routing - #2928

Open
Visio-Vanitas wants to merge 2 commits into
d2lang:masterfrom
Visio-Vanitas:feat/shape-cycle-border-routing
Open

Visio-Vanitas wants to merge 2 commits into
d2lang:masterfrom
Visio-Vanitas:feat/shape-cycle-border-routing

Conversation

@Visio-Vanitas

Copy link
Copy Markdown

Description

This PR implements shape: cycle for circular diagram layouts with circular Bézier arc routing that accurately terminates at visible shape boundaries (fixing #1578, resolving the open constraints from #2362).

Implementation Details

  1. Circular Bézier Arc Representation:

    • Arcs are partitioned into sub-segments ($\Delta\theta \le \pi/2$) and represented as cubic Bézier curves with the optimal control point distance factor $k = \frac{4}{3} \tan\left(\frac{\Delta\theta}{4}\right)$.
    • Conforms strictly to D2's curve route contract ($1 + 3n$ points).
    • Because the tangent vector at the endpoint is collinear with the circular arc tangent, arrowhead alignment at the boundary is naturally oriented without artificial distortion.
  2. Accurate Shape Boundary Trimming:

    • Evaluates the circular trajectory against shape.Shape.Perimeter().Intersections(), accurately snapping the arc entry/exit points to the visible perimeter of diverse shapes (rectangle, circle, cylinder, hexagon, etc.).
    • Includes binary search boundary resolution as fallback for complex geometry bounds.
  3. Cycle Configurations & Nested Container Support:

    • Single-node cycles ($N=1$) are centered gracefully with radius 0 (preventing division-by-zero on $\sin(\pi)$).
    • Nested child containers and descendant edges (a.x -> b.y) preserve their relative coordinates and connections during cycle container layout.
  4. Testing & Golden Fixtures:

    • Added unit test suite in d2layouts/d2cycle/layout_test.go covering radius computation, single-node safety, nested layout preservation, cross-child descendant routes, and shape diversity.
    • Added E2E txtar test cases in e2etests/txtar.txt under -- cycle-diagram --. Generated golden .exp.json and .exp.svg files across Dagre, ELK, and Tala layout engines via TA=1 ./ci/test.sh ./e2etests -run TestE2E/txtar/cycle-diagram -v (all pass).

Closes #1578
/claim #1578

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shape: cycle

1 participant