00001 #ifndef __DIM_2D__
00002 #define __DIM_2D__
00003
00004 #include <QString>
00005
00006 namespace apig {
00007
00009 class Dim2D {
00010 public:
00011 Dim2D() : defined(false), w(UNDEFINED), h(UNDEFINED) {}
00012
00013 Dim2D(int w, int h) : defined(w > UNDEFINED && h > UNDEFINED), w(defined ? w : UNDEFINED), h(defined ? h : UNDEFINED) {}
00014
00015 int width() const { return w; }
00016 int height() const { return h; }
00017 bool isDefined() const { return defined; }
00018 bool isBetween(int min, int max) const { return w >= min && h >= min && w <= max && h <= max; }
00019 bool contains(int x, int y) const { return x >= 0 && x < w && y >= 0 && y < h; }
00020
00021 bool operator==(Dim2D s) const { return w == s.w && h == s.h; }
00022 bool operator!=(Dim2D s) const { return w != s.w || h != s.h; }
00023
00024 QString toQString() const { return defined ? QString("(%1,%2)").arg(w).arg(h) : QString("<undefined>"); }
00025
00026 private:
00027 bool defined;
00028 int w, h;
00029 static const int UNDEFINED = 0;
00030 };
00031
00032 }
00033
00034 #endif
00035