00001 #ifndef PRIMITIVE_H 00002 #define PRIMITIVE_H 00003 00004 #include "mimasexception.h" 00005 00006 namespace mimas { 00010 struct pixel { 00011 00012 pixel operator=(const pixel &rhs) 00013 { 00014 this->x = rhs.x; 00015 this->y = rhs.y; 00016 return *this; 00017 } 00018 00019 pixel operator+(const pixel &rhs) const 00020 { 00021 pixel result; 00022 result.x = this->x + rhs.x; 00023 result.y = this->y + rhs.y; 00024 return result; 00025 } 00026 00027 unsigned int x,y; 00028 pixel(int x = 0, int y = 0) throw(mimasexception) 00029 { 00030 if (x < 0 || y < 0) 00031 { 00032 mimasexception e; 00033 e << "Pixel must have positive coordinates" ; 00034 throw e; 00035 } 00036 else 00037 { 00038 this->x = x; 00039 this->y = y; 00040 } 00041 } 00042 }; 00043 00044 00048 struct pixel_f { 00049 double x, y; 00050 pixel_f( double x = 0, double y = 0): x(x), y(y){ assert(x >=0 && y>= 0); } 00051 }; 00052 00056 struct point { 00057 point operator=(const point &rhs) 00058 { 00059 this->x = rhs.x; 00060 this->y = rhs.y; 00061 return *this; 00062 } 00063 00064 point operator+(const point &rhs) const 00065 { 00066 point result; 00067 result.x = this->x + rhs.x; 00068 result.y = this->y + rhs.y; 00069 return result; 00070 } 00071 int x,y; 00072 point(int x = 0, int y = 0): x(x), y(y){} 00073 }; 00074 00078 struct point_f { 00079 double x,y; 00080 point_f(double x = 0, double y = 0): x(x), y(y){} 00081 }; 00082 00086 template< typename T > 00087 struct segment { 00088 T p1,p2; 00089 segment(T &p1, T &p2): p1(p1), p2(p2){} 00090 }; 00091 00092 } 00093 #endif