MCPcopy Create free account
hub / github.com/chrxh/alien / isCellPresent

Method isCellPresent

source/EngineInterface/DescriptionEditService.cpp:617–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615}
616
617bool DescriptionEditService::isCellPresent(Occupancy const& cellPosBySlot, SpaceCalculator const& spaceCalculator, RealVector2D const& posToCheck, float distance)
618{
619 auto intPos = toIntVector2D(posToCheck);
620
621 auto getMatchingSlots = [&cellPosBySlot](IntVector2D const& intPos) {
622 auto findResult = cellPosBySlot.find(intPos);
623 if (findResult != cellPosBySlot.end()) {
624 return findResult->second;
625 }
626 return std::vector<RealVector2D>{};
627 };
628
629 auto isOccupied = [&](std::vector<RealVector2D> const& cellPositions) {
630 for (auto const& cellPos : cellPositions) {
631 auto otherPos = spaceCalculator.getCorrectedPosition(cellPos);
632 if (Math::length(posToCheck - otherPos) < distance) {
633 return true;
634 }
635 }
636 return false;
637 };
638
639 auto distanceInt = toInt(ceilf(distance));
640 for (int dx = -distanceInt; dx <= distanceInt; ++dx) {
641 for (int dy = -distanceInt; dy <= distanceInt; ++dy) {
642 if (isOccupied(getMatchingSlots({intPos.x + dx, intPos.y + dy}))) {
643 return true;
644 }
645 }
646 }
647 return false;
648}
649
650uint64_t DescriptionEditService::getId(CellOrParticleDescription const& entity)
651{

Callers

nothing calls this directly

Calls 5

toIntVector2DFunction · 0.85
toIntFunction · 0.85
findMethod · 0.80
endMethod · 0.80
getCorrectedPositionMethod · 0.80

Tested by

no test coverage detected