From 3111e72dd62033415c309ec5d84c346d92c86f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 13 Sep 2018 17:36:42 +0200 Subject: [PATCH] Add octagonal distance --- raycastlib.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/raycastlib.h b/raycastlib.h index 205500e..3df8282 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -478,10 +478,19 @@ Unit dist(Vector2D p1, Vector2D p2) Unit dx = p2.x - p1.x; Unit dy = p2.y - p1.y; +#ifdef RAYCAST_TINY + // octagonal approximation of Euclidean distance + + dx = absVal(dx); + dy = absVal(dy); + + return dy > dx ? dx / 2 + dy : dy / 2 + dx; +#else dx = dx * dx; dy = dy * dy; return sqrtInt((Unit) (dx + dy)); +#endif } Unit len(Vector2D v)