queryRadius method
Items whose stored position lies within Euclidean distance radius of
(x, y). Requires radius >= 0. Order is unspecified.
Audited: 2026-06-12 11:26 EDT
Implementation
List<T> queryRadius(double x, double y, double radius) {
// Enforced in release: a negative radius would silently match points within
// |radius| (r2 squares away the sign) instead of being rejected.
if (radius < 0) {
throw ArgumentError.value(radius, 'radius', 'must be >= 0');
}
final double r2 = radius * radius;
// Filter the cell candidates by true distance — a cell overlapping the
// query box can still hold points outside the circle.
return <T>[
for (final _Entry<T> e in _candidates(x, y, radius))
if ((e.x - x) * (e.x - x) + (e.y - y) * (e.y - y) <= r2) e.item,
];
}