package inf101.v18.grid; import java.util.List; import java.util.stream.Stream; /** * Representation of a two-dimensional area. *
* This describes the coordinate system of the area and defines the set of valid * locations within the area. *
* See {@link #location(int, int)} to covert (x,y)-coordinates to * {@link ILocation}s. *
* An {@link IArea} does not store anything, it just defines valid
* storage locations (e.g., for an {@link IGrid}), and the relationships between
* locations (e.g., how to find neighbours of a given location).
*
* @author Anya Helene Bagge, UiB
*/
public interface IArea extends Iterable
* The iterator will yield up to eight positions (less if the given position is
* at the edge of the area, and the coordinates are not wrapped). E.g., for a
* 1x1 area, the iterator will yield nothing (if the area is not wrapped), or
* the same position two or eight times (if the area is wrapped horizontally,
* vertically or both).
*
* @param pos
* A position in the area
* @return An iterable over positions, with {@link #contains(ILocation)} being
* true for each position.
* @see #wrapsHorizontally(), {@link #wrapsVertically()}
* @throws IndexOutOfBoundsException
* if !contains(pos)
*/
Iterable
* With no wrapping, accessing positions outside (0,0)–(getWidth(),getHeight())
* is illegal.
*
* @return True if the area wraps around horizontally
*/
boolean wrapsHorizontally();
/**
* If the area wraps vertically, then y will be the same as y+(k*getHeight())
* for any k – i.e., it will be as if the 2D area is projected on a cylinder or
* torus in 3D-space.
*
* With no wrapping, accessing positions outside (0,0)–(getWidth(),getHeight())
* is illegal.
*
* @return True if the area wraps around vertically
*/
boolean wrapsVertically();
/** @return A {@link Stream} of all locations in the area */
Stream
* Returns a location
* Since IArea is @{@link Iterable}, you can also use directly in a for-loop to
* iterate over the locations.
*
* All locations in the list are guaranteed to be valid
* according to {@link #isValid(ILocation)}. The returned list cannot be modified.
*
* @return An unmodifiable list with all the locations in the area
*/
Listl = fromIndex(i)
such that
* toIndex(l.getX(), l.getY()) == i
.
*
* @param i
* @return A location
*/
ILocation fromIndex(int i);
/**
* Get all locations in area
*