Package dev.twilite.game.common
Record Class Rect
java.lang.Object
java.lang.Record
dev.twilite.game.common.Rect
Rectangular area on a single floor, inclusive of both minimum and maximum tiles.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether this area contains all of the supplied coordinates.booleanReturns whether this area contains any of the supplied coordinates.border()Returns every border tile coordinate contained by this area.center()Returns the center coordinate of this area, rounded down for even dimensions.booleanReturns whether this area contains the coordinate.booleanReturns whether this area fully contains another area.booleanReturns whether this area contains any tile occupied by a unit.coord()Returns the southwest/base coordinate of this area.coords()Returns every tile coordinate contained by this area.corners()Returns the corner coordinates of this area.directPathTo(Coord coord) Returns the direct greedy/dumb walk path from this area to a coordinate in the currently loaded world.directPathTo(Rect rect) Returns the direct greedy/dumb walk path from this area to another area in the currently loaded world.directPathTo(Unit unit) Returns the direct greedy/dumb walk path from this area to a unit in the currently loaded world.intdistanceTo(Coord coord) Returns Chebyshev tile distance from this area to a coordinate.intdistanceTo(Rect rect) Returns Chebyshev tile distance between this area and another area.intdistanceTo(Unit unit) Returns Chebyshev tile distance from this area to a unit's occupied area.dx(int x) Returns this area offset on the x-axis.dy(int y) Returns this area offset on the y-axis.booleanIndicates whether some other object is "equal to" this one.expanded(int radius) Returns this area expanded equally in every direction.expanded(int xRadius, int yRadius) Returns this area expanded by the supplied x/y radii.intfloor()Returns the value of thefloorrecord component.static RectCreates an area starting atcoord.inthashCode()Returns a hash code value for this object.intheight()Returns the value of theheightrecord component.intersection(Rect rect) Returns the overlapping area shared with another area on the same floor.booleanintersects(Rect rect) Returns whether this area overlaps another area on the same floor.booleanlineOfSightTo(Coord coord) Returns whether line of sight is clear from this area to a coordinate in the currently loaded world.booleanlineOfSightTo(Rect rect) Returns whether line of sight is clear from this area to another area in the currently loaded world.booleanlineOfSightTo(Unit unit) Returns whether line of sight is clear from this area to a unit in the currently loaded world.booleanlineOfWalkTo(Coord coord) Returns whether a direct line of walk is clear from this area to a coordinate in the currently loaded world.booleanlineOfWalkTo(Rect rect) Returns whether a direct line of walk is clear from this area to another area in the currently loaded world.booleanlineOfWalkTo(Unit unit) Returns whether a direct line of walk is clear from this area to a unit in the currently loaded world.intmanhattanDistanceTo(Coord coord) Returns Manhattan/taxicab tile distance from this area to a coordinate.intmanhattanDistanceTo(Rect rect) Returns Manhattan/taxicab tile distance between this area and another area.intmanhattanDistanceTo(Unit unit) Returns Manhattan/taxicab tile distance from this area to a unit's occupied area.intmaxX()Returns the greatest x tile contained by this area.intmaxY()Returns the greatest y tile contained by this area.booleanpathInDirection(int x, int y) Returns whether this area has an open one-tile path in the supplied direction in the currently loaded world.random()Returns a random coordinate contained by this area.Returns the coordinates immediately surrounding this area.surrounding(int radius) Returns the coordinates around this area at the supplied radius.Converts this template area to its matching loaded instance area.final StringtoString()Returns a string representation of this record class.Converts this loaded instance area to its source template area.transform(UnaryOperator<Coord> transform) Transforms all coords in a rect and returns the transformed recttranslate(int x, int y) Returns this area offset by the supplied x/y deltas.Returns the smallest area that contains this area and another area on the same floor.intwidth()Returns the value of thewidthrecord component.intx()Returns the value of thexrecord component.inty()Returns the value of theyrecord component.
-
Constructor Details
-
Rect
Creates an area starting atcoord. -
Rect
public Rect(int x, int y, int width, int height, int floor) Creates an instance of aRectrecord class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord componentwidth- the value for thewidthrecord componentheight- the value for theheightrecord componentfloor- the value for thefloorrecord component
-
-
Method Details
-
from
Creates an area starting atcoord. -
coord
Returns the southwest/base coordinate of this area. -
maxX
public int maxX()Returns the greatest x tile contained by this area. -
maxY
public int maxY()Returns the greatest y tile contained by this area. -
contains
Returns whether this area contains the coordinate. -
contains
Returns whether this area fully contains another area. Useintersects(Rect)to check if this area contains a single coordinate of another area. -
any
Returns whether this area contains any of the supplied coordinates. -
all
Returns whether this area contains all of the supplied coordinates. -
intersects
Returns whether this area overlaps another area on the same floor. -
intersection
Returns the overlapping area shared with another area on the same floor. -
union
Returns the smallest area that contains this area and another area on the same floor. -
contains
Returns whether this area contains any tile occupied by a unit. -
translate
Returns this area offset by the supplied x/y deltas. -
dx
Returns this area offset on the x-axis. -
dy
Returns this area offset on the y-axis. -
expanded
Returns this area expanded equally in every direction. -
expanded
Returns this area expanded by the supplied x/y radii. -
distanceTo
Returns Chebyshev tile distance from this area to a coordinate. -
distanceTo
Returns Chebyshev tile distance between this area and another area. -
distanceTo
Returns Chebyshev tile distance from this area to a unit's occupied area. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance from this area to a coordinate. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance between this area and another area. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance from this area to a unit's occupied area. -
lineOfSightTo
Returns whether line of sight is clear from this area to a coordinate in the currently loaded world. -
lineOfSightTo
Returns whether line of sight is clear from this area to a unit in the currently loaded world. -
lineOfSightTo
Returns whether line of sight is clear from this area to another area in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this area to a coordinate in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this area to a unit in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this area to another area in the currently loaded world. -
directPathTo
Returns the direct greedy/dumb walk path from this area to a coordinate in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
directPathTo
Returns the direct greedy/dumb walk path from this area to a unit in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
directPathTo
Returns the direct greedy/dumb walk path from this area to another area in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
pathInDirection
public boolean pathInDirection(int x, int y) Returns whether this area has an open one-tile path in the supplied direction in the currently loaded world. -
toTemplate
Converts this loaded instance area to its source template area. Returns this area when it is not in an instance or no template mapping is available. -
toInstance
Converts this template area to its matching loaded instance area. Returns this area when it is already in an instance or no instance mapping is available. -
transform
Transforms all coords in a rect and returns the transformed rect -
coords
Returns every tile coordinate contained by this area. -
border
Returns every border tile coordinate contained by this area. -
corners
Returns the corner coordinates of this area. -
surrounding
Returns the coordinates immediately surrounding this area. -
surrounding
Returns the coordinates around this area at the supplied radius. -
center
Returns the center coordinate of this area, rounded down for even dimensions. -
random
Returns a random coordinate contained by this area. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
x
public int x()Returns the value of thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public int y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-
width
public int width()Returns the value of thewidthrecord component.- Returns:
- the value of the
widthrecord component
-
height
public int height()Returns the value of theheightrecord component.- Returns:
- the value of the
heightrecord component
-
floor
public int floor()Returns the value of thefloorrecord component.- Returns:
- the value of the
floorrecord component
-