diff --git a/qw/include/mathlib.h b/qw/include/mathlib.h index 315db4c7e..da63f9541 100644 --- a/qw/include/mathlib.h +++ b/qw/include/mathlib.h @@ -44,18 +44,18 @@ extern int nanmask; #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2]) -#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];} -#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];} -#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];} +#define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} +#define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];} +#define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];} /* * VectorDistance, the distance between two points. * Yes, this is the same as sqrt(VectorSubtract then DotProduct), * however that way would involve more vars, this is cheaper. */ -#define VectorDistance_fast(a, b) (((a[0] - b[0]) * (a[0] - b[0])) + \ - ((a[1] - b[1]) * (a[1] - b[1])) + \ - ((a[2] - b[2]) * (a[2] - b[2]))) +#define VectorDistance_fast(a, b) ((((a)[0] - (b)[0]) * ((a)[0] - (b)[0])) + \ + (((a)[1] - (b)[1]) * ((a)[1] - (b)[1])) + \ + (((a)[2] - (b)[2]) * ((a)[2] - (b)[2]))) #define VectorDistance(a, b) sqrt(VectorDistance_fast(a, b))