From 4cdd638a0781d58f99b654dd99f24b287096abf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Wed, 3 Jan 2024 20:49:17 +0100 Subject: [PATCH] Use angle instead of range when checking identical points --- src/r_main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index eef3c1d25..9813dfb46 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1058,19 +1058,29 @@ boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y) } else if (dist == closestdist) { - // we're most likely matching against a corner here, so check which point is closest on the opposite side. - vertex_t *diff; + // coordinates are the same; we're most likely matching against a corner here. + // check closest angle instead. + vertex_t *cv, *dv; + angle_t angle = R_PointToAngle2(v.x, v.y, x, y); + angle_t ca, da; if (closest->v1->x == v.x && closest->v1->y == v.y) - diff = closest->v2; + cv = closest->v2; else - diff = closest->v1; + cv = closest->v1; if (v1->x == v.x && v1->y == v.y) - v = *v2; + dv = v2; else - v = *v1; + dv = v1; - if (R_PointToDist2(v.x, v.y, x, y) < R_PointToDist2(diff->x, diff->y, x, y)) + ca = R_PointToAngle2(v.x, v.y, cv->x, cv->y) - angle; + da = R_PointToAngle2(v.x, v.y, dv->x, dv->y) - angle; + if (ca > ANGLE_180) + ca = ANGLE_180 - (ca - ANGLE_180); + if (da > ANGLE_180) + da = ANGLE_180 - (da - ANGLE_180); + + if (ca > da) { closest = sector->lines[i]; closestdist = dist;