00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef UPOINT_HPP
00029
#define UPOINT_HPP
00030
00031
#include "../uobject.hpp"
00032
00033
namespace ufo {
00034
00044 class UFO_EXPORT UPoint {
00045
public:
00046
inline UPoint();
00047
inline UPoint(
int x,
int y);
00048
00049
inline int getX()
const;
00050
inline void setX(
int x);
00051
00052
inline int getY()
const;
00053
inline void setY(
int y);
00054
00056
inline void setLocation(
const UPoint & p);
00058
inline UPoint getLocation()
const;
00059
00061
inline void translate(
const UPoint & p);
00062
00066
inline bool isInvalid()
const;
00068
inline bool isNull()
const;
00069
00073
inline UPoint & operator+=(
const UPoint & p);
00077
inline UPoint & operator-=(
const UPoint & p);
00081
inline UPoint & operator*=(
int c);
00086
inline UPoint & operator*=(
double c);
00091
inline UPoint & operator/=(
int c);
00096
inline UPoint & operator/=(
double c);
00097
00098
inline friend std::ostream & operator<<(std::ostream & os,
const UPoint & o);
00099
00100
public:
00101
int x;
00102
int y;
00103
public:
00104
static UPoint invalid;
00105 };
00106
00107
00108
00109
00110
inline UPoint operator+(
const UPoint & p1,
const UPoint & p2);
00111
inline UPoint operator-(
const UPoint & p1,
const UPoint & p2);
00112
00113
inline UPoint operator-(
const UPoint & p);
00114
inline UPoint operator*(
const UPoint & p,
int c);
00115
inline UPoint operator*(
int c,
const UPoint & p);
00116
inline UPoint operator*(
const UPoint & p,
double c);
00117
inline UPoint operator*(
double c,
const UPoint & p);
00118
inline UPoint operator/(
const UPoint & p,
int c);
00119
inline UPoint operator/(
const UPoint & p,
double c);
00120
00122
inline bool operator==(
const UPoint & p1,
const UPoint & p2);
00123
inline bool operator!=(
const UPoint & p1,
const UPoint & p2);
00124
00128 class UFO_EXPORT UPointObject :
public UPoint,
public UObject {
00129 UFO_DECLARE_DYNAMIC_CLASS(UPointObject)
00130
public:
00131
inline UPointObject();
00132
inline UPointObject(
const UPoint & p);
00133
inline UPointObject(
int w,
int h);
00134
00135
00136
00137
00138
virtual unsigned int hashCode()
const;
00139
virtual bool equals(
const UObject * obj);
00140
virtual bool equals(
const UPoint * obj);
00141
virtual UObject * clone()
const;
00142
00143
protected:
00144
virtual std::ostream & paramString(std::ostream & os)
const;
00145 };
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
inline UPoint::UPoint() : x(0), y(0) {}
00156
00157
inline UPoint::UPoint(
int x,
int y) : x(x), y(y) {}
00158
00159
inline int
00160 UPoint::getX()
const {
00161
return x;
00162 }
00163
inline void
00164 UPoint::setX(
int x) {
00165 this->x = x;
00166 }
00167
inline int
00168 UPoint::getY()
const {
00169
return y;
00170 }
00171
inline void
00172 UPoint::setY(
int y) {
00173 this->y = y;
00174 }
00175
00176
inline UPoint
00177 UPoint::getLocation()
const {
00178
return UPoint(x, y);
00179 }
00180
00181
inline void
00182 UPoint::setLocation(
const UPoint & p) {
00183 x = p.
x;
00184 y = p.
y;
00185 }
00186
00187
00188
inline void
00189 UPoint::translate(
const UPoint & p) {
00190 x += p.
x;
00191 y += p.
y;
00192 }
00193
00194
00195
inline bool
00196 UPoint::isInvalid()
const {
00197
return (*
this == UPoint::invalid);
00198 }
00199
00200
inline bool
00201 UPoint::isNull()
const {
00202
return !(x || y);
00203 }
00204
00205
inline UPoint &
00206 UPoint::operator+=(
const UPoint & p) {
00207 x += p.
x;
00208 y += p.
y;
00209
return *
this;
00210 }
00211
00212
inline UPoint &
00213 UPoint::operator-=(
const UPoint & p) {
00214 x -= p.
x;
00215 y -= p.
y;
00216
return *
this;
00217 }
00218
00219
inline UPoint &
00220 UPoint::operator*=(
int c) {
00221 x *= c;
00222 y *= c;
00223
return *
this;
00224 }
00225
00226
inline UPoint &
00227 UPoint::operator*=(
double c) {
00228
00229 x = int(x * c);
00230 y = int(y * c);
00231
return *
this;
00232 }
00233
00234
inline UPoint &
00235 UPoint::operator/=(
int c) {
00236
00237 x = int(x / c);
00238 y = int(y / c);
00239
return *
this;
00240 }
00241
00242
inline UPoint &
00243 UPoint::operator/=(
double c) {
00244
00245 x = int(x / c);
00246 y = int(y / c);
00247
return *
this;
00248 }
00249
00250
inline std::ostream &
00251 operator<<(std::ostream & os,
const UPoint & o) {
00252
return os <<
"UPoint[" << o.
x <<
"," << o.
y <<
"]";
00253 }
00254
00255
00256
00257
00258
00259
inline UPoint operator+(
const UPoint & p1,
const UPoint & p2) {
00260 UPoint ret(p1);
00261
return ret += p2;
00262 }
00263
00264
inline UPoint operator-(
const UPoint & p1,
const UPoint & p2) {
00265 UPoint ret(p1);
00266
return ret -= p2;
00267 }
00268
00269
inline UPoint operator-(
const UPoint & p) {
00270
return UPoint(-p.x, -p.y);
00271 }
00272
00273
inline UPoint operator*(
const UPoint & p,
int c) {
00274 UPoint ret(p);
00275
return ret *= c;
00276 }
00277
00278
inline UPoint operator*(
int c,
const UPoint & p) {
00279 UPoint ret(p);
00280
return ret *= c;
00281 }
00282
00283
inline UPoint operator*(
const UPoint & p,
double c) {
00284 UPoint ret(p);
00285
return ret *= c;
00286 }
00287
00288
inline UPoint operator*(
double c,
const UPoint & p) {
00289 UPoint ret(p);
00290
return ret *= c;
00291 }
00292
00293
inline UPoint operator/(
const UPoint & p,
int c) {
00294 UPoint ret(p);
00295
return ret /= c;
00296 }
00297
00298
inline UPoint operator/(
const UPoint & p,
double c) {
00299 UPoint ret(p);
00300
return ret /= c;
00301 }
00302
00303
00304
inline bool operator==(
const UPoint & p1,
const UPoint & p2) {
00305
return p1.x == p2.x && p1.y == p2.y;
00306 }
00307
00308
inline bool operator!=(
const UPoint & p1,
const UPoint & p2) {
00309
return p1.x != p2.x || p1.y != p2.y;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
inline
00319 UPointObject::UPointObject() : UPoint() {}
00320
00321
inline
00322 UPointObject::UPointObject(
const UPoint & p) : UPoint(p) {}
00323
00324
inline
00325 UPointObject::UPointObject(
int x,
int y) : UPoint(x, y) {}
00326
00327
inline unsigned int
00328 UPointObject::hashCode()
const {
00329
00330
return (((x << 8) | y) ^ y);
00331 }
00332
00333
inline bool
00334 UPointObject::equals(
const UObject * obj) {
00335
if (
const UPointObject * p = dynamic_cast<const UPointObject*>(obj)) {
00336
return (x == p->
x) && (y == p->
y);
00337 }
00338
return false;
00339 }
00340
inline bool
00341 UPointObject::equals(
const UPoint * obj) {
00342
if (obj) {
00343
return (x == obj->x) && (y == obj->y);
00344 }
00345
return false;
00346 }
00347
00348
inline UObject *
00349 UPointObject::clone()
const {
00350
return new UPointObject(x, y);
00351 }
00352
00353
00354
00355
00356
00357
inline std::ostream &
00358 UPointObject::paramString(std::ostream & os)
const {
00359
return os << x <<
"," << y;
00360 }
00361
00362 }
00363
00364
#endif // UPOINT_HPP