X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg_m.h;h=9e70c9290ca48d859df9f9c054065c506040df23;hb=edd5498fac470c6a98e45ab326c2bf2e2a552664;hp=690683710d816a9bec4ec8444b29d54b58b9e007;hpb=95036f2af35f1b5af66bfcd90811f7c3c4bebf78;p=fishladder.git diff --git a/vg/vg_m.h b/vg/vg_m.h index 6906837..9e70c92 100644 --- a/vg/vg_m.h +++ b/vg/vg_m.h @@ -17,6 +17,11 @@ static inline float vg_maxf( float a, float b ) return a > b? a: b; } +static inline float vg_clampf( float a, float min, float max ) +{ + return vg_minf( max, vg_maxf( a, min ) ); +} + #define VG_MIN( A, B ) ((A)<(B)?(A):(B)) #define VG_MAX( A, B ) ((A)>(B)?(A):(B)) @@ -98,6 +103,28 @@ static inline void v2_muladds( v2f a, v2f b, float s, v2f d ) d[0] = a[0]+b[0]*s; d[1] = a[1]+b[1]*s; } +static inline float v2_length2( v2f a ) +{ + return a[0]*a[0] + a[1]*a[1]; +} + +static inline float v2_length( v2f a ) +{ + return sqrtf( v2_length2( a ) ); +} + +static inline float v2_dist2( v2f a, v2f b ) +{ + v2f delta; + v2_sub( a, b, delta ); + return v2_length2( delta ); +} + +static inline float v2_dist( v2f a, v2f b ) +{ + return sqrtf( v2_dist2( a, b ) ); +} + // Vector 3 // ==================================================================================================================