-
Notifications
You must be signed in to change notification settings - Fork 18
pymath.normalize_inplace
Daniel Flassig edited this page Jul 17, 2026
·
1 revision
In-place variant of pymath.normalize: scales the vector to unit length by overwriting its entries instead of allocating a new table.
v, len = pymath.normalize_inplace(v [, threshold])| Parameter | Type | Description |
|---|---|---|
v |
vector | A vector of any dimension; receives the normalized components. |
threshold |
number (optional)
|
Non-negative length at or below which the vector counts as too short. Default: an implementation defined tolerance. |
| Type | Description |
|---|---|
v |
The same table that was passed in, now of unit length (returned for convenience) — or nil if the length of v is not above the threshold. |
len |
The original length of v before normalization (only on success). |
- On failure (
nilreturned) the entries ofvare left unchanged. -
nilholes invare filled with0.0, so the vector is fully dense afterwards (also on failure). - All other guarantees of
pymath.normalizeapply: overflow-safe length computation,nilfor non-finite input, athresholdof0rejects exactly the zero vector, and the result components lie in[-1, 1].
local dir = {3, 4}
local _, len = pymath.normalize_inplace(dir)
-- dir == {0.6, 0.8}, len == 5.0
-- the nil return makes degenerate input easy to catch
if not pymath.normalize_inplace(axis) then
axis = {0, 0, 1} -- fall back to a default axis
endMinimum PYTHA Version: V27