@Override public final boolean contains(ShortPoint2D position) { return contains(position.x, position.y); }
@Override public boolean iterate(IBooleanCoordinateFunction function) { for (int relativeY = 0; relativeY < height; relativeY++) { int lineStartX = getLineStartX(relativeY); for (int relativeX = 0; relativeX < width; relativeX++) { int x = lineStartX + relativeX; int y = getLineY(relativeY); if (!function.apply(x, y)) { return false; } } } return true; } };
public void setMapViewport(MapRectangle screenArea, IGraphicsGrid grid) { this.grid = grid; short x = (short) (screenArea.getMinX() + (screenArea.getWidth() / 2)); short y = (short) (screenArea.getMinY() + (screenArea.getHeight() / 2)); displayCenter = new ShortPoint2D(x, y); sendMapPositionChange(); }
public final boolean contains(int x, int y) { if (!containsLine(y)) { return false; } return !(x < getLineStartX(y - getMinY()) || x > getLineEndX(y - getMinY())); }
final short[] yJumps = buildingArea.yJumps; final int lineLength = mapArea.getWidth() + mapArea.getHeight() / 2; final BitSet doneSet = new BitSet(lineLength * mapArea.getHeight()); for (int line = 0; line < mapArea.getHeight(); line++) { final int y = mapArea.getLineY(line); final int xLineOffset = mapArea.getMinX(); final short partitionId; if (!mapArea.contains(x, y) || doneSet.get(dx + line * lineLength)) { // if this position has already been pruned. continue;
int line = (int) (Math.random() * screen.getHeight()); int x0 = screen.getLineStartX(line); int x = x0 + (int) (Math.random() * screen.getWidth()); int y = screen.getLineY(line); } else if (hasMountain(x, y)) { sound.playSound(INDEX_MOUNTAIN, MOUNTAIN_VOLUME, x, y); } else for (int x1 = 0; x1 < screen.getWidth(); x1++) { if (hasRiver(x0 + x1, y)) { sound.playSound(INDEX_RIVER, RIVER_VOLUME, x0 + x1, y);
for (int line = 0; line < area.getHeight() + 50 && linePartiallyVisible; line++) { int y = area.getLineY(line); if (y < 0) { continue; int endX = Math.min(area.getLineEndX(line), width - 1); int startX = Math.max(area.getLineStartX(line), 0); for (int x = startX; x <= endX; x++) { drawTile(x, y);
int rand = random.nextInt(alternatives.length); int maxA = area.getWidth(); // get screen area int maxB = area.getHeight(); int b = y - area.getMinY(); int a = x - area.getLineStartX(b); float leftVolume, rightVolume;
private ShortPoint2D searchNext() { int startLine = currentLine; while (startLine >= currentLine - 2 || currentLine < MIN_SEARCH_LINES) { currentX++; if (currentX > base.getLineEndX(currentLine)) { currentLine++; currentX = base.getLineStartX(currentLine); } int x = currentX; int y = base.getLineY(currentLine); if (contains(x, y)) { return new ShortPoint2D(x, y); } } return null; }
@Test public void containsBorders() { MapRectangle mapRectangle = new MapRectangle(0, 0, 10, 10); assertTrue(mapRectangle.contains(0, 0)); assertTrue(mapRectangle.contains(9, 0)); assertTrue(mapRectangle.contains(4, 9)); assertTrue(mapRectangle.contains(13, 9)); }
@Override public boolean iterate(IBooleanCoordinateFunction function) { MapRectangle rect = getConverter().getMapForScreen(drawRect); for (int x = rect.getMinX(); x <= rect.getMinX() + rect.getHeight(); x++) { for (int y = rect.getMinY(); y <= rect.getMinY() + rect.getHeight(); y++) { if (HeightedMapRectangle.this.contains(x, y)) { if (!function.apply(x, y)) { return false; } } } } return true; } };
/** * Test method for {@link jsettlers.common.map.shapes.MapRectangle#iterator()}. */ @Test public void testRectIterator() { MapRectangle rect = new MapRectangle((short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect); MapRectangle rect2 = new MapRectangle((short) (TEST_WIDTH / 4 + 1), (short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect2); MapRectangle rect3 = new MapRectangle((short) (TEST_WIDTH / 4), (short) (TEST_WIDTH / 4 + 1), (short) (TEST_WIDTH / 2), (short) (TEST_WIDTH / 2)); testShapeIterator(rect3); }
/** * Removes all construction marks on the screen. */ public void removeConstructionMarks() { if (lastArea != null) { lastArea.stream() .filterBounds(map.getWidth(), map.getHeight()) .forEach((x, y) -> map.setConstructMarking(x, y, false, false, null)); lastArea = null; } }
/** * 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 containsNotOutsideBorders() { MapRectangle mapRectangle = new MapRectangle(0, 0, 10, 10); assertFalse(mapRectangle.contains(0 - 1, 0)); assertFalse(mapRectangle.contains(0, -1)); assertFalse(mapRectangle.contains(-1, -1)); assertFalse(mapRectangle.contains(10, 0)); assertFalse(mapRectangle.contains(9, -1)); assertFalse(mapRectangle.contains(10, -1)); assertFalse(mapRectangle.contains(4 - 1, 9)); assertFalse(mapRectangle.contains(4, 9 + 1)); assertFalse(mapRectangle.contains(4 - 1, 9 + 1)); assertFalse(mapRectangle.contains(13 + 1, 9)); assertFalse(mapRectangle.contains(13, 9 + 1)); assertFalse(mapRectangle.contains(13 + 1, 9 + 1)); } }
/** * Gets a rectangle that is almost covered by the given int rectangle. * <p> * No assumptions can be made about the rect. * * @param screen * The screen positions * @return A MapRectangle */ public MapRectangle getMapForScreen(FloatRectangle screen) { float maxMountainHeight = HEIGHT_Y_DISPLACEMENT * Byte.MAX_VALUE; float minX = getExactMapXwithHeight(screen.getMinX(), screen.getMaxY(), 0); float maxX = getExactMapXwithHeight(screen.getMaxX(), screen.getMinY(), maxMountainHeight); float minY = getExactMapYwithHeight(screen.getMaxX(), screen.getMaxY(), 0); float maxY = getExactMapYwithHeight(screen.getMinX(), screen.getMinY(), maxMountainHeight); return new MapRectangle((short) minX, (short) minY, (short) (maxX - minX), (short) (maxY - minY)); }
private void drawDebugColors() { GLDrawContext gl = this.context.getGl(); if(shapeHandle == null || !shapeHandle.isValid()) shapeHandle = gl.storeGeometry(shape, EGeometryFormatType.VertexOnly2D, false, "debugshape"); int drawX = context.getOffsetX(); int drawY = context.getOffsetY(); context.getScreenArea().stream().filterBounds(width, height).forEach((x, y) -> { try { int argb = map.getDebugColorAt(x, y, debugColorMode); if (argb != 0) { int height = context.getHeight(x, y); float dx = drawX+context.getConverter().getViewX(x, y, height); float dy = drawY+context.getConverter().getViewY(x, y, height); gl.draw2D(shapeHandle, null, EGeometryType.Quad, 0, 4, dx, dy, .5f, 1, 1, 1, Color.fromShort((short) argb), 1); } } catch (IllegalBufferException e) { // TODO: Create a crash report // This should never happen since we only use texture 0 (no texture) } }); }
@Override public ShortPoint2D next() { if (relativeY < height && width > 0) { int x = getLineStartX(relativeY) + relativeX; int y = getLineY(relativeY); ShortPoint2D pos = new ShortPoint2D(x, y); relativeX++; if (relativeX >= width) { relativeX = 0; relativeY++; } return pos; } else { throw new NoSuchElementException("There are no more elements in the shape"); } }