00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 inline ImageRef::ImageRef()
00022 {
00023 x=y=0;
00024 }
00025
00026 inline ImageRef::ImageRef(int xp, int yp)
00027 :x(xp),y(yp)
00028 {}
00029
00030 inline ImageRef::ImageRef(std::istream& is)
00031 {
00032 is.read((char*)&x,sizeof(int));
00033 is.read((char*)&y,sizeof(int));
00034 }
00035
00037
00038
00039
00040
00042
00043 inline bool ImageRef::next(const ImageRef& max)
00044 {
00045 return(++x < max.x || (x=0, ++y < max.y) || (y=0, false));
00046 }
00047
00048 inline bool ImageRef::next(const ImageRef& min, const ImageRef& max)
00049 {
00050 return (++x < max.x || (x=min.x, ++y < max.y) || (y=min.y, false));
00051 }
00052
00053 inline bool ImageRef::prev(const ImageRef& max)
00054 {
00055 return(--x > -1 || (x=max.x-1, --y > -1) || (y=max.y-1, false));
00056 }
00057
00058 inline bool ImageRef::prev(const ImageRef& min, const ImageRef& max)
00059 {
00060 return (--x > min.x-1 || (x=max.x-1, --y > min.y-1) || (y=max.y-1, false));
00061 }
00062
00063 inline void ImageRef::home()
00064 {
00065 x=y=0;
00066 }
00067
00068 inline void ImageRef::end(const ImageRef& size)
00069 {
00070 x=size.x-1;
00071 y=size.y-1;
00072 }
00073
00074 inline ImageRef& ImageRef::operator=(const ImageRef& ref)
00075 {
00076 x=ref.x;
00077 y=ref.y;
00078 return *this;
00079 }
00080
00081 inline bool ImageRef::operator ==(const ImageRef& ref) const
00082 {
00083 return (x==ref.x && y==ref.y);
00084 }
00085
00086 inline bool ImageRef::operator !=(const ImageRef& ref) const
00087 {
00088 return (x!=ref.x || y!=ref.y);
00089 }
00090
00091 inline ImageRef ImageRef::operator-() const
00092 {
00093 ImageRef v(-x, -y);
00094 return v;
00095 }
00096
00097 inline ImageRef& ImageRef::operator*=(const double scale)
00098 {
00099 x=(int)(x*scale);
00100 y=(int)(y*scale);
00101 return *this;
00102 }
00103
00104 inline ImageRef& ImageRef::operator/=(const double scale)
00105 {
00106 x=(int)(x/scale);
00107 y=(int)(y/scale);
00108 return *this;
00109 }
00110
00111 inline ImageRef& ImageRef::operator+=(const ImageRef rhs)
00112 {
00113 x+=rhs.x;
00114 y+=rhs.y;
00115 return *this;
00116 }
00117
00118 inline ImageRef& ImageRef::operator-=(const ImageRef rhs)
00119 {
00120 x-=rhs.x;
00121 y-=rhs.y;
00122 return *this;
00123 }
00124
00125 inline ImageRef ImageRef::operator*(const double scale) const
00126 {
00127 ImageRef v((int)(x*scale),(int)(y*scale));
00128 return v;
00129 }
00130
00131 inline ImageRef ImageRef::operator/(const double scale) const
00132 {
00133 ImageRef v((int)(x/scale),(int)(y/scale));
00134 return v;
00135 }
00136
00137 inline ImageRef ImageRef::operator+(const ImageRef rhs) const
00138 {
00139 ImageRef v(x+rhs.x, y+rhs.y);
00140 return v;
00141 }
00142
00143 inline ImageRef ImageRef::operator-(const ImageRef rhs) const
00144 {
00145 ImageRef v(x-rhs.x, y-rhs.y);
00146 return v;
00147 }
00148
00149 inline ImageRef& ImageRef::operator<<=(int i)
00150 {
00151 x = x << i;
00152 y=y << i;
00153 return *this;
00154 }
00155
00156 inline ImageRef& ImageRef::operator>>=(int i)
00157 {
00158 x = x >> i;
00159 y=y >> i;
00160 return *this;
00161 }
00162
00163 inline ImageRef ImageRef::shiftl(int i) const
00164 {
00165 ImageRef result;
00166 result.x = x << i;
00167 result.y=y << i;
00168 return result;
00169 }
00170
00171 inline ImageRef ImageRef::shiftr(int i) const
00172 {
00173 ImageRef result;
00174 result.x = x >> i;
00175 result.y=y >> i;
00176 return result;
00177 }
00178
00179 inline ImageRef ImageRef::operator<<(int i) const
00180 {
00181 return shiftl(i);
00182 }
00183
00184 inline ImageRef ImageRef::operator>>(int i) const
00185 {
00186 return shiftr(i);
00187 }
00188
00189
00190 inline ImageRef operator*(const int scale, const ImageRef& ref)
00191 {
00192 return ImageRef(ref.x*scale, ref.y*scale);
00193 }
00194
00195 inline bool ImageRef::operator<(const ImageRef & other) const
00196 {
00197 return y < other.y || ( y == other.y && x < other.x);
00198 }
00199
00200 inline bool ImageRef::operator>(const ImageRef & other) const
00201 {
00202 return y > other.y || ( y == other.y && x > other.x);
00203 }
00204
00205
00206 inline int& ImageRef::operator[](int i)
00207 {
00208 if(i==0)
00209 return x;
00210 if(i==1)
00211 return y;
00212 throw Exceptions::BadSubscript();
00213 }
00214
00215 inline int ImageRef::operator[](int i) const
00216 {
00217 if(i==0)
00218 return x;
00219 if(i==1)
00220 return y;
00221 throw Exceptions::BadSubscript();
00222 }
00223
00224 inline unsigned int ImageRef::mag_squared() const
00225 {
00226 typedef unsigned int uint;
00227 return uint(x*x) + uint(y*y);
00228 }
00229
00230 inline int ImageRef::area() const
00231 {
00232 return x * y;
00233 }
00234
00235 inline ImageRef ImageRef::dot_times(const ImageRef &ref) const
00236 {
00237 return ImageRef(x * ref.x, y * ref.y);
00238 }