#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
#define invpow(base,number) (log(number) / log(base))
-#define bit2i(n) (((n & 0x55555555) != 0 ? 1 : 0) | ((n & 0x66666666) !=0 ? 2 : 0) | ((n & 0x78787878) != 0 ? 4 : 0) | ((n & 0x7F807F80) != 0 ? 8 : 0) | ((n & 0x7FFF8000) != 0 ? 16 : 0))
-#define log2i(n) (((n & 0xAAAAAAAA) != 0 ? 1 : 0) | ((n & 0xCCCCCCCC) != 0 ? 2 : 0) | ((n & 0xF0F0F0F0) != 0 ? 4 : 0) | ((n & 0xFF00FF00) != 0 ? 8 : 0) | ((n & 0xFFFF0000) != 0 ? 16 : 0))
+#define log2i(n) ((((n) & 0xAAAAAAAA) != 0 ? 1 : 0) | (((n) & 0xCCCCCCCC) != 0 ? 2 : 0) | (((n) & 0xF0F0F0F0) != 0 ? 4 : 0) | (((n) & 0xFF00FF00) != 0 ? 8 : 0) | (((n) & 0xFFFF0000) != 0 ? 16 : 0))
+#define bit2i(n) log2i((n) << 1)
#define DEG2RAD(a) ((a) * ((float) M_PI / 180.0f))
#define RAD2DEG(a) ((a) * (180.0f / (float) M_PI))
void VectorVectorsDouble(const double *forward, double *right, double *up);
void PlaneClassify(struct mplane_s *p);
-int BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p);
+int BoxOnPlaneSide(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p);
+int BoxOnPlaneSide_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, const vec_t dist);
+void BoxPlaneCorners(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec3_t outnear, vec3_t outfar);
+void BoxPlaneCorners_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec3_t outnear, vec3_t outfar);
+void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec_t *outnear, vec_t *outfar);
+void BoxPlaneCornerDistances_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec_t *outnear, vec_t *outfar);
#define PlaneDist(point,plane) ((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal))
#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist)