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

Fix len function

This commit is contained in:
Miloslav Číž 2018-09-14 15:18:34 +02:00
parent 680e5b23a8
commit e1a285c7c4

View file

@ -34,7 +34,7 @@
#else #else
#define UNITS_PER_SQUARE 128 #define UNITS_PER_SQUARE 128
typedef int16_t Unit; typedef int16_t Unit;
#define UNIT_INFINITY 32767; #define UNIT_INFINITY 32000;
#define USE_DIST_APPROX 2 #define USE_DIST_APPROX 2
#endif #endif
@ -516,12 +516,13 @@ Unit dist(Vector2D p1, Vector2D p2)
b = dy; b = dy;
} }
result = (a * 1007) + (b * 441); result = a + (44 * b) / 102;
if (a < (b << 4)) if (a < (b << 4))
result -= (a * 40); result -= (5 * a) / 128;
return result;
return ((result + 512 ) >> 10);
#else #else
dx = dx * dx; dx = dx * dx;
dy = dy * dy; dy = dy * dy;
@ -534,10 +535,11 @@ Unit len(Vector2D v)
{ {
profileCall(len); profileCall(len);
v.x *= v.x; Vector2D zero;
v.y *= v.y; zero.x = 0;
zero.y = 0;
return sqrtInt(((Unit) v.x) + ((Unit) v.y)); return dist(zero,v);
} }
int8_t pointIsLeftOfRay(Vector2D point, Ray ray) int8_t pointIsLeftOfRay(Vector2D point, Ray ray)
@ -716,7 +718,7 @@ HitResult castRay(Ray ray, ArrayFunction arrayFunc)
profileCall(castRay); profileCall(castRay);
HitResult result; HitResult result;
uint16_t len; uint16_t len;
RayConstraints c; RayConstraints c;
c.maxSteps = 1000; c.maxSteps = 1000;