Package cn.lunadeer.dominion.api.dtos
Class CuboidDTO
java.lang.Object
cn.lunadeer.dominion.api.dtos.CuboidDTO
Represents an axis-aligned cuboid in block coordinates.
The lower and upper coordinates are normalized independently on each axis. Containment of a block coordinate uses a half-open range: the lower bound is inclusive and the upper bound is exclusive.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCuboidDTO(int[] pos1, int[] pos2) Constructs a cuboid from two three-element coordinate arrays.CuboidDTO(int x1, int y1, int z1, int x2, int y2, int z2) Constructs a CuboidDTO with the specified coordinates.Constructs a copy of the specified cuboid.Constructs a cuboid from two three-element coordinate vectors.CuboidDTO(org.bukkit.Location loc1, org.bukkit.Location loc2) Constructs a cuboid from the block coordinates of two Bukkit locations. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDown(int size) Moves the lower y-boundary by the specified amount.voidaddEast(int size) Moves the upper x-boundary by the specified amount (east).voidaddNorth(int size) Moves the lower z-boundary by the specified amount (north).voidaddSouth(int size) Moves the upper z-boundary by the specified amount (south).voidaddUp(int size) Moves the upper y-boundary by the specified amount.voidaddWest(int size) Moves the lower x-boundary by the specified amount (west).booleancontain(int x, int y, int z) Checks whether the specified block coordinate is inside this cuboid.booleanChecks whether this cuboid contains another cuboid, including coincident boundaries.booleanChecks whether this cuboid contains another cuboid, optionally ignoring the y-axis.booleancontainedBy(CuboidDTO cuboid) Checks whether this cuboid is contained by another cuboid.org.bukkit.LocationgetLoc1(org.bukkit.World world) Converts the lower corner to a Bukkit location in the specified world.org.bukkit.LocationgetLoc2(org.bukkit.World world) Converts the upper corner to a Bukkit location in the specified world.int[]getPos1()Gets a copy of the lower corner of the cuboid.int[]getPos2()Gets a copy of the upper corner of the cuboid.longGets the area of the cuboid's horizontal base (x and z extents).longGets the cuboid volume from its three coordinate extents.booleanintersectWith(CuboidDTO cuboid) Checks whether this cuboid has a non-zero-volume intersection with another cuboid.longminusSquareWith(CuboidDTO cuboid) Calculates this cuboid's horizontal area minus another cuboid's area.longminusVolumeWith(CuboidDTO cuboid) Calculates this cuboid's volume minus another cuboid's volume.voidsetPos1(int[] pos1) Sets the first corner of the cuboid.voidsetPos2(int[] pos2) Sets the second corner of the cuboid.intx1()Gets the x-coordinate of the first position.intx2()Gets the x-coordinate of the second position.longxLength()Gets the coordinate extent of the cuboid along the x-axis.inty1()Gets the y-coordinate of the first position.inty2()Gets the y-coordinate of the second position.longyLength()Gets the coordinate extent of the cuboid along the y-axis.intz1()Gets the z-coordinate of the first position.intz2()Gets the z-coordinate of the second position.longzLength()Gets the coordinate extent of the cuboid along the z-axis.
-
Field Details
-
ZERO
A cuboid whose coordinate extents are all zero.
-
-
Constructor Details
-
CuboidDTO
public CuboidDTO(int[] pos1, int[] pos2) Constructs a cuboid from two three-element coordinate arrays.- Parameters:
pos1- the first position as[x, y, z]pos2- the second position as[x, y, z]
-
CuboidDTO
Constructs a copy of the specified cuboid.- Parameters:
cuboid- the cuboid whose coordinates are copied
-
CuboidDTO
public CuboidDTO(int x1, int y1, int z1, int x2, int y2, int z2) Constructs a CuboidDTO with the specified coordinates.- Parameters:
x1- the x-coordinate of the first positiony1- the y-coordinate of the first positionz1- the z-coordinate of the first positionx2- the x-coordinate of the second positiony2- the y-coordinate of the second positionz2- the z-coordinate of the second position
-
CuboidDTO
Constructs a cuboid from two three-element coordinate vectors.- Parameters:
pos1- the first position as[x, y, z]pos2- the second position as[x, y, z]
-
CuboidDTO
public CuboidDTO(org.bukkit.Location loc1, org.bukkit.Location loc2) Constructs a cuboid from the block coordinates of two Bukkit locations. The world associated with either location is not stored by this class.- Parameters:
loc1- the first location of the cuboidloc2- the second location of the cuboid
-
-
Method Details
-
getPos1
public int[] getPos1()Gets a copy of the lower corner of the cuboid.- Returns:
- a three-element array in
[x, y, z]order
-
setPos1
public void setPos1(int[] pos1) Sets the first corner of the cuboid.The supplied array is copied. This method does not automatically normalize the second corner after the assignment.
- Parameters:
pos1- the new corner as[x, y, z]
-
getPos2
public int[] getPos2()Gets a copy of the upper corner of the cuboid.- Returns:
- a three-element array in
[x, y, z]order
-
setPos2
public void setPos2(int[] pos2) Sets the second corner of the cuboid.The supplied array is copied. This method does not automatically normalize the first corner after the assignment.
- Parameters:
pos2- the new corner as[x, y, z]
-
getLoc1
public org.bukkit.Location getLoc1(org.bukkit.World world) Converts the lower corner to a Bukkit location in the specified world.- Parameters:
world- the world in which the cuboid is located- Returns:
- the first location of the cuboid
-
getLoc2
public org.bukkit.Location getLoc2(org.bukkit.World world) Converts the upper corner to a Bukkit location in the specified world.- Parameters:
world- the world in which the cuboid is located- Returns:
- the second location of the cuboid
-
x1
public int x1()Gets the x-coordinate of the first position.- Returns:
- the x-coordinate of the first position
-
y1
public int y1()Gets the y-coordinate of the first position.- Returns:
- the y-coordinate of the first position
-
z1
public int z1()Gets the z-coordinate of the first position.- Returns:
- the z-coordinate of the first position
-
x2
public int x2()Gets the x-coordinate of the second position.- Returns:
- the x-coordinate of the second position
-
y2
public int y2()Gets the y-coordinate of the second position.- Returns:
- the y-coordinate of the second position
-
z2
public int z2()Gets the z-coordinate of the second position.- Returns:
- the z-coordinate of the second position
-
xLength
public long xLength()Gets the coordinate extent of the cuboid along the x-axis.- Returns:
x2 - x1
-
yLength
public long yLength()Gets the coordinate extent of the cuboid along the y-axis.- Returns:
y2 - y1
-
zLength
public long zLength()Gets the coordinate extent of the cuboid along the z-axis.- Returns:
z2 - z1
-
getSquare
public long getSquare()Gets the area of the cuboid's horizontal base (x and z extents). -
getVolume
public long getVolume()Gets the cuboid volume from its three coordinate extents. -
intersectWith
Checks whether this cuboid has a non-zero-volume intersection with another cuboid. Cuboids that only touch at a face, edge, or corner do not intersect.- Parameters:
cuboid- the other cuboid to check for intersection- Returns:
- true if the cuboids intersect, false otherwise
-
contain
Checks whether this cuboid contains another cuboid, including coincident boundaries.- Parameters:
cuboid- the other cuboid to check for containment- Returns:
- true if this cuboid contains the other cuboid, false otherwise
-
contain
Checks whether this cuboid contains another cuboid, optionally ignoring the y-axis.- Parameters:
cuboid- the other cuboid to check for containmentignoreY- if true, ignores the y-dimension in the containment check- Returns:
- true if this cuboid contains the other cuboid, false otherwise
-
contain
public boolean contain(int x, int y, int z) Checks whether the specified block coordinate is inside this cuboid. The lower bounds are inclusive and the upper bounds are exclusive.- Parameters:
x- the x-coordinate to checky- the y-coordinate to checkz- the z-coordinate to check- Returns:
- true if this cuboid contains the specified coordinates, false otherwise
-
containedBy
Checks whether this cuboid is contained by another cuboid.- Parameters:
cuboid- the other cuboid to check for containment- Returns:
- true if this cuboid is contained by the other cuboid, false otherwise
-
minusSquareWith
Calculates this cuboid's horizontal area minus another cuboid's area.- Parameters:
cuboid- the other cuboid to compare with- Returns:
this.getSquare() - cuboid.getSquare()
-
minusVolumeWith
Calculates this cuboid's volume minus another cuboid's volume.- Parameters:
cuboid- the other cuboid to compare with- Returns:
this.getVolume() - cuboid.getVolume()
-
addUp
public void addUp(int size) Moves the upper y-boundary by the specified amount. A negative amount contracts the cuboid; the implementation preserves a minimum one-coordinate-unit extent when a boundary would cross.- Parameters:
size- the number of coordinate units to add to the upper y-boundary
-
addDown
public void addDown(int size) Moves the lower y-boundary by the specified amount.- Parameters:
size- the number of coordinate units to subtract from the lower y-boundary
-
addNorth
public void addNorth(int size) Moves the lower z-boundary by the specified amount (north).- Parameters:
size- the number of coordinate units to subtract from the lower z-boundary
-
addSouth
public void addSouth(int size) Moves the upper z-boundary by the specified amount (south).- Parameters:
size- the number of coordinate units to add to the upper z-boundary
-
addEast
public void addEast(int size) Moves the upper x-boundary by the specified amount (east).- Parameters:
size- the number of coordinate units to add to the upper x-boundary
-
addWest
public void addWest(int size) Moves the lower x-boundary by the specified amount (west).- Parameters:
size- the number of coordinate units to subtract from the lower x-boundary
-