Skip to content

Add geomGetLongestSurroundingRectangle and rename SSR type#308

Merged
bhousel merged 1 commit intomainfrom
longest_surrounding_rectangle
May 5, 2026
Merged

Add geomGetLongestSurroundingRectangle and rename SSR type#308
bhousel merged 1 commit intomainfrom
longest_surrounding_rectangle

Conversation

@bhousel
Copy link
Copy Markdown
Collaborator

@bhousel bhousel commented May 5, 2026

Summary

Adds geomGetLongestSurroundingRectangle alongside the existing geomGetSmallestSurroundingRectangle, and renames the SSR interface to SurroundingRectangle.

Changes

  • New function: geomGetLongestSurroundingRectangle — returns the surrounding rectangle whose longest side is maximized. This may result in generating a more intuitive bounding box around features with a dominant axis (like buildings), and may be useful for placing labels and icons aligned to a building's dominant axis.
  • Renamed type: SSRSurroundingRectangle for clarity.
  • Shared implementation: Both functions delegate to a generalized getSurroundingRectangle helper, differing only in their scoring strategy.
  • Angle deduplication: Candidate angles are deduplicated via a Set keyed on Math.round(angle / ANGLE_EPSILON), avoiding testing of redundant rotations.
  • Loop optimization: Replaced reduce with a for...of loop for extent accumulation; inlined rotation math to avoid allocating a temporary rotated-polygon array.
  • Tests: Added real off-axis L-shaped building fixture (offAxisLShapedBuildingPoints) and assertions verifying both functions choose the correct envelope orientation.

Closes #267
Closes facebook/Rapid#1045

@bhousel bhousel merged commit 70da5b1 into main May 5, 2026
1 check passed
@bhousel bhousel deleted the longest_surrounding_rectangle branch May 5, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant