X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg_m.h;h=a0c01077048b0a5cd599f206e428b474ca3af1d9;hb=5276db4a15a6565813bdde22198f8aee4030e56f;hp=0c4ba358593af4927a59f6e6335906a5cf0e653c;hpb=c8165f11120b296045f670bbdd8e614e92b0c5e8;p=fishladder.git diff --git a/vg/vg_m.h b/vg/vg_m.h index 0c4ba35..a0c0107 100644 --- a/vg/vg_m.h +++ b/vg/vg_m.h @@ -17,6 +17,15 @@ 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)) + +// Hopefully deprecate this!! static inline int vg_min( int a, int b ) { return a < b? a: b; @@ -41,6 +50,21 @@ static inline void v2_copy( v2f a, v2f b ) b[0] = a[0]; b[1] = a[1]; } +static inline void v2i_copy( v2i a, v2i b ) +{ + b[0] = a[0]; b[1] = a[1]; +} + +static inline void v2i_add( v2i a, v2i b, v2i d ) +{ + d[0] = a[0]+b[0]; d[1] = a[1]+b[1]; +} + +static inline void v2i_sub( v2i a, v2i b, v2i d ) +{ + d[0] = a[0]-b[0]; d[1] = a[1]-b[1]; +} + static inline void v2_minv( v2f a, v2f b, v2f dest ) { dest[0] = vg_minf(a[0], b[0]); @@ -73,6 +97,12 @@ static inline void v2_muls( v2f a, float s, v2f d ) d[0] = a[0]*s; d[1] = a[1]*s; } +static inline void v2_divs( v2f a, float s, v2f d ) +{ + d[0] = a[0]/s; d[1] = a[1]/s; +} + + static inline void v2_mul( v2f a, v2f b, v2f d ) { d[0] = a[0]*b[0]; d[1] = a[1]*b[1]; @@ -83,6 +113,33 @@ static inline void v2_div( v2f a, v2f b, v2f d ) d[0] = a[0]/b[0]; d[1] = a[1]/b[1]; } +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 // ==================================================================================================================