Class CoordArea
- java.lang.Object
-
- org.rspeer.game.coord.shape.CoordArea
-
- All Implemented Interfaces:
CoordShape
public class CoordArea extends Object implements CoordShape
Represents an axis-aligned rectangular area of world coordinates on a single floor level.A
CoordAreais defined by two cornerCoordvalues and a target floor. X- and Y-spans are automatically normalized viaRange.ordered(int, int), ensuringminimum() <= maximum()for both axes.All coordinates are inclusive: an area from (10, 20) to (12, 23) contains 3 × 4 = 12 tiles.
Floor-level handling
By default, the area only matches coordinates on the same floor level. CallingignoreFloorLevel()allowscontains(SceneNode)to match regardless of floor.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(SceneNode node)Checks whether the given coordinate lies inside this rectangular area.static CoordAreafrom(Coord coord)static CoordAreafrom(Coord a, Coord b)Constructs a rectangular coordinate area from two opposite corner coordinates, using the floor of the coord as the area floorstatic CoordAreafrom(Coord a, Coord b, int floorLevel)Constructs a rectangular coordinate area from two opposite corner coordinates.CoordAreaViewgetAreaView()CoordgetBottomLeft()CoordgetBottomRight()Set<Coord>getBoundary(boolean outer)Returns all coordinates forming the perimeter of the rectangle.Set<Coord>getCoords()Returns all coordinates contained within this rectangular area.intgetFloorLevel()intgetHeight()Returns the height of the area in tiles.CoordgetTopLeft()CoordgetTopRight()Set<Coord>getVertices()Returns the four rectangle corner coordinates in a fixed order: bottom-left, top-left, bottom-right, top-right.intgetWidth()Returns the width of the area in tiles.RangegetXs()RangegetYs()CoordAreaignoreFloorLevel()Allows the area to match coordinates on any floor level instead of only the configuredfloorLevel.static CoordAreasurrounding(Coord origin, int distance)AreatoArea()
-
-
-
Method Detail
-
from
public static CoordArea from(Coord a, Coord b, int floorLevel)
Constructs a rectangular coordinate area from two opposite corner coordinates.The X and Y ranges are normalized so that the rectangle always spans:
xs.minimum() .. xs.maximum() ys.minimum() .. ys.maximum()
- Parameters:
a- one corner of the rectangleb- the opposite corner of the rectanglefloorLevel- the floor level this area applies to
-
from
public static CoordArea from(Coord a, Coord b)
Constructs a rectangular coordinate area from two opposite corner coordinates, using the floor of the coord as the area floorThe X and Y ranges are normalized so that the rectangle always spans:
xs.minimum() .. xs.maximum() ys.minimum() .. ys.maximum()
- Parameters:
a- one corner of the rectangleb- the opposite corner of the rectangle
-
from
public static CoordArea from(Coord coord)
Creates aCoordArearepresenting exactly one tile — the givenCoord.This is equivalent to constructing an area where both corners are the same coordinate:
new CoordArea(coord, coord, coord.getFloorLevel())
The resulting area has:
- width = 1
- height = 1
- floor level taken from the provided coord
- exactly one tile returned by
getCoords()
- Parameters:
coord- the coordinate defining the single-tile area (must not be null)- Returns:
- a
CoordAreacontaining only the specified coordinate
-
toArea
public Area toArea()
-
ignoreFloorLevel
public CoordArea ignoreFloorLevel()
Allows the area to match coordinates on any floor level instead of only the configuredfloorLevel.- Returns:
- this area (for chaining)
-
getXs
public Range getXs()
- Returns:
- the inclusive X-range for this area
-
getYs
public Range getYs()
- Returns:
- the inclusive Y-range for this area
-
getBottomLeft
public Coord getBottomLeft()
-
getBottomRight
public Coord getBottomRight()
-
getTopLeft
public Coord getTopLeft()
-
getTopRight
public Coord getTopRight()
-
getWidth
public int getWidth()
Returns the width of the area in tiles.Because the range is inclusive, width is computed as:
maxX - minX + 1
- Returns:
- the number of tiles spanned along the X axis
-
getHeight
public int getHeight()
Returns the height of the area in tiles.- Returns:
- the number of tiles spanned along the Y axis
-
contains
public boolean contains(SceneNode node)
Checks whether the given coordinate lies inside this rectangular area.If
ignoreFloorLevel()was called, the floor does not matter.- Specified by:
containsin interfaceCoordShape- Parameters:
node- the node to test- Returns:
trueif inside the rectangle
-
getVertices
public Set<Coord> getVertices()
Returns the four rectangle corner coordinates in a fixed order: bottom-left, top-left, bottom-right, top-right.- Specified by:
getVerticesin interfaceCoordShape- Returns:
- an immutable set of the rectangle's vertices
-
getBoundary
public Set<Coord> getBoundary(boolean outer)
Returns all coordinates forming the perimeter of the rectangle.- Specified by:
getBoundaryin interfaceCoordShape- Parameters:
outer- iftrue, returns the outer boundary (one tile outside the rectangle);
iffalse, returns the perimeter tiles on the rectangle itself.- Returns:
- a set of perimeter coordinates
-
getCoords
public Set<Coord> getCoords()
Returns all coordinates contained within this rectangular area.For large rectangles, this may be a large set. The set is pre-sized to avoid internal resizing.
- Specified by:
getCoordsin interfaceCoordShape- Returns:
- all coordinates inside the area
-
getFloorLevel
public int getFloorLevel()
-
getAreaView
public CoordAreaView getAreaView()
-
-