1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00

Add octagonal distance

This commit is contained in:
Miloslav Číž 2018-09-13 17:36:42 +02:00
parent 284135bcae
commit 3111e72dd6

View file

@ -478,10 +478,19 @@ Unit dist(Vector2D p1, Vector2D p2)
Unit dx = p2.x - p1.x; Unit dx = p2.x - p1.x;
Unit dy = p2.y - p1.y; 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; dx = dx * dx;
dy = dy * dy; dy = dy * dy;
return sqrtInt((Unit) (dx + dy)); return sqrtInt((Unit) (dx + dy));
#endif
} }
Unit len(Vector2D v) Unit len(Vector2D v)