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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00054 #ifndef __PPOINTH__
00055 #define __PPOINTH__
00056
00057 namespace pandore {
00058
00059 class Dimension1d;
00060 class Dimension2d;
00061 class Dimension3d;
00062 class Point1d;
00063 class Point2d;
00064 class Point3d;
00065
00066
00067
00068
00069
00070
00071 template<>
00072 struct TypeName< Point1d > {
00073
00074
00075
00076
00077 static std::string Name() { return "Point1d"; }
00078 };
00079
00080
00081
00082
00083
00084
00085 template<>
00086 struct TypeName< Point2d > {
00091 static std::string Name() { return "Point2d"; }
00092 };
00093
00094
00095
00096
00097
00098
00099 template<>
00100 struct TypeName< Point3d > {
00105 static std::string Name() { return "Point3d"; }
00106 };
00107
00121 class Point: public Pobject {
00122 protected:
00123 Point() {}
00124
00125 public:
00126 ~Point() {}
00127
00133 Pobject* Mask( const Pobject * ) {
00134 return this;
00135 }
00136
00143 Pobject* UnMask( const Pobject * , const Pobject * ) {
00144 return this;
00145 }
00146
00153 Errc LoadAttributes( FILE* ) {
00154 return SUCCESS;
00155 }
00156
00162 Errc SaveAttributes( FILE* ) const {
00163 return SUCCESS;
00164 }
00165 };
00166
00182 class Point1d: public Point {
00183 public:
00185 Long x;
00186
00192 Typobj Type() const { return Po_Point1d; }
00193
00198 std::string Name() const { return TypeName< Point1d >::Name(); }
00199
00204 Point1d(): Point(), x(0) {}
00205
00211 Point1d( Long x ): Point(), x(x) {}
00212
00218 Point1d( const Point1d& p ): Point(), x(p.x) {}
00219
00224 Point1d( const Dimension1d& d ): Point(), x(d.w) {}
00225
00231 const Point1d& operator=( const Point1d& pt ) {
00232 x = pt.x;
00233 return *this;
00234 }
00235
00242 bool operator==( const Point1d& pt ) const {
00243 return pt.x == x;
00244 }
00245
00251 bool operator!=( const Point1d& pt ) const {
00252 return !(pt == *this);
00253 }
00254
00260 Point1d& operator+=( const Point1d& pt ) {
00261 x += pt.x;
00262 return *this;
00263 }
00264
00270 Point1d& operator-=( const Point1d& pt ) {
00271 x -= pt.x;
00272 return *this;
00273 }
00274
00280 Point1d& operator*=( const Point1d& pt ) {
00281 x *= pt.x;
00282 return *this;
00283 }
00284
00290 Point1d& operator/=( const Point1d& pt ) {
00291 x /= pt.x;
00292 return *this;
00293 }
00294
00302 Point1d operator+( const Point1d& pt ) const {
00303 return Point1d(x + pt.x);
00304 }
00305
00313 Point1d operator-( const Point1d& pt ) const {
00314 return Point1d(x - pt.x);
00315 }
00316
00324 Point1d operator*( const Point1d& pt ) const {
00325 return Point1d(x * pt.x);
00326 }
00327
00335 Point1d operator/( const Point1d& pt ) const {
00336 return Point1d(x / pt.x);
00337 }
00338
00342 Pobject* Clone() const {
00343 return new Point1d(x);
00344 }
00345
00351 Errc LoadData( FILE *df ) {
00352 if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00353 return FAILURE;
00354 }
00355 return SUCCESS;
00356 }
00357
00363 Errc SaveData( FILE *df ) const {
00364 if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00365 return FAILURE;
00366 }
00367 return SUCCESS;
00368 }
00369 };
00370
00386 class Point2d: public Point {
00387 public:
00389 Long x;
00391 Long y;
00392
00398 Typobj Type() const { return Po_Point2d; }
00399
00404 std::string Name() const { return TypeName< Point2d >::Name(); }
00405
00410 Point2d(): Point(), x(0), y(0) {}
00411
00417 Point2d( Long i ): Point(), x(i), y(i) {}
00418
00425 Point2d( Long y, Long x ): Point(), x(x), y(y) {}
00426
00432 Point2d( const Point2d& p): Point(), x(p.x), y(p.y) {}
00433
00438 Point2d( const Dimension2d& p): Point(), x(p.w), y(p.h) {}
00439
00445 const Point2d& operator=( const Point2d& pt ) {
00446 x = pt.x;
00447 y = pt.y;
00448 return *this;
00449 }
00450
00457 bool operator==( const Point2d& pt ) const {
00458 return pt.x == x && pt.y == y;
00459 }
00460
00466 bool operator!=( const Point2d& pt ) const {
00467 return !(pt == *this);
00468 }
00469
00475 Point2d& operator+=( const Point2d& pt ) {
00476 x += pt.x;
00477 y += pt.y;
00478 return *this;
00479 }
00480
00486 Point2d& operator-=( const Point2d& pt ) {
00487 x -= pt.x;
00488 y -= pt.y;
00489 return *this;
00490 }
00491
00497 Point2d& operator/=( const Point2d& pt ) {
00498 x /= pt.x;
00499 y /= pt.y;
00500 return *this;
00501 }
00502
00508 Point2d& operator*=( const Point2d& pt ) {
00509 x *= pt.x;
00510 y *= pt.y;
00511 return *this;
00512 }
00513
00521 Point2d operator+( const Point2d& pt ) const {
00522 return Point2d(y + pt.y, x + pt.x);
00523 }
00524
00532 Point2d operator-( const Point2d& pt ) const {
00533 return Point2d(y - pt.y, x - pt.x);
00534 }
00535
00543 Point2d operator*( const Point2d& pt ) const {
00544 return Point2d(y * pt.y, x * pt.x);
00545 }
00546
00554 Point2d operator/( const Point2d& pt ) const {
00555 return Point2d(y / pt.y, x / pt.x);
00556 }
00557
00561 Pobject* Clone() const {
00562 return new Point2d(y, x);
00563 }
00564
00570 Errc LoadData( FILE *df ) {
00571 if (Fdecode(&y, sizeof(y), 1, df) < 1) {
00572 return FAILURE;
00573 }
00574 if (Fdecode(&x, sizeof(x), 1, df) < 1) {
00575 return FAILURE;
00576 }
00577 return SUCCESS;
00578 }
00579
00585 Errc SaveData( FILE *df ) const {
00586 if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00587 return FAILURE;
00588 }
00589 if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00590 return FAILURE;
00591 }
00592 return SUCCESS;
00593 }
00594 };
00595
00611 class Point3d: public Point {
00612 public:
00614 Long z;
00616 Long y;
00618 Long x;
00619
00625 Typobj Type() const { return Po_Point3d; }
00626
00631 std::string Name() const { return TypeName< Point3d >::Name(); }
00632
00637 Point3d(): Point(), z(0), y(0), x(0) {}
00638
00644 Point3d( Long i ): Point(), z(i), y(i), x(i) {}
00645
00653 Point3d( Long z, Long y, Long x ): Point(), z(z), y(y), x(x) {}
00654
00659 Point3d( const Dimension3d& p): Point(), z(p.d), y(p.h), x(p.w) {}
00660
00666 Point3d( const Point3d& p): Point(), z(p.z), y(p.y), x(p.x) {}
00667
00673 Point3d operator=( Point3d pt ) {
00674 x = pt.x;
00675 y = pt.y;
00676 z = pt.z;
00677 return *this; }
00678
00685 bool operator==( const Point3d& pt ) const {
00686 return pt.x == x && pt.y == y && pt.z == z;
00687 }
00688
00694 bool operator!=( const Point3d& pt ) const {
00695 return !(pt == *this);
00696 }
00697
00703 Point3d& operator+=( const Point3d& pt ) {
00704 x += pt.x;
00705 y += pt.y;
00706 z += pt.z;
00707 return *this;
00708 }
00709
00715 Point3d& operator-=( const Point3d& pt ) {
00716 x -= pt.x;
00717 y -= pt.y;
00718 z -= pt.z;
00719 return *this;
00720 }
00721
00727 Point3d& operator*=( const Point3d& pt ) {
00728 x *= pt.x;
00729 y *= pt.y;
00730 z *= pt.z;
00731 return *this;
00732 }
00733
00739 Point3d& operator/=( const Point3d& pt ) {
00740 x /= pt.x;
00741 y /= pt.y;
00742 z /= pt.z;
00743 return *this;
00744 }
00745
00753 Point3d operator+( const Point3d& pt ) const {
00754 return Point3d(z + pt.z, y + pt.y, x + pt.x);
00755 }
00756
00764 Point3d operator-( const Point3d& pt ) const {
00765 return Point3d(z - pt.z, y - pt.y, x - pt.x);
00766 }
00767
00775 Point3d operator*( const Point3d& pt ) const {
00776 return Point3d(z * pt.z, y * pt.y, x * pt.x);
00777 }
00778
00786 Point3d operator/( const Point3d& pt ) const {
00787 return Point3d(z / pt.z, y / pt.y, x / pt.x);
00788 }
00789
00793 Pobject* Clone() const {
00794 return new Point3d(z, y, x);
00795 }
00796
00802 Errc LoadData( FILE *df ) {
00803 if (this->Fdecode(&z, sizeof(z), 1, df) < 1) {
00804 return FAILURE;
00805 }
00806 if (this->Fdecode(&y, sizeof(y), 1, df) < 1) {
00807 return FAILURE;
00808 }
00809 if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00810 return FAILURE;
00811 }
00812 return SUCCESS;
00813 }
00814
00820 Errc SaveData( FILE *df ) const {
00821 if (this->Fencode(&z, sizeof(z), 1, df) < 1) {
00822 return FAILURE;
00823 }
00824 if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00825 return FAILURE;
00826 }
00827 if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00828 return FAILURE;
00829 }
00830 return SUCCESS;
00831 }
00832 };
00833
00834 }
00835
00836 #endif // __PPOINTH__