Skip to content

Commit

Permalink
remove a possible div by 0 error
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Apr 4, 2024
1 parent d806700 commit 9cbe62d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/bzflag/World.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ TeamColor World::whoseBase(const float* pos) const
{
float nx = pos[0] - it->p[0];
float ny = pos[1] - it->p[1];
float rx = (float) (cosf(atanf(ny / nx) - it->p[3]) * sqrt((ny * ny) + (nx * nx)));
float ry = (float) (sinf(atanf(ny / nx) - it->p[3]) * sqrt((ny * ny) + (nx * nx)));
float an = atan2f(ny, nx) - it->p[3];
float di = hypotf(nx, ny);
float rx = cosf(an) * di;
float ry = sinf(an) * di;
if (fabsf(rx) < it->p[4] &&
fabsf(ry) < it->p[5])
{
Expand Down
8 changes: 4 additions & 4 deletions src/bzfs/TeamBases.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ float TeamBases::findBaseZ( float x, float y, float z ) const
float rotation = it->rotation;
float nx = x - pos[0];
float ny = y - pos[1];
if (nx == 0.0f)
nx = 1.0f;
float rx = (float)(cosf(atanf(ny/nx)-rotation) * sqrt((ny * ny) + (nx * nx)));
float ry = (float)(sinf(atanf(ny/nx)-rotation) * sqrt((ny * ny) + (nx * nx)));
float an = atan2f(ny, nx) - rotation;
float di = hypotf(nx, ny);
float rx = cosf(an) * di;
float ry = sinf(an) * di;


if (fabsf(rx) < _size[0] &&
Expand Down

0 comments on commit 9cbe62d

Please sign in to comment.