Package arc.math.geom

Class BoundingBox

java.lang.Object
arc.math.geom.BoundingBox

public class BoundingBox extends Object
Encapsulates an axis aligned bounding box represented by a minimum and a maximum Vector. Additionally you can query for the bounding box's center, dimensions and corner points.
  • Field Details

    • min

      public final Vec3 min
    • max

      public final Vec3 max
  • Constructor Details

    • BoundingBox

      public BoundingBox()
      Constructs a new bounding box with the minimum and maximum vector set to zeros.
    • BoundingBox

      public BoundingBox(BoundingBox bounds)
      Constructs a new bounding box from the given bounding box.
      Parameters:
      bounds - The bounding box to copy
    • BoundingBox

      public BoundingBox(Vec3 minimum, Vec3 maximum)
      Constructs the new bounding box using the given minimum and maximum vector.
      Parameters:
      minimum - The minimum vector
      maximum - The maximum vector
  • Method Details

    • getCenter

      public Vec3 getCenter(Vec3 out)
      Parameters:
      out - The Vec3 to receive the center of the bounding box.
      Returns:
      The vector specified with the out argument.
    • getCenterX

      public float getCenterX()
    • getCenterY

      public float getCenterY()
    • getCenterZ

      public float getCenterZ()
    • getCorner000

      public Vec3 getCorner000(Vec3 out)
    • getCorner001

      public Vec3 getCorner001(Vec3 out)
    • getCorner010

      public Vec3 getCorner010(Vec3 out)
    • getCorner011

      public Vec3 getCorner011(Vec3 out)
    • getCorner100

      public Vec3 getCorner100(Vec3 out)
    • getCorner101

      public Vec3 getCorner101(Vec3 out)
    • getCorner110

      public Vec3 getCorner110(Vec3 out)
    • getCorner111

      public Vec3 getCorner111(Vec3 out)
    • getDimensions

      public Vec3 getDimensions(Vec3 out)
      Parameters:
      out - The Vec3 to receive the dimensions of this bounding box on all three axis.
      Returns:
      The vector specified with the out argument
    • getWidth

      public float getWidth()
    • getHeight

      public float getHeight()
    • getDepth

      public float getDepth()
    • getMin

      public Vec3 getMin(Vec3 out)
      Parameters:
      out - The Vec3 to receive the minimum values.
      Returns:
      The vector specified with the out argument
    • getMax

      public Vec3 getMax(Vec3 out)
      Parameters:
      out - The Vec3 to receive the maximum values.
      Returns:
      The vector specified with the out argument
    • set

      public BoundingBox set(BoundingBox bounds)
      Sets the given bounding box.
      Parameters:
      bounds - The bounds.
      Returns:
      This bounding box for chaining.
    • set

      public BoundingBox set(Vec3 minimum, Vec3 maximum)
      Sets the given minimum and maximum vector.
      Parameters:
      minimum - The minimum vector
      maximum - The maximum vector
      Returns:
      This bounding box for chaining.
    • set

      public BoundingBox set(Vec3[] points)
      Sets the bounding box minimum and maximum vector from the given points.
      Parameters:
      points - The points.
      Returns:
      This bounding box for chaining.
    • set

      public BoundingBox set(Seq<Vec3> points)
      Sets the bounding box minimum and maximum vector from the given points.
      Parameters:
      points - The points.
      Returns:
      This bounding box for chaining.
    • inf

      public BoundingBox inf()
      Sets the minimum and maximum vector to positive and negative infinity.
      Returns:
      This bounding box for chaining.
    • ext

      public BoundingBox ext(Vec3 point)
      Extends the bounding box to incorporate the given Vec3.
      Parameters:
      point - The vector
      Returns:
      This bounding box for chaining.
    • clr

      public BoundingBox clr()
      Sets the minimum and maximum vector to zeros.
      Returns:
      This bounding box for chaining.
    • isValid

      public boolean isValid()
      Returns whether this bounding box is valid. This means that max is greater than or equal to min.
      Returns:
      True in case the bounding box is valid, false otherwise
    • ext

      public BoundingBox ext(BoundingBox a_bounds)
      Extends this bounding box by the given bounding box.
      Parameters:
      a_bounds - The bounding box
      Returns:
      This bounding box for chaining.
    • ext

      public BoundingBox ext(Vec3 center, float radius)
      Extends this bounding box by the given sphere.
      Parameters:
      center - Sphere center
      radius - Sphere radius
      Returns:
      This bounding box for chaining.
    • contains

      public boolean contains(BoundingBox b)
      Returns whether the given bounding box is contained in this bounding box.
      Parameters:
      b - The bounding box
      Returns:
      Whether the given bounding box is contained
    • intersects

      public boolean intersects(BoundingBox b)
      Returns whether the given bounding box is intersecting this bounding box (at least one point in).
      Parameters:
      b - The bounding box
      Returns:
      Whether the given bounding box is intersected
    • contains

      public boolean contains(Vec3 v)
      Returns whether the given vector is contained in this bounding box.
      Parameters:
      v - The vector
      Returns:
      Whether the vector is contained or not.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • ext

      public BoundingBox ext(float x, float y, float z)
      Extends the bounding box by the given vector.
      Parameters:
      x - The x-coordinate
      y - The y-coordinate
      z - The z-coordinate
      Returns:
      This bounding box for chaining.