X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=src%2Fvg%2Fvg_m.h;h=8e49fe55e330f4adb99d2291ae552c56fbf55274;hb=3dd767bb10e6fee9cbffeb185d1a9685810c17b5;hp=0736752364113b85a711349926d3df5208e22f2a;hpb=a83978cdbdf393dc37362bff71d828b9b00c6879;p=vg.git diff --git a/src/vg/vg_m.h b/src/vg/vg_m.h index 0736752..8e49fe5 100644 --- a/src/vg/vg_m.h +++ b/src/vg/vg_m.h @@ -188,7 +188,14 @@ static inline void v2_lerp( v2f a, v2f b, float t, v2f d ) static inline void v2_normalize( v2f a ) { - v2_muls( a, 1.f / v2_length( a ), a ); + v2_muls( a, 1.0f / v2_length( a ), a ); +} + +static void v2_normalize_clamp( v2f a ) +{ + float l2 = v2_length2( a ); + if( l2 > 1.0f ) + v2_muls( a, 1.0f/sqrtf(l2), a ); } static inline void v2_floor( v2f a, v2f b )