nearest

fun nearest(center: Point2D, k: Int): List<A>(source)

The k nearest agents to center, ordered by distance. Implemented as a progressive radius doubling on top of within: start with a small radius (one cell), double until enough candidates are found, then trim to k. Bounded scanning rather than the O(n) linear sort the previous implementation used.

If k is larger than the number of placed agents, returns all of them.