Record Class Rect

java.lang.Object
java.lang.Record
dev.twilite.game.common.Rect

public record Rect(int x, int y, int width, int height, int floor) extends Record
Rectangular area on a single floor, inclusive of both minimum and maximum tiles.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rect(int x, int y, int width, int height, int floor)
    Creates an instance of a Rect record class.
    Rect(Coord coord, int width, int height)
    Creates an area starting at coord.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    all(Iterable<Coord> coords)
    Returns whether this area contains all of the supplied coordinates.
    boolean
    any(Iterable<Coord> coords)
    Returns whether this area contains any of the supplied coordinates.
    Returns every border tile coordinate contained by this area.
    Returns the center coordinate of this area, rounded down for even dimensions.
    boolean
    contains(Coord coord)
    Returns whether this area contains the coordinate.
    boolean
    contains(Rect rect)
    Returns whether this area fully contains another area.
    boolean
    contains(Unit unit)
    Returns whether this area contains any tile occupied by a unit.
    Returns the southwest/base coordinate of this area.
    Returns every tile coordinate contained by this area.
    Returns the corner coordinates of this area.
    Returns the direct greedy/dumb walk path from this area to a coordinate in the currently loaded world.
    Returns the direct greedy/dumb walk path from this area to another area in the currently loaded world.
    Returns the direct greedy/dumb walk path from this area to a unit in the currently loaded world.
    int
    Returns Chebyshev tile distance from this area to a coordinate.
    int
    Returns Chebyshev tile distance between this area and another area.
    int
    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.
    boolean
    equals(Object other)
    Indicates 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.
    int
    Returns the value of the floor record component.
    static Rect
    from(Coord coord, int width, int height)
    Creates an area starting at coord.
    int
    Returns a hash code value for this object.
    int
    Returns the value of the height record component.
    Returns the overlapping area shared with another area on the same floor.
    boolean
    Returns whether this area overlaps another area on the same floor.
    boolean
    Returns whether line of sight is clear from this area to a coordinate in the currently loaded world.
    boolean
    Returns whether line of sight is clear from this area to another area in the currently loaded world.
    boolean
    Returns whether line of sight is clear from this area to a unit in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this area to a coordinate in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this area to another area in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this area to a unit in the currently loaded world.
    int
    Returns Manhattan/taxicab tile distance from this area to a coordinate.
    int
    Returns Manhattan/taxicab tile distance between this area and another area.
    int
    Returns Manhattan/taxicab tile distance from this area to a unit's occupied area.
    int
    Returns the greatest x tile contained by this area.
    int
    Returns the greatest y tile contained by this area.
    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.
    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 String
    Returns a string representation of this record class.
    Converts this loaded instance area to its source template area.
    Transforms all coords in a rect and returns the transformed rect
    translate(int x, int y)
    Returns this area offset by the supplied x/y deltas.
    union(Rect rect)
    Returns the smallest area that contains this area and another area on the same floor.
    int
    Returns the value of the width record component.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Rect

      public Rect(Coord coord, int width, int height)
      Creates an area starting at coord.
    • Rect

      public Rect(int x, int y, int width, int height, int floor)
      Creates an instance of a Rect record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
      width - the value for the width record component
      height - the value for the height record component
      floor - the value for the floor record component
  • Method Details

    • from

      public static Rect from(Coord coord, int width, int height)
      Creates an area starting at coord.
    • coord

      public Coord 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

      public boolean contains(Coord coord)
      Returns whether this area contains the coordinate.
    • contains

      public boolean contains(Rect rect)
      Returns whether this area fully contains another area. Use intersects(Rect) to check if this area contains a single coordinate of another area.
    • any

      public boolean any(Iterable<Coord> coords)
      Returns whether this area contains any of the supplied coordinates.
    • all

      public boolean all(Iterable<Coord> coords)
      Returns whether this area contains all of the supplied coordinates.
    • intersects

      public boolean intersects(Rect rect)
      Returns whether this area overlaps another area on the same floor.
    • intersection

      public Optional<Rect> intersection(Rect rect)
      Returns the overlapping area shared with another area on the same floor.
    • union

      public Optional<Rect> union(Rect rect)
      Returns the smallest area that contains this area and another area on the same floor.
    • contains

      public boolean contains(Unit unit)
      Returns whether this area contains any tile occupied by a unit.
    • translate

      public Rect translate(int x, int y)
      Returns this area offset by the supplied x/y deltas.
    • dx

      public Rect dx(int x)
      Returns this area offset on the x-axis.
    • dy

      public Rect dy(int y)
      Returns this area offset on the y-axis.
    • expanded

      public Rect expanded(int radius)
      Returns this area expanded equally in every direction.
    • expanded

      public Rect expanded(int xRadius, int yRadius)
      Returns this area expanded by the supplied x/y radii.
    • distanceTo

      public int distanceTo(Coord coord)
      Returns Chebyshev tile distance from this area to a coordinate.
    • distanceTo

      public int distanceTo(Rect rect)
      Returns Chebyshev tile distance between this area and another area.
    • distanceTo

      public int distanceTo(Unit unit)
      Returns Chebyshev tile distance from this area to a unit's occupied area.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Coord coord)
      Returns Manhattan/taxicab tile distance from this area to a coordinate.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Rect rect)
      Returns Manhattan/taxicab tile distance between this area and another area.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Unit unit)
      Returns Manhattan/taxicab tile distance from this area to a unit's occupied area.
    • lineOfSightTo

      public boolean lineOfSightTo(Coord coord)
      Returns whether line of sight is clear from this area to a coordinate in the currently loaded world.
    • lineOfSightTo

      public boolean lineOfSightTo(Unit unit)
      Returns whether line of sight is clear from this area to a unit in the currently loaded world.
    • lineOfSightTo

      public boolean lineOfSightTo(Rect rect)
      Returns whether line of sight is clear from this area to another area in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Coord coord)
      Returns whether a direct line of walk is clear from this area to a coordinate in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Unit unit)
      Returns whether a direct line of walk is clear from this area to a unit in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Rect rect)
      Returns whether a direct line of walk is clear from this area to another area in the currently loaded world.
    • directPathTo

      public List<Coord> directPathTo(Coord coord)
      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

      public List<Coord> directPathTo(Unit unit)
      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

      public List<Coord> directPathTo(Rect rect)
      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

      public Rect 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

      public Rect 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

      public Rect transform(UnaryOperator<Coord> transform)
      Transforms all coords in a rect and returns the transformed rect
    • coords

      public List<Coord> coords()
      Returns every tile coordinate contained by this area.
    • border

      public List<Coord> border()
      Returns every border tile coordinate contained by this area.
    • corners

      public List<Coord> corners()
      Returns the corner coordinates of this area.
    • surrounding

      public List<Coord> surrounding()
      Returns the coordinates immediately surrounding this area.
    • surrounding

      public List<Coord> surrounding(int radius)
      Returns the coordinates around this area at the supplied radius.
    • center

      public Coord center()
      Returns the center coordinate of this area, rounded down for even dimensions.
    • random

      public Coord random()
      Returns a random coordinate contained by this area.
    • equals

      public boolean equals(Object other)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      other - the object with which to compare
      Returns:
      true if this object is the same as the other argument; false otherwise.
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public int y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • width

      public int width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public int height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component
    • floor

      public int floor()
      Returns the value of the floor record component.
      Returns:
      the value of the floor record component