Class CuboidDTO

java.lang.Object
cn.lunadeer.dominion.api.dtos.CuboidDTO

public class CuboidDTO extends Object
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
    Modifier and Type
    Field
    Description
    static CuboidDTO
    A cuboid whose coordinate extents are all zero.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CuboidDTO(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 Type
    Method
    Description
    void
    addDown(int size)
    Moves the lower y-boundary by the specified amount.
    void
    addEast(int size)
    Moves the upper x-boundary by the specified amount (east).
    void
    addNorth(int size)
    Moves the lower z-boundary by the specified amount (north).
    void
    addSouth(int size)
    Moves the upper z-boundary by the specified amount (south).
    void
    addUp(int size)
    Moves the upper y-boundary by the specified amount.
    void
    addWest(int size)
    Moves the lower x-boundary by the specified amount (west).
    boolean
    contain(int x, int y, int z)
    Checks whether the specified block coordinate is inside this cuboid.
    boolean
    Checks whether this cuboid contains another cuboid, including coincident boundaries.
    boolean
    contain(CuboidDTO cuboid, boolean ignoreY)
    Checks whether this cuboid contains another cuboid, optionally ignoring the y-axis.
    boolean
    Checks whether this cuboid is contained by another cuboid.
    org.bukkit.Location
    getLoc1(org.bukkit.World world)
    Converts the lower corner to a Bukkit location in the specified world.
    org.bukkit.Location
    getLoc2(org.bukkit.World world)
    Converts the upper corner to a Bukkit location in the specified world.
    int[]
    Gets a copy of the lower corner of the cuboid.
    int[]
    Gets a copy of the upper corner of the cuboid.
    long
    Gets the area of the cuboid's horizontal base (x and z extents).
    long
    Gets the cuboid volume from its three coordinate extents.
    boolean
    Checks whether this cuboid has a non-zero-volume intersection with another cuboid.
    long
    Calculates this cuboid's horizontal area minus another cuboid's area.
    long
    Calculates this cuboid's volume minus another cuboid's volume.
    void
    setPos1(int[] pos1)
    Sets the first corner of the cuboid.
    void
    setPos2(int[] pos2)
    Sets the second corner of the cuboid.
    int
    x1()
    Gets the x-coordinate of the first position.
    int
    x2()
    Gets the x-coordinate of the second position.
    long
    Gets the coordinate extent of the cuboid along the x-axis.
    int
    y1()
    Gets the y-coordinate of the first position.
    int
    y2()
    Gets the y-coordinate of the second position.
    long
    Gets the coordinate extent of the cuboid along the y-axis.
    int
    z1()
    Gets the z-coordinate of the first position.
    int
    z2()
    Gets the z-coordinate of the second position.
    long
    Gets the coordinate extent of the cuboid along the z-axis.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ZERO

      public static CuboidDTO 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

      public CuboidDTO(CuboidDTO cuboid)
      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 position
      y1 - the y-coordinate of the first position
      z1 - the z-coordinate of the first position
      x2 - the x-coordinate of the second position
      y2 - the y-coordinate of the second position
      z2 - the z-coordinate of the second position
    • CuboidDTO

      public CuboidDTO(Vector<Integer> pos1, Vector<Integer> pos2)
      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 cuboid
      loc2 - 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).
      Returns:
      xLength() multiplied by zLength()
    • getVolume

      public long getVolume()
      Gets the cuboid volume from its three coordinate extents.
      Returns:
      xLength() multiplied by yLength() and zLength()
    • intersectWith

      public boolean intersectWith(CuboidDTO cuboid)
      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

      public boolean contain(CuboidDTO cuboid)
      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

      public boolean contain(CuboidDTO cuboid, boolean ignoreY)
      Checks whether this cuboid contains another cuboid, optionally ignoring the y-axis.
      Parameters:
      cuboid - the other cuboid to check for containment
      ignoreY - 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 check
      y - the y-coordinate to check
      z - the z-coordinate to check
      Returns:
      true if this cuboid contains the specified coordinates, false otherwise
    • containedBy

      public boolean containedBy(CuboidDTO cuboid)
      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

      public long minusSquareWith(CuboidDTO cuboid)
      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

      public long minusVolumeWith(CuboidDTO cuboid)
      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