From 06da0f97202b82e648b144b7a6992cac4f5d8748 Mon Sep 17 00:00:00 2001 From: Quietust Date: Sun, 1 Apr 2012 19:44:35 -0500 Subject: [PATCH] Fix coord/coord2d division/modulo operators to properly handle negative numbers (fixes some glitches with revflood and possibly other utils) --- library/include/df/custom/coord.methods.inc | 4 ++-- library/include/df/custom/coord2d.methods.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/include/df/custom/coord.methods.inc b/library/include/df/custom/coord.methods.inc index a66a71919..6814be3c2 100644 --- a/library/include/df/custom/coord.methods.inc +++ b/library/include/df/custom/coord.methods.inc @@ -33,7 +33,7 @@ coord operator-(const coord &other) 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 { @@ -41,7 +41,7 @@ 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 diff --git a/library/include/df/custom/coord2d.methods.inc b/library/include/df/custom/coord2d.methods.inc index f617001cb..c27629458 100644 --- a/library/include/df/custom/coord2d.methods.inc +++ b/library/include/df/custom/coord2d.methods.inc @@ -29,7 +29,7 @@ coord2d operator-(const coord2d &other) 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 { @@ -37,5 +37,5 @@ coord2d operator*(int number) const } coord2d operator%(int number) const { - return coord2d(x%number, y%number); + return coord2d((x+number)%number, (y+number)%number); }