mirror of
https://github.com/ZDoom/zdbsp.git
synced 2025-03-13 22:32:22 +00:00
- Nodebuilding is a little faster if we inline PointOnSide.
SVN r171 (trunk)
This commit is contained in:
parent
4ce1df4aeb
commit
0d37e97f13
2 changed files with 34 additions and 32 deletions
|
@ -29,10 +29,6 @@
|
|||
#include "nodebuild.h"
|
||||
#include "templates.h"
|
||||
|
||||
// Points within this distance of a line will be considered on the line.
|
||||
// Units are in fixed_ts.
|
||||
const double SIDE_EPSILON = 6.5536;
|
||||
|
||||
#define Printf printf
|
||||
#define STACK_ARGS
|
||||
|
||||
|
@ -1151,33 +1147,6 @@ double FNodeBuilder::InterceptVector (const node_t &splitter, const FPrivSeg &se
|
|||
return num / den;
|
||||
}
|
||||
|
||||
int FNodeBuilder::PointOnSide (int x, int y, int x1, int y1, int dx, int dy)
|
||||
{
|
||||
// For most cases, a simple dot product is enough.
|
||||
double d_dx = double(dx);
|
||||
double d_dy = double(dy);
|
||||
double d_x = double(x);
|
||||
double d_y = double(y);
|
||||
double d_x1 = double(x1);
|
||||
double d_y1 = double(y1);
|
||||
|
||||
double s_num = (d_y1-d_y)*d_dx - (d_x1-d_x)*d_dy;
|
||||
|
||||
if (fabs(s_num) < 17179869184.f) // 4<<32
|
||||
{
|
||||
// Either the point is very near the line, or the segment defining
|
||||
// the line is very short: Do a more expensive test to determine
|
||||
// just how far from the line the point is.
|
||||
double l = d_dx*d_dx + d_dy*d_dy; // double l = sqrt(d_dx*d_dx+d_dy*d_dy);
|
||||
double dist = s_num * s_num / l; // double dist = fabs(s_num)/l;
|
||||
if (dist < SIDE_EPSILON*SIDE_EPSILON) // if (dist < SIDE_EPSILON)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return s_num > 0.0 ? -1 : 1;
|
||||
}
|
||||
|
||||
void FNodeBuilder::PrintSet (int l, DWORD set)
|
||||
{
|
||||
Printf ("set %d:\n", l);
|
||||
|
|
35
nodebuild.h
35
nodebuild.h
|
@ -1,3 +1,4 @@
|
|||
#include <math.h>
|
||||
#include "doomdata.h"
|
||||
#include "workdata.h"
|
||||
#include "tarray.h"
|
||||
|
@ -150,7 +151,7 @@ public:
|
|||
// == 0 : on line
|
||||
// > 0 : behind line
|
||||
|
||||
static int PointOnSide (int x, int y, int x1, int y1, int dx, int dy);
|
||||
static inline int PointOnSide (int x, int y, int x1, int y1, int dx, int dy);
|
||||
|
||||
private:
|
||||
FVertexMap *VertexMap;
|
||||
|
@ -225,3 +226,35 @@ private:
|
|||
|
||||
void PrintSet (int l, DWORD set);
|
||||
};
|
||||
|
||||
// Points within this distance of a line will be considered on the line.
|
||||
// Units are in fixed_ts.
|
||||
const double SIDE_EPSILON = 6.5536;
|
||||
|
||||
inline int FNodeBuilder::PointOnSide (int x, int y, int x1, int y1, int dx, int dy)
|
||||
{
|
||||
// For most cases, a simple dot product is enough.
|
||||
double d_dx = double(dx);
|
||||
double d_dy = double(dy);
|
||||
double d_x = double(x);
|
||||
double d_y = double(y);
|
||||
double d_x1 = double(x1);
|
||||
double d_y1 = double(y1);
|
||||
|
||||
double s_num = (d_y1-d_y)*d_dx - (d_x1-d_x)*d_dy;
|
||||
|
||||
if (fabs(s_num) < 17179869184.f) // 4<<32
|
||||
{
|
||||
// Either the point is very near the line, or the segment defining
|
||||
// the line is very short: Do a more expensive test to determine
|
||||
// just how far from the line the point is.
|
||||
double l = d_dx*d_dx + d_dy*d_dy; // double l = sqrt(d_dx*d_dx+d_dy*d_dy);
|
||||
double dist = s_num * s_num / l; // double dist = fabs(s_num)/l;
|
||||
if (dist < SIDE_EPSILON*SIDE_EPSILON) // if (dist < SIDE_EPSILON)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return s_num > 0.0 ? -1 : 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue