mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-23 20:49:57 +01:00
Add octagonal distance
This commit is contained in:
parent
284135bcae
commit
3111e72dd6
1 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue