mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Add linalg.clamp_length(vector, max_length) -> clamped_vector
This commit is contained in:
@@ -167,6 +167,18 @@ vector_triple_product :: proc "contextless" (a, b, c: $T/[$N]$E) -> T where IS_N
|
|||||||
length :: proc{vector_length, quaternion_length}
|
length :: proc{vector_length, quaternion_length}
|
||||||
length2 :: proc{vector_length2, quaternion_length2}
|
length2 :: proc{vector_length2, quaternion_length2}
|
||||||
|
|
||||||
|
|
||||||
|
@(require_results)
|
||||||
|
clamp_length :: proc "contextless" (v: $T/[$N]$E, a: E) -> T where IS_FLOAT(E) {
|
||||||
|
if a <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
m2 := length2(v)
|
||||||
|
return v if (m2 <= a*a) else (v / sqrt(m2) * a) // returns original when m2 is 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
projection :: proc "contextless" (x, normal: $T/[$N]$E) -> T where IS_NUMERIC(E) {
|
projection :: proc "contextless" (x, normal: $T/[$N]$E) -> T where IS_NUMERIC(E) {
|
||||||
return dot(x, normal) / dot(normal, normal) * normal
|
return dot(x, normal) / dot(normal, normal) * normal
|
||||||
|
|||||||
Reference in New Issue
Block a user