fix: Use rectangle hull fallback for near-collinear clusters - #3
Conversation
- Detect thin convex hulls (low area/perimeter²) common in 3-node layouts - Fall back to padded bounding rectangle instead of centroid expansion overshoot Fixes Fayupable#2 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
|
@VedantMadane Thanks for tackling this — the 3-node overshoot case is clearly much better than before, and the larger clusters still look fine. But I think this went a bit too far in the opposite direction: on several clusters, the hull now hugs the nodes so tightly that its boundary sits right at (or even overlaps) the node circles themselves, with little to no visible margin. Two concrete examples from testing this locally:
Could we adjust this so there's always a consistent minimum margin around every node — enough that a node never appears to sit on or outside the hull boundary — while still avoiding the original overshoot problem for near-collinear clusters? Happy to share exact screenshots/coordinates from my local test if that helps narrow down the right padding value. |
Fayupable
left a comment
There was a problem hiding this comment.
Thanks for the update, re-tested locally. The 3-node overshoot case looks better now. Not 100% sure what's going on here (that's why I opened this as an issue), but a couple things I noticed:
- A 4-node triangular cluster still shows a node sitting right on the hull boundary with almost no margin (screenshot attached). Might not be hitting the COLLINEAR_AREA_RATIO threshold, not sure.
- The 3-node case that does hit the fallback also shows very little margin around the outer nodes. Not sure if padRectangle is applying HULL_PADDING correctly there. Could be wrong about the cause, just flagging what I saw.
Centroid radial padding under-cleared hull edges, so nodes could sit on the boundary; the thin-hull rectangle fallback also left only ~14px past the 22px node radius. Expand each node to a square of half-side (node radius + 20px margin) and take the convex hull instead — that guarantees clearance on every node (including edge-sitting ones) and naturally becomes a padded AABB for near-collinear clusters without perpendicular overshoot. Add unit tests covering the 3-node line, 4-node triangle, and collinear height bound. Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
|
Thanks for the clear repro notes and screenshots — you were right on both counts. What was going wrong
Fix (
All 8 frontend tests pass. Happy to tweak |
|
Thanks for this, genuinely appreciate it. I ran into this exact problem and couldn't find the right fix myself. Nice work digging into the geometry. @VedantMadane |



Summary
Use rectangle hull fallback for near-collinear clusters
Changes
Fixes #2