| 264 | } |
| 265 | |
| 266 | DataDescription DescriptionEditService::randomMultiply( |
| 267 | DataDescription const& input, |
| 268 | RandomMultiplyParameters const& parameters, |
| 269 | IntVector2D const& worldSize, |
| 270 | DataDescription&& existentData, |
| 271 | bool& overlappingCheckSuccessful) |
| 272 | { |
| 273 | overlappingCheckSuccessful = true; |
| 274 | SpaceCalculator spaceCalculator(worldSize); |
| 275 | std::unordered_map<IntVector2D, std::vector<RealVector2D>> cellPosBySlot; |
| 276 | |
| 277 | //create map for overlapping check |
| 278 | if (parameters._overlappingCheck) { |
| 279 | int index = 0; |
| 280 | for (auto const& cell : existentData.cells) { |
| 281 | auto intPos = toIntVector2D(spaceCalculator.getCorrectedPosition(cell.pos)); |
| 282 | cellPosBySlot[intPos].emplace_back(cell.pos); |
| 283 | ++index; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | //do multiplication |
| 288 | DataDescription result = input; |
| 289 | generateNewIds(result); |
| 290 | auto& numberGen = NumberGenerator::get(); |
| 291 | for (int i = 0; i < parameters._number; ++i) { |
| 292 | bool overlapping = false; |
| 293 | DataDescription copy; |
| 294 | int attempts = 0; |
| 295 | do { |
| 296 | copy = input; |
| 297 | removeMetadata(copy); |
| 298 | copy.shift({toFloat(numberGen.getRandomReal(0, toInt(worldSize.x))), toFloat(numberGen.getRandomReal(0, toInt(worldSize.y)))}); |
| 299 | copy.rotate(toInt(numberGen.getRandomReal(parameters._minAngle, parameters._maxAngle))); |
| 300 | copy.accelerate( |
| 301 | {toFloat(numberGen.getRandomReal(parameters._minVelX, parameters._maxVelX)), |
| 302 | toFloat(numberGen.getRandomReal(parameters._minVelY, parameters._maxVelY))}, |
| 303 | toFloat(numberGen.getRandomReal(parameters._minAngularVel, parameters._maxAngularVel))); |
| 304 | |
| 305 | //overlapping check |
| 306 | overlapping = false; |
| 307 | if (parameters._overlappingCheck) { |
| 308 | for (auto const& cell : copy.cells) { |
| 309 | auto pos = spaceCalculator.getCorrectedPosition(cell.pos); |
| 310 | if (isCellPresent(cellPosBySlot, spaceCalculator, pos, 2.0f)) { |
| 311 | overlapping = true; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | ++attempts; |
| 316 | } while (overlapping && attempts < 200 && overlappingCheckSuccessful); |
| 317 | if (attempts == 200) { |
| 318 | overlappingCheckSuccessful = false; |
| 319 | } |
| 320 | |
| 321 | generateNewIds(copy); |
| 322 | generateNewCreatureIds(copy); |
| 323 | result.add(copy); |
no test coverage detected