public MapCircleIterator(MapCircle circle) { this.circle = circle; radius = circle.getRadius(); currentY = -(int) (radius / MapCircle.Y_SCALE); currentLineHalfWidth = circle.getHalfLineWidth(currentY); currentX = -currentLineHalfWidth; centerX = circle.getCenterX(); centerY = circle.getCenterY(); }
public final boolean contains(int x, int y) { if (!containsLine(y)) { return false; } return !(x < getLineStartX(y - getMinY()) || x > getLineEndX(y - getMinY())); }
/** * Test method for {@link jsettlers.common.map.shapes.MapCircle#iterator()}. */ @Test public void testIterator() { MapCircle circle = new MapCircle((short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2), 31.123f); testShapeIterator(circle); }
@Override public final boolean contains(ShortPoint2D pos) { return contains(pos.x, pos.y); }
@Override public CoordinateStream stream() { return stream(centerX, centerY, radius); }
/** * Gets the distance of map coordinates to the center. * * @param x * The x coordinate. * @param y * The y coordinate * @return The distance to the center of this circle, so that the tiles around the center all have distance 1. */ public final float squaredDistanceToCenter(int x, int y) { return getSquaredDistance(x - centerX, y - centerY); }
/** * Gets the last x coordinate contained by a line. * * @param line * The line relative to the first line of this rectangle. */ public final int getLineEndX(int line) { return getLineStartX(line) + this.width - 1; }
@Test public void testParallelogramIterator() { Parallelogram rect = new Parallelogram((short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect); Parallelogram rect2 = new Parallelogram((short) (TEST_WIDTH / 4 + 1), (short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect2); Parallelogram rect3 = new Parallelogram((short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 4 + 1), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect3); }
/** * 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(); }
/** * Gets the half width of a line, roundend. * * @param relativeY * The x coordinate of the line relative to the center * @return The width of the line, NAN if the line is outside the circle. */ protected final float getHalfLineWidth(int relativeY) { return calculateHalfLineWidth(radius, relativeY); }
/** * Creates a free map area by converting the relative points to absolute ones. * * @param pos * The origin for the relative points * @param relativePoints * The relative points */ public FreeMapArea(ShortPoint2D pos, RelativePoint[] relativePoints) { this(convertRelative(pos, relativePoints)); }
/** * Gets the first x coordinate contained by a line. * * @param line * The line relative to the first line of this rectangle. */ public final int getLineStartX(int line) { return minX + getOffsetForLine(line); }
public boolean contains(int x, int y) { int dx = x - xOffset; int dy = y - yOffset; return isValidMapPos(dx, dy) && areaMap[dx][dy]; }
@Override public boolean contains(ShortPoint2D position) { return contains(position.x, position.y); }
@Override public Iterator<ShortPoint2D> iterator() { return new ParallelogramIterator(); }
@Override public HexGridAreaIterator iterator() { return new HexGridAreaIterator(this); }
@Override public final MapCircleIterator iterator() { return new MapCircleIterator(this); }
public static final float getDistanceSquared(int x1, int y1, int x2, int y2) { int dx = x1 - x2; int dy = y1 - y2; return getSquaredDistance(dx, dy); }