Switch norm and normalized again

This commit is contained in:
ffrostfall 2024-05-13 18:52:16 -04:00 committed by GitHub
parent 364d2be862
commit ba2f90e679
Signed by: DevComp
GPG key ID: B5690EEEBB952194

View file

@ -28,7 +28,7 @@ Due to the common usage of vectors, vector creation should be ergonomic. Therefo
Calculates the magnitude of a given vector. Calculates the magnitude of a given vector.
`vector.norm(vec: vector): vector` `vector.normalized(vec: vector): vector`
Returns the normalized version (aka unit vector) of a given vector. If a zero vector is passed, return `0`. `vector(0, 0, 0):normalized()` should return zero. Returns the normalized version (aka unit vector) of a given vector. If a zero vector is passed, return `0`. `vector(0, 0, 0):normalized()` should return zero.
@ -109,5 +109,3 @@ Another alternative to vector creation is special syntax for creating buffers, s
Instead of `vector.magnitude`, the magnitude could be derived from the vector's coordinates themselves, and be accessed by a property instead of a function. There is a downside to this: all current properties of vectors are hard-coded to the VM, so any new property to vectors requires a lot of additional complexity & changes to the VM to allow for this. A library function, however, would be trivial. An easy and quick workaround to the verbosity would be at the runtime/C API level. It's trivial to set the metatable of vectors to be the vector library: this allows for `vec:magnitude()` without much issue. Instead of `vector.magnitude`, the magnitude could be derived from the vector's coordinates themselves, and be accessed by a property instead of a function. There is a downside to this: all current properties of vectors are hard-coded to the VM, so any new property to vectors requires a lot of additional complexity & changes to the VM to allow for this. A library function, however, would be trivial. An easy and quick workaround to the verbosity would be at the runtime/C API level. It's trivial to set the metatable of vectors to be the vector library: this allows for `vec:magnitude()` without much issue.
Instead of ignoring the 4th dimension in `vector.cross`, the function could be disabled when four-dimensional vectors are enabled. Instead of ignoring the 4th dimension in `vector.cross`, the function could be disabled when four-dimensional vectors are enabled.
While "norm" is the proper math term for a normalized vector, `vector.normalized` is more explicit to those who aren't as familiar with math terminology.