OptionalonOptional 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.
Allocates a new vector with the same components. The clone has no change hook. This is the only allocating method on the type (§7b).
Copies the components of v into this vector. The change hook is not copied.
Component-wise approximate equality: true when every component differs by
at most epsilon (absolute tolerance).
Euclidean length.
Squared length. Preferred over Vector2.length for comparisons.
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.
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:
0 (components below
about 1.57e-162) takes the zero-length branch, so the vector is left
unchanged and non-unit.1.3407807929942597e+154 squares
to Infinity, so the reciprocal is 0 and this vector becomes (0, 0).NaN in that slot and
0 in the other; a NaN component leaves the vector untouched, because
NaN > 0 is false.Multiplies both components by the scalar s.
Sets both components.
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) andequalsApproxnever allocate and never mutate.Change notification (plan D3): every mutator invokes Vector2.onChanged after writing, which lets owners such as
Transformbump theirversionwhen a member vector is mutated through a method (§7). Direct field writes (v.x = 1) bypass the hook by design and require an explicitmarkDirty()on the owner.