Package limn.math

Record Class Aabb


public record Aabb(Vec3 min, Vec3 max) extends Record
An axis-aligned bounding box. Used for the broadphase of picking and (later) frustum culling. Build one by folding points into EMPTY with union(limn.math.Vec3).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Aabb
    Inverted/empty box (min = +∞, max = −∞), the identity for union(limn.math.Vec3).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Aabb(Vec3 min, Vec3 max)
    Creates an instance of a Aabb record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Midpoint of the box.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Full size per axis: max - min, not the half-extent.
    final int
    Returns a hash code value for this object.
    float
    Ray/box intersection (slab method).
    boolean
    Whether the box is inverted on any axis, which is what EMPTY is.
    max()
    Returns the value of the max record component.
    min()
    Returns the value of the min record component.
    static Aabb
    of(Vec3 min, Vec3 max)
    A box from explicit corners; the caller guarantees min <= max per axis.
    final String
    Returns a string representation of this record class.
    World-space AABB of this box transformed by an affine m (bottom row 0,0,0,1, which every model/world matrix has).
    This box grown to contain another; EMPTY is the identity.
    This box grown to contain p.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • EMPTY

      public static final Aabb EMPTY
      Inverted/empty box (min = +∞, max = −∞), the identity for union(limn.math.Vec3).
  • Constructor Details

    • Aabb

      public Aabb(Vec3 min, Vec3 max)
      Creates an instance of a Aabb record class.
      Parameters:
      min - the value for the min record component
      max - the value for the max record component
  • Method Details

    • of

      public static Aabb of(Vec3 min, Vec3 max)
      A box from explicit corners; the caller guarantees min <= max per axis.
    • union

      public Aabb union(Vec3 p)
      This box grown to contain p.
    • union

      public Aabb union(Aabb o)
      This box grown to contain another; EMPTY is the identity.
    • isEmpty

      public boolean isEmpty()
      Whether the box is inverted on any axis, which is what EMPTY is.
    • center

      public Vec3 center()
      Midpoint of the box. Meaningless when isEmpty().
    • extent

      public Vec3 extent()
      Full size per axis: max - min, not the half-extent.
    • transformedBy

      public Aabb transformedBy(Mat4 m)
      World-space AABB of this box transformed by an affine m (bottom row 0,0,0,1, which every model/world matrix has). Arvo's method: new center = M·c, new half-extent = |M|·h. That is equivalent to transforming the 8 corners but allocation-light (runs per mesh per frame for culling). An empty box stays EMPTY.
    • intersect

      public float intersect(Ray ray)
      Ray/box intersection (slab method). Returns the nearest non-negative distance t of entry (or 0 if the origin is inside), or Float.NaN if the ray misses.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • min

      public Vec3 min()
      Returns the value of the min record component.
      Returns:
      the value of the min record component
    • max

      public Vec3 max()
      Returns the value of the max record component.
      Returns:
      the value of the max record component