Package org.sunflow.math

## Class BoundingBox

- java.lang.Object
- - org.sunflow.math.BoundingBox

-     public class BoundingBox
      extends java.lang.Object

  3D axis-aligned bounding box. Stores only the minimum and maximum corner points.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `BoundingBox()` | Creates an empty box.
    `BoundingBox​(float size)` | Creates a bounding box centered around the origin.
    `BoundingBox​(float x, float y, float z)` | Creates a bounding box containing only the specified point.
    `BoundingBox​(BoundingBox b)` | Creates a copy of the given box.
    `BoundingBox​(Point3 p)` | Creates a bounding box containing only the specified point.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `contains​(float x, float y, float z)` | Check to see if the specified point is inside the volume defined by this box.
    `boolean` | `contains​(Point3 p)` | Checks to see if the specified `point`is inside the volume defined by this box.
    `void` | `enlargeUlps()` | Enlarge the bounding box by the minimum possible amount to avoid numeric precision related problems.
    `float` | `getArea()` | Gets the surface area of the box.
    `float` | `getBound​(int i)` | Gets a specific coordinate of the surface's bounding box.
    `Point3` | `getCenter()` | Gets the center of the box, computed as (min + max) / 2.
    `Point3` | `getCorner​(int i)` | Gets a corner of the bounding box.
    `Vector3` | `getExtents()` | Gets the extents vector for the box.
    `Point3` | `getMaximum()` | Gets the maximum corner of the box.
    `Point3` | `getMinimum()` | Gets the minimum corner of the box.
    `float` | `getVolume()` | Gets the box's volume
    `void` | `include​(float x, float y, float z)` | Changes the extents of the box as needed to include the given point into this box.
    `void` | `include​(BoundingBox b)` | Changes the extents of the box as needed to include the given box into this box.
    `void` | `include​(Point3 p)` | Changes the extents of the box as needed to include the given `point`into this box.
    `boolean` | `intersects​(BoundingBox b)` | Returns `true` if the specified bounding box intersects this one.
    `boolean` | `isEmpty()` | Returns `true` when the box has just been initialized, and is still empty.
    `java.lang.String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### BoundingBox

          public BoundingBox()

      Creates an empty box. The minimum point will have all components set to positive infinity, and the maximum will have all components set to negative infinity.

    - #### BoundingBox

          public BoundingBox​(BoundingBox b)

      Creates a copy of the given box.
      Parameters:
        `b` - bounding box to copy

    - #### BoundingBox

          public BoundingBox​(Point3 p)

      Creates a bounding box containing only the specified point.
      Parameters:
        `p` - point to include

    - #### BoundingBox

          public BoundingBox​(float x,
                             float y,
                             float z)

      Creates a bounding box containing only the specified point.
      Parameters:
        `x` - x coordinate of the point to include
        `y` - y coordinate of the point to include
        `z` - z coordinate of the point to include

    - #### BoundingBox

          public BoundingBox​(float size)

      Creates a bounding box centered around the origin.
      Parameters:
        `size` - half edge length of the bounding box

  - ### Method Detail

    - #### getMinimum

          public final Point3 getMinimum()

      Gets the minimum corner of the box. That is the corner of smallest coordinates on each axis. Note that the returned reference is not cloned for efficiency purposes so care must be taken not to change the coordinates of the point.
      Returns:
        a reference to the minimum corner

    - #### getMaximum

          public final Point3 getMaximum()

      Gets the maximum corner of the box. That is the corner of largest coordinates on each axis. Note that the returned reference is not cloned for efficiency purposes so care must be taken not to change the coordinates of the point.
      Returns:
        a reference to the maximum corner

    - #### getCenter

          public final Point3 getCenter()

      Gets the center of the box, computed as (min + max) / 2.
      Returns:
        a reference to the center of the box

    - #### getCorner

          public final Point3 getCorner​(int i)

      Gets a corner of the bounding box. The index scheme uses the binary representation of the index to decide which corner to return. Corner 0 is equivalent to the minimum and corner 7 is equivalent to the maximum.
      Parameters:
        `i` - a corner index, from 0 to 7
      Returns:
        the corresponding corner

    - #### getBound

          public final float getBound​(int i)

      Gets a specific coordinate of the surface's bounding box.
      Parameters:
        `i` - index of a side from 0 to 5
      Returns:
        value of the request bounding box side

    - #### getExtents

          public final Vector3 getExtents()

      Gets the extents vector for the box. This vector is computed as (max - min). Its coordinates are always positive and represent the dimensions of the box along the three axes.
      Returns:
        a refreence to the extent vector
      See Also:
        `Vector3.length()`

    - #### getArea

          public final float getArea()

      Gets the surface area of the box.
      Returns:
        surface area

    - #### getVolume

          public final float getVolume()

      Gets the box's volume
      Returns:
        volume

    - #### enlargeUlps

          public final void enlargeUlps()

      Enlarge the bounding box by the minimum possible amount to avoid numeric precision related problems.

    - #### isEmpty

          public final boolean isEmpty()

      Returns `true` when the box has just been initialized, and is still empty. This method might also return true if the state of the box becomes inconsistent and some component of the minimum corner is larger than the corresponding coordinate of the maximum corner.
      Returns:
        `true` if the box is empty, `false` otherwise

    - #### intersects

          public final boolean intersects​(BoundingBox b)

      Returns `true` if the specified bounding box intersects this one. The boxes are treated as volumes, so a box inside another will return true. Returns `false` if the parameter is `null`.
      Parameters:
        `b` - box to be tested for intersection
      Returns:
        `true` if the boxes overlap, `false` otherwise

    - #### contains

          public final boolean contains​(Point3 p)

      Checks to see if the specified `point`is inside the volume defined by this box. Returns `false` if the parameter is `null`.
      Parameters:
        `p` - point to be tested for containment
      Returns:
        `true` if the point is inside the box, `false` otherwise

    - #### contains

          public final boolean contains​(float x,
                                        float y,
                                        float z)

      Check to see if the specified point is inside the volume defined by this box.
      Parameters:
        `x` - x coordinate of the point to be tested
        `y` - y coordinate of the point to be tested
        `z` - z coordinate of the point to be tested
      Returns:
        `true` if the point is inside the box, `false` otherwise

    - #### include

          public final void include​(Point3 p)

      Changes the extents of the box as needed to include the given `point`into this box. Does nothing if the parameter is `null`.
      Parameters:
        `p` - point to be included

    - #### include

          public final void include​(float x,
                                    float y,
                                    float z)

      Changes the extents of the box as needed to include the given point into this box.
      Parameters:
        `x` - x coordinate of the point
        `y` - y coordinate of the point
        `z` - z coordinate of the point

    - #### include

          public final void include​(BoundingBox b)

      Changes the extents of the box as needed to include the given box into this box. Does nothing if the parameter is `null`.
      Parameters:
        `b` - box to be included

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`