# HG changeset patch # User sam # Date 1725119853 -25200 # Node ID 55c7aac521e3b704590ab57484c380608665e4af # Parent 6e94b1717d3a55ca83e03936fd40ee57307ff594 add: clamp operation for vectors diff -r 6e94b1717d3a -r 55c7aac521e3 semicongine/core/vector.nim --- a/semicongine/core/vector.nim Tue Aug 27 23:19:00 2024 +0700 +++ b/semicongine/core/vector.nim Sat Aug 31 22:57:33 2024 +0700 @@ -269,6 +269,34 @@ func ceil*[T](vec: TVec4[T]): auto = TVec4([ceil(vec[0]), ceil(vec[1]), ceil(vec[2]), ceil(vec[3])]) +func clamp*[T, S: SomeNumber](vec: TVec1[T], a, b: S): auto = + TVec1([clamp(vec[0], a, b)]) +func clamp*[T, S: SomeNumber](vec: TVec2[T], a, b: S): auto = + TVec2([clamp(vec[0], a, b), clamp(vec[1], a, b)]) +func clamp*[T, S: SomeNumber](vec: TVec3[T], a, b: S): auto = + TVec3([clamp(vec[0], a, b), clamp(vec[1], a, b), clamp(vec[2], a, b)]) +func clamp*[T, S: SomeNumber](vec: TVec4[T], a, b: S): auto = + TVec4( + [clamp(vec[0], a, b), clamp(vec[1], a, b), clamp(vec[2], a, b), clamp(vec[3], a, b)] + ) +func clamp*[T, S: SomeNumber](vec: TVec1[T], a, b: TVec1[S]): auto = + TVec1[T]([clamp(vec[0], a[0], b[0])]) +func clamp*[T, S: SomeNumber](vec: TVec2[T], a, b: TVec2[S]): auto = + TVec2[T]([clamp(vec[0], a[0], b[0]), clamp(vec[1], a[1], b[1])]) +func clamp*[T, S: SomeNumber](vec: TVec3[T], a, b: TVec3[S]): auto = + TVec3[T]( + [clamp(vec[0], a[0], b[0]), clamp(vec[1], a[1], b[1]), clamp(vec[2], a[2], b[2])] + ) +func clamp*[T, S: SomeNumber](vec: TVec4[T], a, b: TVec4[S]): auto = + TVec4[T]( + [ + clamp(vec[0], a[0], b[0]), + clamp(vec[1], a[1], b[1]), + clamp(vec[2], a[2], b[2]), + clamp(vec[3], a[3], b[3]), + ] + ) + func manhattan*(vec: TVec1): auto = abs(vec[0]) func manhattan*(vec: TVec2): auto =