* \brief Positions and offsets
*/
-/* Copyright 2013 Martin Read
+/* Copyright 2013-2014 Martin Read
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
template <typename T> inline T myabs(T val) { return (val < 0) ? -val : val; }
template <typename T> inline T mysign(T val) { return (val < 0) ? -1 : ((val > 0) ? 1 : 0); }
+/*! \brief A two-dimensional vector
+ *
+ * An Offset represents a vector in a plane. Addition and subtraction of
+ * Offsets is fully defined.
+ *
+ * The lt/le/ge/gt operators impose a total ordering, allowing Offset to
+ * be used as the key-type of std::map.
+ */
struct Offset
{
int y;
Offset const& operator -=(Offset const& right) { y -= right.y; x -= right.x; return *this; }
bool operator !=(Offset const& right) const { return (y != right.y) || (x != right.x); }
bool operator ==(Offset const& right) const { return (y == right.y) && (x == right.x); }
+ bool operator <(Offset const& right) const { return (y < right.y) || ((y == right.y) && (x < right.x)); }
+ bool operator <=(Offset const& right) const { return (y < right.y) || ((y == right.y) && (x <= right.x)); }
+ bool operator >(Offset const& right) const { return (y > right.y) || ((y == right.y) && (x > right.x)); }
+ bool operator >=(Offset const& right) const { return (y > right.y) || ((y == right.y) && (x >= right.x)); }
};
+/*! \brief A two-dimensional point
+ *
+ * A Coord approximately represents a point on a plane. Addition of Coords
+ * to each other is undefined. Addition of an Offset to a Coord yields a
+ * Coord. Subtraction of a Coord from another Coord yields an Offset.
+ *
+ * The lt/le/ge/gt operators impose a total ordering, allowing Coord to
+ * be used as the key-type of std::map.
+ */
struct Coord
{
int y;
Coord const& operator -=(Offset const& right) { y -= right.y; x -= right.x; return *this;}
bool operator !=(Coord const& right) const { return (y != right.y) || (x != right.x); }
bool operator ==(Coord const& right) const { return (y == right.y) && (x == right.x); }
+ bool operator <(Coord const& right) const { return (y < right.y) || ((y == right.y) && (x < right.x)); }
+ bool operator <=(Coord const& right) const { return (y < right.y) || ((y == right.y) && (x <= right.x)); }
+ bool operator >(Coord const& right) const { return (y > right.y) || ((y == right.y) && (x > right.x)); }
+ bool operator >=(Coord const& right) const { return (y > right.y) || ((y == right.y) && (x >= right.x)); }
};
extern Coord const Nowhere;