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

Method reconnectCells

source/EngineInterface/DescriptionEditService.cpp:356–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356void DescriptionEditService::reconnectCells(DataDescription& data, float maxDistance)
357{
358 std::unordered_map<int, std::unordered_map<int, std::vector<int>>> cellIndicesBySlot;
359
360 int index = 0;
361 for (auto& cell : data.cells) {
362 cell.connections.clear();
363 cellIndicesBySlot[toInt(cell.pos.x)][toInt(cell.pos.y)].emplace_back(toInt(index));
364 ++index;
365 }
366
367 std::unordered_map<uint64_t, int> cache;
368 for (auto const& [index, cell] : data.cells | boost::adaptors::indexed(0)) {
369 cache.emplace(cell.id, static_cast<int>(index));
370 }
371 for (auto& cell : data.cells) {
372 auto nearbyCellIndices = getCellIndicesWithinRadius(data, cellIndicesBySlot, cell.pos, maxDistance);
373 for (auto const& nearbyCellIndex : nearbyCellIndices) {
374 auto const& nearbyCell = data.cells.at(nearbyCellIndex);
375 if (cell.id != nearbyCell.id && cell.connections.size() < cell.maxConnections && nearbyCell.connections.size() < nearbyCell.maxConnections
376 && !cell.isConnectedTo(nearbyCell.id)) {
377 data.addConnection(cell.id, nearbyCell.id, &cache);
378 }
379 }
380 }
381}
382
383void DescriptionEditService::removeStickiness(DataDescription& data)
384{

Callers 3

showMethod · 0.80
onDrawingMethod · 0.80
createDiscMethod · 0.80

Calls 5

toIntFunction · 0.85
sizeMethod · 0.80
isConnectedToMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected