Fix coord/coord2d division/modulo operators to properly handle negative numbers (fixes some glitches with revflood and possibly other utils)

develop
Quietust 2012-04-01 19:44:35 -05:00
parent a9a6fbd8b5
commit 06da0f9720
2 changed files with 4 additions and 4 deletions

@ -33,7 +33,7 @@ coord operator-(const coord &other) const
coord operator/(int number) const coord operator/(int number) const
{ {
return coord(x/number, y/number, z); return coord((x < 0 ? x - number : x)/number, (y < 0 ? y - number : y)/number, z);
} }
coord operator*(int number) const coord operator*(int number) const
{ {
@ -41,7 +41,7 @@ coord operator*(int number) const
} }
coord operator%(int number) const coord operator%(int number) const
{ {
return coord(x%number, y%number, z); return coord((x+number)%number, (y+number)%number, z);
} }
coord operator-(int number) const coord operator-(int number) const

@ -29,7 +29,7 @@ coord2d operator-(const coord2d &other) const
coord2d operator/(int number) const coord2d operator/(int number) const
{ {
return coord2d(x/number, y/number); return coord2d((x < 0 ? x - number : x)/number, (y < 0 ? y - number : y)/number);
} }
coord2d operator*(int number) const coord2d operator*(int number) const
{ {
@ -37,5 +37,5 @@ coord2d operator*(int number) const
} }
coord2d operator%(int number) const coord2d operator%(int number) const
{ {
return coord2d(x%number, y%number); return coord2d((x+number)%number, (y+number)%number);
} }