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_COMPARATOR
A 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 Coord
center(Rectangle r)
static boolean
contains(Iterable<? extends Rectangle> rs, Coord c)
static boolean
contains(Rectangle r, int x, int y)
static boolean
contains(Rectangle r, Coord c)
static boolean
containsAny(Rectangle r, Collection<Coord> cs)
static Rectangle
extend(Rectangle r, Direction d)
static Coord[]
getAll4Corners(Rectangle r, Coord[] buf)
static List<Coord>
getBorder(Rectangle r, Direction cardinal, List<Coord> buf)
static Coord
getCorner(Rectangle r, Direction dir)
static Rectangle
shrink(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 int
size(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
r
containsc
.
-
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
r
containsc
.
-
containsAny
- Parameters:
r
- a Rectanglecs
- a Collection of Coord to check against r; returns true if r contains any items in cs- Returns:
true
ifr
contains 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:
true
if a member ofrs
contains
c
.
-
size
- Parameters:
r
- a Rectangle- Returns:
- The number of cells that
r
covers.
-
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
r
contains, 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
r
contains, from bottom left to top right.
-
extend
- Parameters:
d
- A direction.- Returns:
r
extended tod
by one row and/or column.
-
getCorner
- Parameters:
r
-dir
-- Returns:
- The coord at the corner identified by
dir
inr
.
-
getAll4Corners
- Parameters:
r
-buf
- An array of (at least) size 4, to hold the 4 corners. It is returned, except ifnull
or 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 ornull
to let this method allocate.- Returns:
- The border of
r
at the positioncardinal
, i.e. the lowest line ifr
isDirection.DOWN
, the highest line ifr
isDirection.UP
, the leftest column ifr
isDirection.LEFT
, and the rightest column ifr
isDirection.RIGHT
.
-