@Override public CoordinateStream stream() { return stream(x, y); }
@Override public boolean contains(ShortPoint2D position) { return contains(position.x, position.y); }
private EDirection getDirectionOfMaximumHeightDifference(int x, int y, int minimumHeightDifference) { byte height = landscapeGrid.getHeightAt(x, y); for (ShortPoint2D pos : new MapNeighboursArea((short) x, (short) y)) { if (Math.abs(height - landscapeGrid.getHeightAt(pos.x, pos.y)) >= minimumHeightDifference) { return EDirection.getDirection((short) x, (short) y, pos.x, pos.y); } } return null; }
private boolean hasNeighbourLandscape(int x, int y, ELandscapeType landscape) { for (ShortPoint2D pos : new MapNeighboursArea(new ShortPoint2D(x, y))) { if (isInBounds(pos.x, pos.y) && landscapeGrid.getLandscapeTypeAt(pos.x, pos.y) == landscape) { return true; } } return false; }
private static void setupInitial(int width, int height, ICoordinatePredicate provider, BitSet done, BitSet next) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (provider.test(x, y)) { done.set(width * y + x); // set as done MapNeighboursArea.stream(x, y).filterBounds(width, height).forEach((neighborX, neighborY) -> { // set neighbors for next run next.set(width * neighborY + neighborX); }); } } } } }
public static BitSet calculatePositionsInDistance(int width, int height, ICoordinatePredicate provider, int maxDistance) { int area = width * height; BitSet inDistance = new BitSet(area); BitSet next = new BitSet(area); setupInitial(width, height, provider, inDistance, next); // DebugImagesHelper.writeDebugImageBoolean("inDistance-" + 0, width, height, (x, y) -> inDistance.get(x + y * width)); for (int distance = 1; distance <= maxDistance; distance++) { next.andNot(inDistance); BitSet current = next; if (current.isEmpty()) { break; } BitSet neighbors = new BitSet(area); for (int index = current.nextSetBit(0); index >= 0; index = current.nextSetBit(index + 1)) { int x = index % width; int y = index / width; MapNeighboursArea.stream(x, y).filterBounds(width, height).forEach((neighborX, neighborY) -> { // set neighbors for next run neighbors.set(width * neighborY + neighborX); }); } next = neighbors; inDistance.or(current); // DebugImagesHelper.writeDebugImageBoolean("inDistance-" + distance, width, height, (x, y) -> inDistance.get(x + y * width)); } return inDistance; }
private boolean hasBlockedNeighbor(short x, short y) { return !MapNeighboursArea.stream(x, y).iterate((currX, currY) -> isInBounds(currX, currY) && !flagsGrid.isBlocked(currX, currY)); }
private boolean hasNeighborIngestibleByPioneersOf(int x, int y, Player player) { return !MapNeighboursArea.stream(x, y) .filterBounds(mainGrid.getWidth(), mainGrid.getHeight()) .filter((currX, currY) -> isIngestibleByPioneersOf(currX, currY, player)) .isEmpty(); }