From a4c6b88dc19f87654e7581a104be8274203c98f2 Mon Sep 17 00:00:00 2001 From: fluffymormegil Date: Tue, 12 Oct 2010 22:51:06 +0100 Subject: [PATCH] Featurefulness for Coord.hh --- include/libmormegil/Coord.hh | 50 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/include/libmormegil/Coord.hh b/include/libmormegil/Coord.hh index f0c66f9..aefcd60 100644 --- a/include/libmormegil/Coord.hh +++ b/include/libmormegil/Coord.hh @@ -26,8 +26,8 @@ // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. -// We need std::max<>, std::min<>. The thing called std::abs<> is in -// and is intended for use on complex numbers; dude what the fuck? +// We need std::max<> and std::min<>. The thing called std::abs<> is in +// and is intended for use on complex numbers; dude what the fuck? #ifndef libmormegil_Coord_hh #define libmormegil_Coord_hh @@ -39,6 +39,10 @@ namespace libmormegil { + /* Yes, the basic_offset and basic_coord templates do indeed look very + similar. They are kept distinct, however, as what one might choose + to call an "insurance policy" - you can't add basic_coord objects + together. */ template struct basic_offset { typedef basic_offset& ref; @@ -59,7 +63,16 @@ namespace libmormegil return *this; } - int length_inf() { return std::min(std::abs(y), std::abs(x)); } + ref operator *=(const basic_offset& right) + { + y *= right.y; + x *= right.x; + return *this; + } + + int length_taxi() { return abs(y) + abs(x); } + int lengthsq() { return y * y + x * x; } + int length_inf() { return std::min(abs(y), abs(x)); } }; template struct basic_coord @@ -80,11 +93,42 @@ namespace libmormegil x -= right.x; return *this; } + ref operator *=(const basic_offset& right) + { + y *= right.y; + x *= right.x; + return *this; + } basic_offset operator -(const_ref right) const { basic_offset tmp = { y - right.y, x - right.x }; return tmp; } + int dist_taxi(const_ref right) const + { + return abs(y - right.y) + abs(x - right.x); + } + int distsq(const_ref right) const + { + return ((y - right.y) * (y - right.y) + + (x - right.x) * (x - right.x)); + } + int dist_inf(const_ref right) const + { + return std::max(abs(y - right.y), abs(x - right.x)); + } + int size_taxi() const + { + return abs(y) + abs(x); + } + int sizesq() const + { + return y * y + x * x; + } + int size_inf() const + { + return std::max(abs(y), abs(x)); + } }; typedef basic_offset Offset; -- 2.11.0