Skip to content

fix: Use rectangle hull fallback for near-collinear clusters - #3

Merged
Fayupable merged 2 commits into
Fayupable:mainfrom
VedantMadane:fix/issue-2
Aug 27, 2026
Merged

fix: Use rectangle hull fallback for near-collinear clusters#3
Fayupable merged 2 commits into
Fayupable:mainfrom
VedantMadane:fix/issue-2

Conversation

@VedantMadane

Copy link
Copy Markdown
Contributor

Summary

Use rectangle hull fallback for near-collinear clusters

Changes

  • Detect thin convex hulls (low area/perimeter²) common in 3-node layouts
  • Fall back to padded bounding rectangle instead of centroid expansion overshoot

Fixes #2

- 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>
@Fayupable

Copy link
Copy Markdown
Owner

@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:

  1. The 3-node cluster (nodes labeled 4082/4080/4081 in my test data) — the hull is now a thin lens shape whose edge passes almost exactly through the outer nodes, no clearance around them.
  2. A 4-node triangular cluster (node 4032 specifically) — the hull's bottom-left edge sits right against that node's circle, essentially no padding.

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.
image
image

@Fayupable Fayupable left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. 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>
@VedantMadane

Copy link
Copy Markdown
Contributor Author

Thanks for the clear repro notes and screenshots — you were right on both counts.

What was going wrong

  1. Centroid radial padPoint does not give uniform edge clearance. On a triangle, edge offset is only ~½ of the vertex push, so a node on (or near) a hull edge could sit essentially on the boundary (your 4-node / node 4032 case).
  2. The thin-hull rectangle fallback padded by HULL_PADDING = 36 from the top-left anchors. After centering, that is only 36 - 22 ≈ 14px past the node circle — easy to read as “no margin,” and with corner rounding it looked like a tight lens on the 3-node case.

Fix (843a77c)
Replace centroid expansion + collinear special-case with square inflation: expand every node anchor to a square of half-side NODE_HALF_SIZE (22) + HULL_MARGIN (20) = 42, then take polygonHull of all corners.

  • Guarantees ≥42px clearance from every node anchor → ≥20px air gap outside the 44px circles, including edge-sitting nodes.
  • Near-collinear layouts naturally become a padded AABB of height 2 * 42 (no perpendicular overshoot).
  • Unit tests in hulls.test.ts cover the 3-node line, 4-node triangle with an edge node, and the collinear height bound.

All 8 frontend tests pass. Happy to tweak HULL_MARGIN if 20px still feels tight or loose once you re-check locally.

@Fayupable Fayupable left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will review asap

@Fayupable Fayupable left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally against several cluster shapes (3-node, 4-node, larger organic ones). Margins look correct everywhere now, no overshoot and no nodes sitting on the boundary. Approving.

Image

@Fayupable

Copy link
Copy Markdown
Owner

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

@Fayupable
Fayupable merged commit 074e61d into Fayupable:main Aug 27, 2026
1 check passed
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.

Cluster hull rendering overshoots (or under-covers) nodes for small/near-collinear clusters in the lock graph

2 participants