Package squidpony.squidgrid.mapping
Class Rectangle.Utils
java.lang.Object
squidpony.squidgrid.mapping.Rectangle.Utils
- Enclosing interface:
- Rectangle
public static class Rectangle.Utils extends Object
Utilities pertaining to
Rectangle- Author:
- smelC
-
Field Summary
Fields Modifier and Type Field Description static Comparator<Rectangle>SIZE_COMPARATORA comparator that usessize(Rectangle)as the measure. -
Constructor Summary
Constructors Constructor Description Utils() -
Method Summary
Modifier and Type Method Description static Iterator<Coord>cells(Rectangle r)UsecellsList(Rectangle)if you want them all.static List<Coord>cellsList(Rectangle r)Usecells(Rectangle)if you may stop before the end of the list, you'll save some memory.static Coordcenter(Rectangle r)static booleancontains(Iterable<? extends Rectangle> rs, Coord c)static booleancontains(Rectangle r, int x, int y)static booleancontains(Rectangle r, Coord c)static booleancontainsAny(Rectangle r, Collection<Coord> cs)static Rectangleextend(Rectangle r, Direction d)static Coord[]getAll4Corners(Rectangle r, Coord[] buf)static List<Coord>getBorder(Rectangle r, Direction cardinal, List<Coord> buf)static CoordgetCorner(Rectangle r, Direction dir)static Rectangleshrink(Rectangle r)Creates a new Rectangle that is smaller than r by 1 cell from each of r's edges, to a minimum of a 1x1 cell.static intsize(Rectangle r)
-
Field Details
-
SIZE_COMPARATOR
A comparator that usessize(Rectangle)as the measure.
-
-
Constructor Details
-
Method Details
-
contains
- Parameters:
r- a Rectanglec- a Coord to check against r for presence- Returns:
- Whether
rcontainsc.
-
contains
- Parameters:
r- a Rectanglex- x-coordinate of a point to check against ry- y-coordinate of a point to check against r- Returns:
- Whether
rcontainsc.
-
containsAny
- Parameters:
r- a Rectanglecs- a Collection of Coord to check against r; returns true if r contains any items in cs- Returns:
trueifrcontains a member ofcs.
-
contains
- Parameters:
rs- an Iterable of Rectangle items to check against cc- a Coord to try to find in any of the Rectangles in rs- Returns:
trueif a member ofrscontainsc.
-
size
- Parameters:
r- a Rectangle- Returns:
- The number of cells that
rcovers.
-
center
- Parameters:
r- a Rectangle- Returns:
- The center of
r.
-
cells
UsecellsList(Rectangle)if you want them all.- Parameters:
r- a Rectangle- Returns:
- The cells that
rcontains, from bottom left to top right; lazily computed.
-
cellsList
Usecells(Rectangle)if you may stop before the end of the list, you'll save some memory.- Parameters:
r-- Returns:
- The cells that
rcontains, from bottom left to top right.
-
extend
- Parameters:
d- A direction.- Returns:
rextended todby one row and/or column.
-
getCorner
- Parameters:
r-dir-- Returns:
- The coord at the corner identified by
dirinr.
-
getAll4Corners
- Parameters:
r-buf- An array of (at least) size 4, to hold the 4 corners. It is returned, except ifnullor too small, in which case a fresh array is returned.- Returns:
buf, if it had length of at least 4, or a new 4-element array; it contains this Rectangle's 4 corners
-
shrink
Creates a new Rectangle that is smaller than r by 1 cell from each of r's edges, to a minimum of a 1x1 cell.- Parameters:
r- a Rectangle to shrink- Returns:
- the shrunken Rectangle, newly-allocated
-
getBorder
- Parameters:
r-cardinal-buf- The buffer to fill ornullto let this method allocate.- Returns:
- The border of
rat the positioncardinal, i.e. the lowest line ifrisDirection.DOWN, the highest line ifrisDirection.UP, the leftest column ifrisDirection.LEFT, and the rightest column ifrisDirection.RIGHT.
-