ref: 5a0b85926a68e47864e57c7b96b858a3eec37e7e
parent: 98a0886ca839e39ec50e95220b135af3c3dc7aa7
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 05:54:23 EST 2023
finished the BSP_PointOnSide() function.
--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -156,15 +156,18 @@
int BSP_PointOnSide (seg_t * part, fixed_t x, fixed_t y)
{- fixed_t dx = part->v2->x - part->v1->x;
- fixed_t dy = part->v2->y - part->v1->y;
+ x -= part->v1->x;
+ y -= part->v1->y;
+ fixed_t dx = part->v2->x - part->v1->x;
+ fixed_t dy = part->v2->y - part->v1->y;
+
if (dx == 0)
{- if (x < part->v1->x - DIST_EPSILON)
+ if (x < - DIST_EPSILON)
return (dy < 0) ? +1 : -1;
- if (x > part->v1->x + DIST_EPSILON)
+ if (x > + DIST_EPSILON)
return (dy > 0) ? +1 : -1;
return 0;
@@ -172,17 +175,44 @@
if (dy == 0)
{- if (y < part->v1->y - DIST_EPSILON)
+ if (y < - DIST_EPSILON)
return (dx > 0) ? +1 : -1;
- if (y > part->v1->y + DIST_EPSILON)
+ if (y > + DIST_EPSILON)
return (dx < 0) ? +1 : -1;
return 0;
}
- // TODO !!
+ // note that we compute the distance to the partition along an axis
+ // (rather than perpendicular to it), which can give values smaller
+ // than the true distance. for our purposes, that is okay.
+ if (abs (dx) >= abs (dy))
+ {+ fixed_t slope = FixedDiv (dy, dx);
+
+ y -= FixedMul (x, slope);
+
+ if (y < - DIST_EPSILON)
+ return (dx > 0) ? +1 : -1;
+
+ if (y > + DIST_EPSILON)
+ return (dx < 0) ? +1 : -1;
+ }
+ else
+ {+ fixed_t slope = FixedDiv (dx, dy);
+
+ x -= FixedMul (y, slope);
+
+ if (x < - DIST_EPSILON)
+ return (dy < 0) ? +1 : -1;
+
+ if (x > + DIST_EPSILON)
+ return (dy > 0) ? +1 : -1;
+ }
+
return 0;
}
@@ -324,6 +354,11 @@
//----------------------------------------------------------------------------
+//
+// For segs not intersecting the partition, just move them into the
+// correct output list (`lefts` or `rights`). otherwise split the seg
+// at the intersection point, one pieces goes left, the other right.
+//
void BSP_SplitSegs (seg_t * part, seg_t * soup, seg_t ** lefts, seg_t ** rights)
{// TODO
--
⑨