public static CoordinateStream stream(ShortPoint2D center, float radius) { return stream(center.x, center.y, radius); }
@Test public void testBorderStream() { for (int i = 1; i < 40; i++) { MapCircle circle = new MapCircle(new ShortPoint2D(100, 100), i); MapCircle oneSmallerCircle = new MapCircle(new ShortPoint2D(100, 100), i - 1); circle.streamBorder().forEach((x, y) -> { assertTrue(circle.contains(x, y)); assertTrue(!oneSmallerCircle.contains(x, y)); }); int maxCount = circle.stream().count() - oneSmallerCircle.stream().count(); int actualCount = circle.streamBorder().count(); assertTrue(actualCount <= maxCount); } } }
@Override public CoordinateStream stream() { return stream(centerX, centerY, radius); }
@Override public void occupyAreaByTower(Player player, MapCircle influencingArea, FreeMapArea groundArea) { partitionsGrid.addTowerAndOccupyArea(player.playerId, influencingArea, groundArea); checkAllPositionsForEnclosedBlockedAreas(influencingArea.stream()); // TODO @Andreas Eberle only test the borders of changed areas!! }
public static CoordinateStream streamBorder(int centerX, int centerY, float radius) { return stream(centerX, centerY, radius).filter(getBorderPredicate(centerX, centerY, radius)); }
@Override public final Optional<ShortPoint2D> getConstructablePosition(ShortPoint2D pos, EBuildingType type, byte playerId) { return MapCircle.stream(pos, Constants.BUILDING_PLACEMENT_MAX_SEARCH_RADIUS) .filterBounds(width, height) .filter((x, y) -> constructionMarksGrid.canConstructAt(x, y, type, playerId)) .min((x, y) -> ShortPoint2D.getOnGridDist(pos.x, pos.y, x, y)); }
private void selectPointType(PointAction action) { final ShortPoint2D actionPosition = action.getPosition(); final IGuiMovable selectedMovable = getSelectableMovable(actionPosition.x, actionPosition.y).orElse(null); if (selectedMovable == null) { // nothing found at the location setSelection(new SelectionSet()); return; } EMovableType selectedType = selectedMovable.getMovableType(); byte selectedPlayerId = selectedMovable.getPlayer().getPlayerId(); Set<EMovableType> selectableTypes; if (selectedType.isSwordsman()) { selectableTypes = EMovableType.SWORDSMEN; } else if (selectedType.isPikeman()) { selectableTypes = EMovableType.PIKEMEN; } else if (selectedType.isBowman()) { selectableTypes = EMovableType.BOWMEN; } else { selectableTypes = EnumSet.of(selectedType); } final List<ISelectable> selected = new LinkedList<>(); MapCircle.stream(actionPosition, SELECT_BY_TYPE_RADIUS) .filterBounds(grid.getWidth(), grid.getHeight()) .forEach((x, y) -> { final IGuiMovable movable = grid.getMovable(x, y); if (movable != null && selectableTypes.contains(movable.getMovableType()) && selectedPlayerId == movable.getPlayer().getPlayerId()) { selected.add(movable); } }); setSelection(new SelectionSet(selected)); }
@Test public void testStream() { for (int i = 0; i < 40; i++) { MapCircle circle = new MapCircle(new ShortPoint2D(100, 100), i); MapCircleIterator iterator = circle.iterator(); circle.stream().forEach((x, y) -> { assertTrue(iterator.hasNext()); ShortPoint2D expected = iterator.next(); assertEquals(expected, new ShortPoint2D(x, y)); }); assertFalse(iterator.hasNext()); } }