public class Area
extends java.lang.Object
Constructor and Description |
---|
Area(int[][] positions)
Constructs a polygonal area using each set in a 2d array as a pair of x and y position coordinates.
|
Area(int x1,
int y1,
int x2,
int y2)
Constructs a rectangular area using x and y coordinates from two separate positions.
|
Area(java.awt.Polygon polygon)
Constructs an area based on a
Polygon |
Area(Position[] positions)
Constructs a polygonal area using each position as a point in the polygon.
|
Area(Position southWest,
Position northEast)
Constructs a rectangular area using two positions
Note: The plane is set to the z coordinate of both positions, throwing an IllegalArgumentException if they do not match |
Area(java.awt.Rectangle rectangle)
Constructs a rectangular area using a
Rectangle . |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Entity entity)
Checks if the entity is within the area
|
boolean |
contains(int x,
int y) |
boolean |
contains(int x,
int y,
int z) |
boolean |
contains(Position position)
Checks if the position is within the area
|
Position |
getCentralPosition()
Gets the central position of the area
When the central position is not a round number, the values are rounded up.
|
int |
getPlane() |
java.awt.Polygon |
getPolygon() |
java.util.List<Position> |
getPositions() |
Position |
getRandomPosition() |
Area |
setPlane(int plane)
Sets the plane (z coordinate) for this area; by default this value is set to 0.
|
java.lang.String |
toString()
Returns Position#toString() for all positions within the area
|
public Area(int[][] positions)
positions
- A 2d array of map positionspublic Area(Position[] positions)
positions
- An array of positions to add to the areapublic Area(int x1, int y1, int x2, int y2)
x1
- The bottom left x bound (inclusive)y1
- The bottom left y bound (inclusive)x2
- The top right x bound (inclusive)y2
- The top right y bound (inclusive)public Area(java.awt.Polygon polygon)
Polygon
polygon
- The polygon areapublic Area(java.awt.Rectangle rectangle)
Rectangle
.
Note: The width and height are NOT the south-east position but function as actual width and heightrectangle
- The area rectanglepublic Area(Position southWest, Position northEast)
southWest
- A south-west positionnorthEast
- A north-east positionpublic Area setPlane(int plane)
plane
- The plane to for this areapublic int getPlane()
public java.awt.Polygon getPolygon()
public boolean contains(int x, int y)
x
- The position x coordinatey
- The position y coordinatepublic boolean contains(int x, int y, int z)
x
- The position x coordinatey
- The position y coordinatez
- The position z coordinatepublic boolean contains(Position position)
position
- The position to checkpublic boolean contains(Entity entity)
entity
- The entity to checkpublic java.util.List<Position> getPositions()
public Position getRandomPosition()
public Position getCentralPosition()
public java.lang.String toString()
toString
in class java.lang.Object