From 256221c6a28613bfc1841685e8d12246f7d595a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 21 Oct 2019 17:37:35 +0200 Subject: [PATCH] Fix distance overflow --- raycastlib.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 26f5cbc..cd1d928 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -26,7 +26,7 @@ author: Miloslav "drummyfish" Ciz license: CC0 1.0 - version: 0.90 + version: 0.901 */ #include @@ -855,8 +855,11 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc, divided by leg B (length along the same axis). */ h.distance = - ((h.position.x - ray.start.x) * RCL_UNITS_PER_SQUARE * rayDirXRecip) - / RECIP_SCALE; + (((h.position.x - ray.start.x) / 4) * + RCL_UNITS_PER_SQUARE * rayDirXRecip) + / (RECIP_SCALE / 4); + + // ^ / 4 is here to prevent overflow #endif } else @@ -877,8 +880,11 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc, #if RCL_RECTILINEAR h.distance = - ((h.position.y - ray.start.y) * RCL_UNITS_PER_SQUARE * rayDirYRecip) - / RECIP_SCALE; + (((h.position.y - ray.start.y) / 4) * + RCL_UNITS_PER_SQUARE * rayDirYRecip) + / (RECIP_SCALE / 4); + + // ^ / 4 is here to prevent overflow #endif }