all: make VectorCompare take an explicit epsilon

This commit is contained in:
Eric Wasylishen 2017-04-26 14:20:45 -06:00
parent 15cc98eb27
commit 902c45c946
12 changed files with 21 additions and 21 deletions

View File

@ -32,12 +32,12 @@ using namespace polylib;
const vec3_t vec3_origin = { 0, 0, 0 }; const vec3_t vec3_origin = { 0, 0, 0 };
qboolean qboolean
VectorCompare(const vec3_t v1, const vec3_t v2) VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon)
{ {
int i; int i;
for (i = 0; i < 3; 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 false;
return true; return true;

View File

@ -61,7 +61,7 @@ extern const vec3_t vec3_origin;
#define ZERO_TRI_AREA_EPSILON 0.05f #define ZERO_TRI_AREA_EPSILON 0.05f
#define POINT_EQUAL_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 static inline bool
GLMVectorCompare(const qvec3f &v1, const qvec3f &v2) GLMVectorCompare(const qvec3f &v1, const qvec3f &v2)

View File

@ -33,7 +33,7 @@ typedef vec_t vec3_t[3];
extern const vec3_t vec3_origin; 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); vec_t Q_rint(vec_t in);
extern vec_t DotProduct(const vec3_t v1, const vec3_t v2); extern vec_t DotProduct(const vec3_t v1, const vec3_t v2);

View File

@ -661,7 +661,7 @@ static void CheckLitNeeded(const globalconfig_t &cfg)
// check lights // check lights
for (const auto &light : GetLights()) { for (const auto &light : GetLights()) {
if (!VectorCompare(white, *light.color.vec3Value())) { if (!VectorCompare(white, *light.color.vec3Value(), EQUAL_EPSILON)) {
SetLitNeeded(); SetLitNeeded();
return; return;
} }
@ -669,11 +669,11 @@ static void CheckLitNeeded(const globalconfig_t &cfg)
// check global settings // check global settings
if (cfg.bouncecolorscale.floatValue() != 0 || if (cfg.bouncecolorscale.floatValue() != 0 ||
!VectorCompare(*cfg.minlight_color.vec3Value(), white) || !VectorCompare(*cfg.minlight_color.vec3Value(), white, EQUAL_EPSILON) ||
!VectorCompare(*cfg.sunlight_color.vec3Value(), white) || !VectorCompare(*cfg.sunlight_color.vec3Value(), white, EQUAL_EPSILON) ||
!VectorCompare(*cfg.sun2_color.vec3Value(), white) || !VectorCompare(*cfg.sun2_color.vec3Value(), white, EQUAL_EPSILON) ||
!VectorCompare(*cfg.sunlight2_color.vec3Value(), white) || !VectorCompare(*cfg.sunlight2_color.vec3Value(), white, EQUAL_EPSILON) ||
!VectorCompare(*cfg.sunlight3_color.vec3Value(), white)) { !VectorCompare(*cfg.sunlight3_color.vec3Value(), white, EQUAL_EPSILON)) {
SetLitNeeded(); SetLitNeeded();
return; return;
} }

View File

@ -706,7 +706,7 @@ Lightsurf_Init(const modelinfo_t *modelinfo, const bsp2_dface_t *face,
static_cast<float>((extended_flags & TEX_MINLIGHT_COLOR_R_MASK) >> TEX_MINLIGHT_COLOR_R_SHIFT), static_cast<float>((extended_flags & TEX_MINLIGHT_COLOR_R_MASK) >> TEX_MINLIGHT_COLOR_R_SHIFT),
static_cast<float>((extended_flags & TEX_MINLIGHT_COLOR_G_MASK) >> TEX_MINLIGHT_COLOR_G_SHIFT), static_cast<float>((extended_flags & TEX_MINLIGHT_COLOR_G_MASK) >> TEX_MINLIGHT_COLOR_G_SHIFT),
static_cast<float>((extended_flags & TEX_MINLIGHT_COLOR_B_MASK) >> TEX_MINLIGHT_COLOR_B_SHIFT)}; static_cast<float>((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); VectorSet(extended_mincolor, 255, 255, 255);
} }
VectorCopy(extended_mincolor, lightsurf->minlight_color); VectorCopy(extended_mincolor, lightsurf->minlight_color);

View File

@ -518,7 +518,7 @@ AddBrushPlane(hullbrush_t *hullbrush, plane_t *plane)
mapface = hullbrush->faces; mapface = hullbrush->faces;
for (i = 0; i < hullbrush->numfaces; i++, mapface++) { 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) fabs(mapface->plane.dist - plane->dist) < ON_EPSILON)
return; return;
} }
@ -604,7 +604,7 @@ AddHullPoint(hullbrush_t *hullbrush, vec3_t p, vec3_t hull_size[2])
int x, y, z; int x, y, z;
for (i = 0; i < hullbrush->numpoints; i++) for (i = 0; i < hullbrush->numpoints; i++)
if (VectorCompare(p, hullbrush->points[i])) if (VectorCompare(p, hullbrush->points[i], EQUAL_EPSILON))
return i; return i;
if (hullbrush->numpoints == MAX_HULL_POINTS) if (hullbrush->numpoints == MAX_HULL_POINTS)

View File

@ -315,12 +315,12 @@ FindTexinfoEnt(mtexinfo_t *texinfo, const mapentity_t *entity)
vec3_t mincolor {0.0, 0.0, 0.0}; vec3_t mincolor {0.0, 0.0, 0.0};
GetVectorForKey(entity, "_mincolor", mincolor); GetVectorForKey(entity, "_mincolor", mincolor);
if (VectorCompare(vec3_origin, mincolor)) { if (VectorCompare(vec3_origin, mincolor, EQUAL_EPSILON)) {
GetVectorForKey(entity, "_minlight_color", mincolor); GetVectorForKey(entity, "_minlight_color", mincolor);
} }
normalize_color_format(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 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 g_byte = qmax(0, qmin(255, (int)rint(mincolor[1])));
const uint64_t b_byte = qmax(0, qmin(255, (int)rint(mincolor[2]))); const uint64_t b_byte = qmax(0, qmin(255, (int)rint(mincolor[2])));

View File

@ -42,12 +42,12 @@ VectorLength(const vec3_t v)
} }
bool bool
VectorCompare(const vec3_t v1, const vec3_t v2) VectorCompare(const vec3_t v1, const vec3_t v2, vec_t epsilon)
{ {
int i; int i;
for (i = 0; i < 3; 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 false;
return true; return true;

View File

@ -40,7 +40,7 @@ CheckColinear(face_t *f)
VectorSubtract(f->w.points[j], f->w.points[i], v2); VectorSubtract(f->w.points[j], f->w.points[i], v2);
VectorNormalize(v2); VectorNormalize(v2);
if (VectorCompare(v1, v2)) if (VectorCompare(v1, v2, EQUAL_EPSILON))
Error("Colinear edge (%s)", __func__); Error("Colinear edge (%s)", __func__);
} }
} }

View File

@ -472,7 +472,7 @@ FillOutside(node_t *node, const int hullnum, const int numportals)
inside = false; inside = false;
for (i = 1; i < map.numentities(); i++) { for (i = 1; i < map.numentities(); i++) {
entity = &map.entities.at(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)) if (PlaceOccupant(i, entity->origin, node))
inside = true; inside = true;
} }

View File

@ -538,7 +538,7 @@ DividePlane(surface_t *in, plane_t *split, surface_t **front,
*front = *back = NULL; *front = *back = NULL;
// parallel case is easy // parallel case is easy
if (VectorCompare(inplane->normal, split->normal)) { if (VectorCompare(inplane->normal, split->normal, EQUAL_EPSILON)) {
// check for exactly on node // check for exactly on node
if (inplane->dist == split->dist) { if (inplane->dist == split->dist) {
facet = in->faces; facet = in->faces;

View File

@ -228,7 +228,7 @@ RecursiveLeafFlow(int leafnum, threaddata_t *thread, pstack_t *prevstack)
VectorSubtract(vec3_origin, p->plane.normal, backplane.normal); VectorSubtract(vec3_origin, p->plane.normal, backplane.normal);
backplane.dist = -p->plane.dist; 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 continue; // can't go out a coplanar face
c_portalcheck++; c_portalcheck++;