Class Sphere

The Sphere implements a sphere represented by a center point and a radius. The class follows the 'copy-on-write' pattern, which means that every operation returns a copy of the sphere with updates values. It also implies that the values of the sphere cannot be directly modified.

The concept of immutability improves sharing of objects as all types in TypeScript are assigned by identity, instead of by-value (e.g. a copy) as in other programming languages like C.

Constructors

  • Parameters

    Returns Sphere

Properties

_center: Vector3
_radius: number

Accessors

  • get center(): Vector3
  • Returns Vector3

  • set center(value): void
  • Parameters

    Returns void

  • get radius(): number
  • Returns number

  • set radius(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Copies all properties defined by the prototype of Sphere from other to this instance.

    Parameters

    Returns Sphere

  • Clones this instance and returns a new Sphere with identical values.

    Returns Sphere

  • Test for intersection with a ray.

    Parameters

    • ray: Immutable<Ray>

      The ray to test for intersection.

    • discardInside: boolean

      Whether the ray should immediately return with a value of 0 if inside.

    Returns number

    The first positive intersection time along the ray, if any intersection. -1 otherwise.

  • Determines if this Sphere instance is equal to the other instance.

    Parameters

    Returns boolean

  • Determines if both Sphere instances are equal.

    Parameters

    Returns boolean