# Find the nearest floor edge without reading every edge · dara/icarus

[View on GitCafe](https://git.cafe/dara/icarus/commit/be6b59525d3f1b53d4387ac8c404df811c89587c)

Repository: [dara/icarus](https://git.cafe/dara/icarus)

Visibility: public

Requested revision: be6b59525d3f1b53d4387ac8c404df811c89587c

Requested commit: be6b59525d3f1b53d4387ac8c404df811c89587c

Commit: be6b59525d3f1b53d4387ac8c404df811c89587c

Tree: 57cafcf478f8f4c6e875292ba6985924231d8d8a

Author: Dara Adedeji

Committer: Dara Adedeji

## Message

```
Find the nearest floor edge without reading every edge

Dragging an agent snaps its cone out of wall ink and back onto the floor
(standablePointNear). When the point was off the floor, _pulledIn looked
for the nearest edge of the floor footprint by measuring every edge of it:
9,000 to 13,500 edges on Lotus, Breeze, Bind and Ascent, with an Offset
allocation and a modulo per edge. On the web, where no native library
runs, that cost 384 us per drag frame in a browser CPU profile of the
drag harness (5.7% of busy time).

The footprint already files its edges in rows one unit tall for its
containment test. The nearest-edge search now reads those rows outward
from the point's own and stops once the nearest edge found is no farther
than the rows not yet read; an edge outside them is more than that far.
Ties still go to the first edge in ring order, and a non-finite point
reads every edge in order as before, so the chosen edge, foot and
snapped point are the same. Edge endpoints are kept in one Float64List
that the containment test and the search both read.

Measured on the four maps above:
- Browser drag (CPU profile, 4 maps x 8 s): 384 -> 83 us per frame
  under standablePointNear.
- Browser, per call on drag paths through walls: mean 190-310 -> 10-17
  us, p99 575-935 -> 60-115 us.
- VM, per call: mean 170-220 -> 10-17 us, p99 790-1170 -> 80-120 us.

An old-against-new comparison over 299,234 points on all 26 map sides
(drag paths, points beside wall and floor vertices, off-map, NaN and
infinite points) found no difference in the snapped point.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

```

## Parents

- [0fca2d18bf98fa7a7119a14645cfde80c90ee540](https://git.cafe/dara/icarus/commit/0fca2d18bf98fa7a7119a14645cfde80c90ee540?format=markdown)

[Source at this commit](https://git.cafe/dara/icarus/tree/be6b59525d3f1b53d4387ac8c404df811c89587c?format=markdown)
