Record Class Box

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Box
All Implemented Interfaces:
Shape3D

public record Box(float x, float y, float z, float width, float height, float depth) extends Record implements Shape3D
Immutable three-dimensional box with float precision. The box is specified based on the position of its top-left corner and its size.
  • Field Summary

    Fields inherited from interface nl.colorize.multimedialib.math.Shape3D

    EPSILON
  • Constructor Summary

    Constructors
    Constructor
    Description
    Box(float x, float y, float z, float width, float height, float depth)
    Creates an instance of a Box record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Box
    around(Point3D center, float width, float height, float depth)
    Factory method that creates a box based on the location of its center point.
    static Box
    aroundOrigin(float width, float height, float depth)
    Factory method that creates a box with its center point located at the origin (0, 0, 0).
    combine(Box other)
    Returns a new box that encompasses both this box and the specified other box.
    boolean
    contains(Box other)
    Returns true if the specified other box is entirely or partially located within this box.
    boolean
    Returns true if the specified point is located within this box.
    float
    Returns the value of the depth record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Box
    fromPoints(float x0, float y0, float z0, float x1, float y1, float z1)
    Factory method that creates a box based on the points (x0, y0, z0) and (x1, y1, z1).
    Returns the smallest possible bounding box that can fit this shape.
     
    float
     
    float
     
    float
     
    final int
    Returns a hash code value for this object.
    float
    Returns the value of the height record component.
    boolean
    intersects(Box other)
    Returns true if the specified other box intersects with this box.
    Returns a new Shape3D instance that is repositioned by the specified offset.
    Returns a string representation of this record class.
    float
    Returns the value of the width record component.
    float
    x()
    Returns the value of the x record component.
    float
    y()
    Returns the value of the y record component.
    float
    z()
    Returns the value of the z record component.

    Methods inherited from class java.lang.Object

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

    • Box

      public Box(float x, float y, float z, float width, float height, float depth)
      Creates an instance of a Box record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
      z - the value for the z record component
      width - the value for the width record component
      height - the value for the height record component
      depth - the value for the depth record component
  • Method Details

    • getEndX

      public float getEndX()
    • getEndY

      public float getEndY()
    • getEndZ

      public float getEndZ()
    • getBoundingBox

      public Box getBoundingBox()
      Description copied from interface: Shape3D
      Returns the smallest possible bounding box that can fit this shape.
      Specified by:
      getBoundingBox in interface Shape3D
    • getCenter

      public Point3D getCenter()
      Specified by:
      getCenter in interface Shape3D
    • contains

      public boolean contains(Point3D point)
      Returns true if the specified point is located within this box.
      Specified by:
      contains in interface Shape3D
    • contains

      public boolean contains(Box other)
      Returns true if the specified other box is entirely or partially located within this box.
    • intersects

      public boolean intersects(Box other)
      Returns true if the specified other box intersects with this box.
    • reposition

      public Box reposition(Point3D offset)
      Description copied from interface: Shape3D
      Returns a new Shape3D instance that is repositioned by the specified offset.
      Specified by:
      reposition in interface Shape3D
    • combine

      public Box combine(Box other)
      Returns a new box that encompasses both this box and the specified other box.
    • toString

      public 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
    • fromPoints

      public static Box fromPoints(float x0, float y0, float z0, float x1, float y1, float z1)
      Factory method that creates a box based on the points (x0, y0, z0) and (x1, y1, z1).
    • around

      public static Box around(Point3D center, float width, float height, float depth)
      Factory method that creates a box based on the location of its center point.
    • aroundOrigin

      public static Box aroundOrigin(float width, float height, float depth)
      Factory method that creates a box with its center point located at the origin (0, 0, 0).
    • 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 '=='.
      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.
    • x

      public float x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public float y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • z

      public float z()
      Returns the value of the z record component.
      Returns:
      the value of the z record component
    • width

      public float width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public float height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component
    • depth

      public float depth()
      Returns the value of the depth record component.
      Returns:
      the value of the depth record component