From 4ed686ea81aaedb0c1f992b5092f77f3d8b9c7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 30 Aug 2018 11:15:52 +0200 Subject: [PATCH] Fix distance --- raycastlib.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 48b533b..3eae36f 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -193,9 +193,13 @@ uint16_t sqrtInt(uint32_t value) Unit dist(Vector2D p1, Vector2D p2) { - Unit dx = p2.x - p1.x; - Unit dy = p2.y - p1.y; - return sqrtInt((dx * dx) + (dy * dy)); + int32_t dx = p2.x - p1.x; + int32_t dy = p2.y - p1.y; + + dx = dx * dx; + dy = dy * dy; + + return sqrtInt(((uint32_t) dx) + ((uint32_t) dy)); } int8_t pointIsLeftOfRay(Vector2D point, Ray ray)