Skip to content

Commit

Permalink
Fix number rounding, clarify comment and change var. names
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Sep 2, 2014
1 parent b7f0a8a commit 1c47825
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions TileGenerator.cpp
Expand Up @@ -39,16 +39,16 @@ static inline int color2int(Color c)
return rgb2int(c.r, c.g, c.b, c.a);
}

// rounds n (upwards) to a multiple of f while preserving the sign-bit of n
// rounds n (away from 0) to a multiple of f while preserving the sign of n
static inline int round_multiple_nosign(int n, int f)
{
int nn, ns;
nn = (n >= 0) ? n : -n;
ns = (n >= 0) ? 1 : -1;
if (nn % f == 0)
return n; // n == nn * ns
int abs_n, sign;
abs_n = (n >= 0) ? n : -n;
sign = (n >= 0) ? 1 : -1;
if (abs_n % f == 0)
return n; // n == abs_n * sign
else
return ns * (n + f - (n % f));
return sign * (abs_n + f - (abs_n % f));
}

static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)
Expand Down

1 comment on commit 1c47825

@Zeno-
Copy link

@Zeno- Zeno- commented on 1c47825 Sep 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coulda thanked me :p

Please sign in to comment.