protected void correctPosition( BasicModelData obj, PositionSettings pos, List<HeightInfo> positions) { double xVar = xRatio; double zVar = zRatio; double x = obj.getX(); double z = obj.getZ(); if (!positions.isEmpty() || collisionTree != null) { HeightInfo actual = new HeightInfo(obj.getX(), 0, obj.getZ()); HeightInfo nearest = new HeightInfo(Double.MAX_VALUE, 0, Double.MAX_VALUE); if (!positions.isEmpty()) { nearest = findNearest(positions, actual, nearest); x = nearest.getX(); z = nearest.getZ(); } if (collisionTree != null) { actual.setSx(obj.getSx()); actual.setSz(obj.getSz()); TreeNode place = collisionTree.findPlace(actual); if (place != null) { x = place.getMid()[0]; z = place.getMid()[1]; double nodeRange = place.getRange(); xVar = nodeRange + 1 - actual.getSx(); zVar = nodeRange + 1 - actual.getSz(); TreeNode.mark(place); } else { collisionDetected = true; } } } obj.setX(x + randomizeDouble(-xVar, xVar)); obj.setZ(z + randomizeDouble(-zVar, zVar)); correctPosition(obj, pos); }