| Modifier and Type | Field and Description |
|---|---|
static java.util.Comparator<Rectangle> |
SIZE_COMPARATOR
A comparator that uses
size(Rectangle) as the measure. |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.Iterator<Coord> |
cells(Rectangle r)
Use
cellsList(Rectangle) if you want them all. |
static java.util.List<Coord> |
cellsList(Rectangle r)
Use
cells(Rectangle) if you may stop before the end of the
list, you'll save some memory. |
static Coord |
center(Rectangle r) |
static boolean |
contains(java.lang.Iterable<? extends Rectangle> rs,
Coord c) |
static boolean |
contains(Rectangle r,
Coord c) |
static boolean |
contains(Rectangle r,
int x,
int y) |
static boolean |
containsAny(Rectangle r,
java.util.Collection<Coord> cs) |
static Rectangle |
extend(Rectangle r,
Direction d) |
static Coord[] |
getAll4Corners(Rectangle r,
Coord[] buf) |
static java.util.List<Coord> |
getBorder(Rectangle r,
Direction cardinal,
java.util.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) |
public static final java.util.Comparator<Rectangle> SIZE_COMPARATOR
size(Rectangle) as the measure.public static boolean contains(Rectangle r, Coord c)
r - a Rectanglec - a Coord to check against r for presencer contains c.public static boolean contains(Rectangle r, int x, int y)
r - a Rectanglex - x-coordinate of a point to check against ry - y-coordinate of a point to check against rr contains c.public static boolean containsAny(Rectangle r, java.util.Collection<Coord> cs)
r - a Rectanglecs - a Collection of Coord to check against r; returns true if r contains any items in cstrue if r contains a member of cs.public static boolean contains(java.lang.Iterable<? extends Rectangle> rs, Coord c)
rs - an Iterable of Rectangle items to check against cc - a Coord to try to find in any of the Rectangles in rstrue if a member of rs
contains c.public static int size(Rectangle r)
r - a Rectangler covers.public static Coord center(Rectangle r)
r - a Rectangler.public static java.util.Iterator<Coord> cells(Rectangle r)
cellsList(Rectangle) if you want them all.r - a Rectangler contains, from bottom left to top
right; lazily computed.public static java.util.List<Coord> cellsList(Rectangle r)
cells(Rectangle) if you may stop before the end of the
list, you'll save some memory.r - r contains, from bottom left to top
right.public static Rectangle extend(Rectangle r, Direction d)
d - A direction.r extended to d by one row and/or column.public static Coord getCorner(Rectangle r, Direction dir)
r - dir - dir in
r.public static Coord[] getAll4Corners(Rectangle r, Coord[] buf)
r - buf - An array of (at least) size 4, to hold the 4 corners. It
is returned, except if null or too small, in which
case a fresh array is returned.buf, if it had length of at least 4, or a new 4-element array; it contains this Rectangle's 4 cornerspublic static Rectangle shrink(Rectangle r)
r - a Rectangle to shrinkpublic static java.util.List<Coord> getBorder(Rectangle r, Direction cardinal, java.util.List<Coord> buf)
r - cardinal - buf - The buffer to fill or null to let this method
allocate.r at the position cardinal,
i.e. the lowest line if r is Direction.DOWN,
the highest line if r is Direction.UP, the
leftest column if r is Direction.LEFT, and
the rightest column if r is Direction.RIGHT.Copyright © Eben Howard 2012–2022. All rights reserved.