Documentation
    Preparing search index...

    Class Vector4

    Mutable four-component vector (§7b) — homogeneous coordinates, plane equations, RGBA channels, and shader uniforms.

    Allocation policy (§7b, plan D7): instance methods that produce a "this-shaped" result mutate in place and return this; only Vector4.clone allocates. Scalar queries (dot, lengthSq, length) and equalsApprox never allocate and never mutate. All four components — w included — participate in every operation; there is no perspective divide here.

    Change notification (plan D3): every mutator invokes Vector4.onChanged after writing. Direct field writes (v.x = 1) bypass the hook by design.

    Index
    • Parameters

      • Optionalx: number
      • Optionaly: number
      • Optionalz: number
      • Optionalw: number

      Returns Vector4

    onChanged?: () => void

    Optional change hook invoked at the end of every mutator. Engine-internal: owners install it, user code normally leaves it unset. It is intentionally not copied by Vector4.copy or Vector4.clone.

    w: number
    x: number
    y: number
    z: number
    • Adds v component-wise.

      Parameters

      Returns this

    • Allocates a new vector with the same components. The clone has no change hook. This is the only allocating method on the type (§7b).

      Returns Vector4

    • Copies the components of v into this vector. The change hook is not copied.

      Parameters

      Returns this

    • Dot product with v, including w. Does not mutate.

      Parameters

      Returns number

    • Component-wise approximate equality: true when every component differs by at most epsilon (absolute tolerance).

      Parameters

      • v: Vector4
      • Optionalepsilon: number

      Returns boolean

    • Euclidean length over all four components.

      Returns number

    • Squared length. Preferred over Vector4.length for comparisons.

      Returns number

    • Moves this vector toward target by the factor t, mutating this vector. t = 0 leaves it unchanged, t = 1 makes it equal to target. Values outside [0, 1] extrapolate; no clamping is applied.

      Parameters

      Returns this

    • Scales this vector to unit length.

      Zero-length behaviour (defined here): normalizing a zero-length vector leaves it at (0, 0, 0, 0) rather than producing NaN or throwing — there is no meaningful direction to pick, and poisoning a hot path with NaN is worse than a no-op. The change hook still fires.

      Range behaviour — the guard below tests the squared length, so three ranges leave this vector non-unit and none of them reports an error (measured from a consumer seat, dogfood cycle 10); Vector3.normalize documents the same three with numbers:

      • Underflow. A squared length that rounds to 0 (components below about 1.57e-162) takes the zero-length branch, so the vector is left unchanged and non-unit.
      • Overflow. A component at or above 1.3407807929942597e+154 squares to Infinity, so the reciprocal is 0 and every component becomes 0.
      • Non-finite input. An infinite component gives NaN in that slot and 0 in the others; a NaN component leaves the vector untouched, because NaN > 0 is false.

      Returns this

    • Multiplies every component by the scalar s.

      Parameters

      • s: number

      Returns this

    • Sets all four components.

      Parameters

      • x: number
      • y: number
      • z: number
      • w: number

      Returns this

    • Subtracts v component-wise.

      Parameters

      Returns this