Documentation
    Preparing search index...

    Class Vector2

    Mutable two-component vector (§7b).

    Allocation policy (§7b, plan D7): instance methods that produce a "this-shaped" result mutate in place and return this; only Vector2.clone allocates. Scalar queries (dot, lengthSq, length) and equalsApprox never allocate and never mutate.

    Change notification (plan D3): every mutator invokes Vector2.onChanged after writing, which lets owners such as Transform bump their version when a member vector is mutated through a method (§7). Direct field writes (v.x = 1) bypass the hook by design and require an explicit markDirty() on the owner.

    Index
    • Parameters

      • Optionalx: number
      • Optionaly: number

      Returns Vector2

    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 Vector2.copy or Vector2.clone — the hook belongs to the owner of the instance, not to the value.

    x: number
    y: 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 Vector2

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

      Parameters

      Returns this

    • Dot product with v. Does not mutate.

      Parameters

      Returns number

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

      Parameters

      • v: Vector2
      • Optionalepsilon: number

      Returns boolean

    • Euclidean length.

      Returns number

    • Squared length. Preferred over Vector2.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, no other convention is normative): normalizing a zero-length vector leaves it at (0, 0) rather than producing NaN or throwing. There is no meaningful direction to pick, and silently poisoning a hot path with NaN is worse than a no-op. The change hook still fires, because the method completed as a mutator.

      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 this vector becomes (0, 0).
      • Non-finite input. An infinite component gives NaN in that slot and 0 in the other; a NaN component leaves the vector untouched, because NaN > 0 is false.

      Returns this

    • Multiplies both components by the scalar s.

      Parameters

      • s: number

      Returns this

    • Sets both components.

      Parameters

      • x: number
      • y: number

      Returns this

    • Subtracts v component-wise.

      Parameters

      Returns this