Commit 4c5d69b7 by Sal

Merge branch 'no-aprox-dist' into 'next'

Use R_PointToDist2 over FixedHypot, and FixedHypot over P_AproxDistance See merge request !243
parents 3ad5c0af c23364db
......@@ -238,7 +238,8 @@ static int lib_pAproxDistance(lua_State *L)
fixed_t dx = luaL_checkfixed(L, 1);
fixed_t dy = luaL_checkfixed(L, 2);
//HUDSAFE
lua_pushfixed(L, P_AproxDistance(dx, dy));
LUA_Deprecated(L, "P_AproxDistance", "FixedHypot");
lua_pushfixed(L, FixedHypot(dx, dy));
return 1;
}
......
......@@ -18,8 +18,10 @@
#define HAVE_SQRTF
#endif
#endif
#include "doomdef.h"
#include "m_fixed.h"
#include "tables.h" // ANGLETOFINESHIFT
#ifdef __USE_C_FIXEDMUL__
......@@ -105,20 +107,34 @@ fixed_t FixedSqrt(fixed_t x)
fixed_t FixedHypot(fixed_t x, fixed_t y)
{
fixed_t ax, yx, yx2, yx1;
if (abs(y) > abs(x)) // |y|>|x|
{
ax = abs(y); // |y| => ax
yx = FixedDiv(x, y); // (x/y)
}
else // |x|>|y|
// Moved the code from R_PointToDist2 to here,
// since R_PointToDist2 did the same thing,
// except less prone to overflowing.
angle_t angle;
fixed_t dist;
x = abs(x);
y = abs(y);
if (y > x)
{
ax = abs(x); // |x| => ax
yx = FixedDiv(y, x); // (x/y)
fixed_t temp;
temp = x;
x = y;
y = temp;
}
yx2 = FixedMul(yx, yx); // (x/y)^2
yx1 = FixedSqrt(1 * FRACUNIT + yx2); // (1 + (x/y)^2)^1/2
return FixedMul(ax, yx1); // |x|*((1 + (x/y)^2)^1/2)
if (!y)
return x;
angle = (tantoangle[FixedDiv(y, x)>>DBITS] + ANGLE_90) >> ANGLETOFINESHIFT;
// use as cosine
dist = FixedDiv(x, FINESINE(angle));
return dist;
}
vector2_t *FV2_Load(vector2_t *vec, fixed_t x, fixed_t y)
......
......@@ -24,19 +24,6 @@
#include "z_zone.h"
//
// P_AproxDistance
// Gives an estimation of distance (not exact)
//
fixed_t P_AproxDistance(fixed_t dx, fixed_t dy)
{
dx = abs(dx);
dy = abs(dy);
if (dx < dy)
return dx + dy - (dx>>1);
return dx + dy - (dy>>1);
}
//
// P_ClosestPointOnLine
// Finds the closest point on a given line to the supplied point
//
......
......@@ -41,7 +41,7 @@ typedef boolean (*traverser_t)(intercept_t *in);
boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2,
INT32 pflags, traverser_t ptrav);
FUNCMATH fixed_t P_AproxDistance(fixed_t dx, fixed_t dy);
#define P_AproxDistance(dx, dy) FixedHypot(dx, dy)
void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result);
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result);
INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line);
......
......@@ -393,29 +393,7 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y)
fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1)
{
angle_t angle;
fixed_t dx, dy, dist;
dx = abs(px1 - px2);
dy = abs(py1 - py2);
if (dy > dx)
{
fixed_t temp;
temp = dx;
dx = dy;
dy = temp;
}
if (!dy)
return dx;
angle = (tantoangle[FixedDiv(dy, dx)>>DBITS] + ANGLE_90) >> ANGLETOFINESHIFT;
// use as cosine
dist = FixedDiv(dx, FINESINE(angle));
return dist;
return FixedHypot(px1 - px2, py1 - py2);
}
// Little extra utility. Works in the same way as R_PointToAngle2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment