diff --git a/common/mathlib.cc b/common/mathlib.cc index eda282ba..1a8ffee0 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -32,12 +32,12 @@ using namespace polylib; const vec3_t vec3_origin = { 0, 0, 0 }; qboolean -VectorCompare(const vec3_t v1, const vec3_t v2) +VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon) { int i; for (i = 0; i < 3; i++) - if (fabs(v1[i] - v2[i]) > EQUAL_EPSILON) + if (fabs(v1[i] - v2[i]) > epsilon) return false; return true; diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index 852e2fb8..fde0e58a 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -61,7 +61,7 @@ extern const vec3_t vec3_origin; #define ZERO_TRI_AREA_EPSILON 0.05f #define POINT_EQUAL_EPSILON 0.05f -qboolean VectorCompare(const vec3_t v1, const vec3_t v2); +qboolean VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon); static inline bool GLMVectorCompare(const qvec3f &v1, const qvec3f &v2) diff --git a/include/qbsp/mathlib.hh b/include/qbsp/mathlib.hh index eebc0468..1dd92fa7 100644 --- a/include/qbsp/mathlib.hh +++ b/include/qbsp/mathlib.hh @@ -33,7 +33,7 @@ typedef vec_t vec3_t[3]; extern const vec3_t vec3_origin; -bool VectorCompare(const vec3_t v1, const vec3_t v2); +bool VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon); vec_t Q_rint(vec_t in); extern vec_t DotProduct(const vec3_t v1, const vec3_t v2); diff --git a/light/light.cc b/light/light.cc index e38b74e7..077f65ed 100644 --- a/light/light.cc +++ b/light/light.cc @@ -661,7 +661,7 @@ static void CheckLitNeeded(const globalconfig_t &cfg) // check lights for (const auto &light : GetLights()) { - if (!VectorCompare(white, *light.color.vec3Value())) { + if (!VectorCompare(white, *light.color.vec3Value(), EQUAL_EPSILON)) { SetLitNeeded(); return; } @@ -669,11 +669,11 @@ static void CheckLitNeeded(const globalconfig_t &cfg) // check global settings if (cfg.bouncecolorscale.floatValue() != 0 || - !VectorCompare(*cfg.minlight_color.vec3Value(), white) || - !VectorCompare(*cfg.sunlight_color.vec3Value(), white) || - !VectorCompare(*cfg.sun2_color.vec3Value(), white) || - !VectorCompare(*cfg.sunlight2_color.vec3Value(), white) || - !VectorCompare(*cfg.sunlight3_color.vec3Value(), white)) { + !VectorCompare(*cfg.minlight_color.vec3Value(), white, EQUAL_EPSILON) || + !VectorCompare(*cfg.sunlight_color.vec3Value(), white, EQUAL_EPSILON) || + !VectorCompare(*cfg.sun2_color.vec3Value(), white, EQUAL_EPSILON) || + !VectorCompare(*cfg.sunlight2_color.vec3Value(), white, EQUAL_EPSILON) || + !VectorCompare(*cfg.sunlight3_color.vec3Value(), white, EQUAL_EPSILON)) { SetLitNeeded(); return; } diff --git a/light/ltface.cc b/light/ltface.cc index 8e2489c3..4542a108 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -706,7 +706,7 @@ Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face, static_cast((extended_flags & TEX_MINLIGHT_COLOR_R_MASK) >> TEX_MINLIGHT_COLOR_R_SHIFT), static_cast((extended_flags & TEX_MINLIGHT_COLOR_G_MASK) >> TEX_MINLIGHT_COLOR_G_SHIFT), static_cast((extended_flags & TEX_MINLIGHT_COLOR_B_MASK) >> TEX_MINLIGHT_COLOR_B_SHIFT)}; - if (lightsurf->minlight > 0 && VectorCompare(extended_mincolor, vec3_origin)) { + if (lightsurf->minlight > 0 && VectorCompare(extended_mincolor, vec3_origin, EQUAL_EPSILON)) { VectorSet(extended_mincolor, 255, 255, 255); } VectorCopy(extended_mincolor, lightsurf->minlight_color); diff --git a/qbsp/brush.cc b/qbsp/brush.cc index b6e4e31c..0b4391f4 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -518,7 +518,7 @@ AddBrushPlane(hullbrush_t *hullbrush, plane_t *plane) mapface = hullbrush->faces; for (i = 0; i < hullbrush->numfaces; i++, mapface++) { - if (VectorCompare(mapface->plane.normal, plane->normal) && + if (VectorCompare(mapface->plane.normal, plane->normal, EQUAL_EPSILON) && fabs(mapface->plane.dist - plane->dist) < ON_EPSILON) return; } @@ -604,7 +604,7 @@ AddHullPoint(hullbrush_t *hullbrush, vec3_t p, vec3_t hull_size[2]) int x, y, z; for (i = 0; i < hullbrush->numpoints; i++) - if (VectorCompare(p, hullbrush->points[i])) + if (VectorCompare(p, hullbrush->points[i], EQUAL_EPSILON)) return i; if (hullbrush->numpoints == MAX_HULL_POINTS) diff --git a/qbsp/map.cc b/qbsp/map.cc index 013daa1b..69131eb9 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -315,12 +315,12 @@ FindTexinfoEnt(mtexinfo_t *texinfo, const mapentity_t *entity) vec3_t mincolor {0.0, 0.0, 0.0}; GetVectorForKey(entity, "_mincolor", mincolor); - if (VectorCompare(vec3_origin, mincolor)) { + if (VectorCompare(vec3_origin, mincolor, EQUAL_EPSILON)) { GetVectorForKey(entity, "_minlight_color", mincolor); } normalize_color_format(mincolor); - if (!VectorCompare(vec3_origin, mincolor)) { + if (!VectorCompare(vec3_origin, mincolor, EQUAL_EPSILON)) { const uint64_t r_byte = qmax(0, qmin(255, (int)rint(mincolor[0]))); const uint64_t g_byte = qmax(0, qmin(255, (int)rint(mincolor[1]))); const uint64_t b_byte = qmax(0, qmin(255, (int)rint(mincolor[2]))); diff --git a/qbsp/mathlib.cc b/qbsp/mathlib.cc index e9c960a8..00a0c0cd 100644 --- a/qbsp/mathlib.cc +++ b/qbsp/mathlib.cc @@ -42,12 +42,12 @@ VectorLength(const vec3_t v) } bool -VectorCompare(const vec3_t v1, const vec3_t v2) +VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon) { int i; for (i = 0; i < 3; i++) - if (fabs(v1[i] - v2[i]) > EQUAL_EPSILON) + if (fabs(v1[i] - v2[i]) > epsilon) return false; return true; diff --git a/qbsp/merge.cc b/qbsp/merge.cc index dc303613..b6f1d1fc 100644 --- a/qbsp/merge.cc +++ b/qbsp/merge.cc @@ -40,7 +40,7 @@ CheckColinear(face_t *f) VectorSubtract(f->w.points[j], f->w.points[i], v2); VectorNormalize(v2); - if (VectorCompare(v1, v2)) + if (VectorCompare(v1, v2, EQUAL_EPSILON)) Error("Colinear edge (%s)", __func__); } } diff --git a/qbsp/outside.cc b/qbsp/outside.cc index 5c456b45..7c56b3e6 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -472,7 +472,7 @@ FillOutside(node_t *node, const int hullnum, const int numportals) inside = false; for (i = 1; i < map.numentities(); i++) { entity = &map.entities.at(i); - if (!VectorCompare(entity->origin, vec3_origin)) { + if (!VectorCompare(entity->origin, vec3_origin, EQUAL_EPSILON)) { if (PlaceOccupant(i, entity->origin, node)) inside = true; } diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index d011089a..8943c5db 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -538,7 +538,7 @@ DividePlane(surface_t *in, plane_t *split, surface_t **front, *front = *back = NULL; // parallel case is easy - if (VectorCompare(inplane->normal, split->normal)) { + if (VectorCompare(inplane->normal, split->normal, EQUAL_EPSILON)) { // check for exactly on node if (inplane->dist == split->dist) { facet = in->faces; diff --git a/vis/flow.cc b/vis/flow.cc index c44c4636..d5060790 100644 --- a/vis/flow.cc +++ b/vis/flow.cc @@ -228,7 +228,7 @@ RecursiveLeafFlow(int leafnum, threaddata_t *thread, pstack_t *prevstack) VectorSubtract(vec3_origin, p->plane.normal, backplane.normal); backplane.dist = -p->plane.dist; - if (VectorCompare(prevstack->portalplane.normal, backplane.normal)) + if (VectorCompare(prevstack->portalplane.normal, backplane.normal, EQUAL_EPSILON)) continue; // can't go out a coplanar face c_portalcheck++;