@Override public final MapCircleIterator iterator() { return new MapCircleIterator(this); }
/** * NOTE: nextY() MUST BE CALLED before this method is called! * * @return gives the x of the current iterator position */ public final int nextX() { return computeNextXAndProgress(); }
public CachedViewCircle(int radius) { radius -= FogOfWar.PADDING / 2; MapCircle circle = new MapCircle(0, 0, radius + FogOfWar.PADDING); size = countElements(circle); x = new short[size]; y = new short[size]; sight = new byte[size]; MapCircleIterator iter = circle.iterator(); final float squaredViewDistance = radius * radius; int i = 0; while (iter.hasNext()) { int y = iter.nextY(); int x = iter.nextX(); this.x[i] = (short) x; this.y[i] = (short) y; double squaredDistance = MapCircle.getSquaredDistance(x, y); byte newSight; if (squaredDistance < squaredViewDistance) { newSight = CommonConstants.FOG_OF_WAR_VISIBLE; } else { newSight = (byte) (CommonConstants.FOG_OF_WAR_VISIBLE - (Math.sqrt(squaredDistance) - radius) / FogOfWar.PADDING * CommonConstants.FOG_OF_WAR_VISIBLE); } sight[i] = newSight; i++; } }
@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()); } }
}; boolean result = AreaTraversingAlgorithm.traverseArea(containingProvider, visitor, c1.iterator().next(), WIDTH, HEIGHT); assertTrue(result);
@Override public ShortPoint2D next() { int y = currentY + centerY; int x = computeNextXAndProgress(); return new ShortPoint2D(x, y); }