| 270 | } |
| 271 | |
| 272 | EntityPtr EntityMap::closestEntity(Vec2F const& center, float radius, EntityFilter const& filter) const { |
| 273 | EntityPtr closest; |
| 274 | float distSquared = square(radius); |
| 275 | RectF boundBox(center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius); |
| 276 | |
| 277 | m_spatialMap.forEach(m_geometry.splitRect(boundBox), [&](EntityPtr const& entity) { |
| 278 | Vec2F pos = entity->position(); |
| 279 | float thisDistSquared = m_geometry.diff(center, pos).magnitudeSquared(); |
| 280 | if (distSquared > thisDistSquared) { |
| 281 | if (!filter || filter(entity)) { |
| 282 | distSquared = thisDistSquared; |
| 283 | closest = entity; |
| 284 | } |
| 285 | } |
| 286 | }); |
| 287 | |
| 288 | return closest; |
| 289 | } |
| 290 | |
| 291 | InteractiveEntityPtr EntityMap::interactiveEntityNear(Vec2F const& pos, float maxRadius) const { |
| 292 | auto rect = RectF::withCenter(pos, Vec2F::filled(maxRadius)); |