Browse Source

Relaxed vector equality margin of error a little bit, hopefully leading to less instances of faces not being found for a given point

master
Nico de Poel 3 years ago
parent
commit
ca08893253
  1. 6
      bsp.h
  2. 18
      common.h

6
bsp.h

@ -335,7 +335,7 @@ typedef struct World
const plane_t* plane = &planes[face->plane_id];
// Check if the point lies on the face's plane (it's not strictly necessary to do this, but this check makes the whole function a lot faster)
if (fabs(plane->pointDistance(point)) > 0.001)
if (fabs(plane->pointDistance(point)) > 0.01)
continue;
// Check if the point is contained within the face's polygon
@ -363,7 +363,7 @@ typedef struct World
double m0 = p0.magnitude();
double m1 = p1.magnitude();
if ((m0 * m1) <= 0.001)
if ((m0 * m1) <= 0.01)
{
// Point is on one of the vertices
outFaces.push_back(face);
@ -375,7 +375,7 @@ typedef struct World
}
// If the point is inside the polygon, then the sum of all the above angles will be exactly 360 degrees
if (fabs(2 * M_PI - angleSum) <= 0.001)
if (fabs(2 * M_PI - angleSum) <= 0.01)
outFaces.push_back(face);
}

18
common.h

@ -69,6 +69,14 @@ typedef struct Vec3 // Vector or Position
return (double)x * x + (double)y * y + (double)z * z;
}
double longestElement() const
{
double longest = fabs(x);
if (fabs(y) > longest) longest = fabs(y);
if (fabs(z) > longest) longest = fabs(z);
return longest;
}
Vec3 normalized() const
{
double invMag = 1.0 / magnitude();
@ -138,15 +146,15 @@ template<> struct std::hash<Vec3>
static bool operator==(const Vec3& lhs, const Vec3& rhs)
{
return
fabs(rhs.x - lhs.x) < 0.001 &&
fabs(rhs.y - lhs.y) < 0.001 &&
fabs(rhs.z - lhs.z) < 0.001;
fabs(rhs.x - lhs.x) < 0.01 &&
fabs(rhs.y - lhs.y) < 0.01 &&
fabs(rhs.z - lhs.z) < 0.01;
}
static bool operator<(const Vec3& lhs, const Vec3& rhs)
{
if (fabs(rhs.x - lhs.x) < 0.001)
if (fabs(rhs.y - lhs.y) < 0.001)
if (fabs(rhs.x - lhs.x) < 0.01)
if (fabs(rhs.y - lhs.y) < 0.01)
return lhs.z < rhs.z;
else
return lhs.y < rhs.y;

Loading…
Cancel
Save