MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / closestEntity

Method closestEntity

source/game/StarEntityMap.cpp:272–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272EntityPtr 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
291InteractiveEntityPtr EntityMap::interactiveEntityNear(Vec2F const& pos, float maxRadius) const {
292 auto rect = RectF::withCenter(pos, Vec2F::filled(maxRadius));

Callers

nothing calls this directly

Calls 7

squareFunction · 0.85
filterFunction · 0.85
magnitudeSquaredMethod · 0.80
forEachMethod · 0.45
splitRectMethod · 0.45
positionMethod · 0.45
diffMethod · 0.45

Tested by

no test coverage detected