00001
00204 #ifndef INC_MI32_POINT_H
00205 #define INC_MI32_POINT_H
00206
00212
00213 #ifndef INC_MI32_INIBASE_H
00214 #include <mi32/inibase.h>
00215 #endif
00216
00217 #ifndef INC_MI32_MEMBUF_H
00218 #include <mi32/membuf.h>
00219 #endif
00220
00221 #ifndef INC_MI32_MATH_H
00222 #include <mi32/math.h>
00223 #endif
00224
00225 #ifdef ALLOW_NAMESPACES
00226 #include <cmath>
00227 #endif
00228
00229
00230
00231
00232
00233
00235 enum DIMENSION {
00236 DIMENSION_2D = 0,
00237 DIMENSION_3D = 1
00238 };
00239
00242 enum ORIENTATION {
00243 ORIENTATION_Unknown = 0,
00244 ORIENTATION_CounterClockwise = 1,
00245 ORIENTATION_Clockwise = 2,
00246 ORIENTATION_EmptyPolygon = 3
00247 };
00248
00249
00250 #ifndef GENERATING_DOXYGEN_OUTPUT
00252 struct DPOINT3D;
00253 #endif
00254
00255
00258
00259
00260 struct DPOINT2D_OLD {
00261
00262 double x;
00263 double y;
00264
00266 inline DPOINT2D_OLD& operator= (
00267 const DPOINT2D& rhs
00268 );
00269
00270 #ifndef GENERATING_DOXYGEN_OUTPUT
00271 CHECKSIZE(16);
00272 #endif
00273 };
00274
00275 struct DPOINT3D_OLD {
00276
00277 double x;
00278 double y;
00279 double z;
00280
00282 inline DPOINT3D_OLD& operator= (
00283 const DPOINT3D& rhs
00284 );
00285
00286 #ifndef GENERATING_DOXYGEN_OUTPUT
00287 CHECKSIZE(24);
00288 #endif
00289 };
00290
00291
00292
00293
00295 struct WPOINT2D {
00296
00297 INT16 x;
00298 INT16 y;
00299
00301 WPOINT2D (
00302 ) {
00303 }
00304
00306 WPOINT2D (
00307 INT16 dx,
00308 INT16 dy
00309 ) : x(dx), y(dy) {
00310 }
00311
00312 #ifndef GENERATING_DOXYGEN_OUTPUT
00313 CHECKSIZE(4);
00314 #endif
00315 };
00316
00318 inline bool operator== (
00319 const WPOINT2D& lhs,
00320 const WPOINT2D& rhs
00321 ) {
00322 return (lhs.x == rhs.x && lhs.y == rhs.y);
00323 }
00324
00326 inline bool operator!= (
00327 const WPOINT2D& lhs,
00328 const WPOINT2D& rhs
00329 ) {
00330 return (lhs.x != rhs.x || lhs.y != rhs.y);
00331 }
00332
00333
00334
00335
00337 struct WPOINT3D : public WPOINT2D {
00338
00339 INT16 z;
00340
00342 WPOINT3D (
00343 ) {
00344 }
00345
00347 WPOINT3D (
00348 const INT16 dx,
00349 const INT16 dy,
00350 const INT16 dz
00351 ) : WPOINT2D(dx,dy), z(dz) {
00352 }
00353
00355 WPOINT3D (
00356 const WPOINT2D& rhs
00357 ) : WPOINT2D(rhs), z(0) {
00358 }
00359
00360 #ifndef GENERATING_DOXYGEN_OUTPUT
00361 CHECKSIZE(6);
00362 #endif
00363 };
00364
00366 inline bool operator== (
00367 const WPOINT3D& lhs,
00368 const WPOINT3D& rhs
00369 ) {
00370 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
00371 }
00372
00374 inline bool operator!= (
00375 const WPOINT3D& lhs,
00376 const WPOINT3D& rhs
00377 ) {
00378 return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z);
00379 }
00380
00381
00382
00383
00385 struct LPOINT2D {
00386
00387 INT32 x;
00388 INT32 y;
00389
00391 LPOINT2D (
00392 ) {
00393 }
00394
00396 LPOINT2D (
00397 INT32 dx,
00398 INT32 dy
00399 ) : x(dx), y(dy) {
00400 }
00401
00403 LPOINT2D (
00404 const WPOINT2D& pt
00405 ) : x(pt.x), y(pt.y) { }
00406
00408 explicit inline LPOINT2D (
00409 const DPOINT2D& pt
00410 );
00411
00413 LPOINT2D& operator= (
00414 const WPOINT2D& rhs
00415 ) { x = rhs.x; y = rhs.y; return (*this); }
00416
00418 inline LPOINT2D& operator= (
00419 const DPOINT2D& pt
00420 );
00421
00423 LPOINT2D operator- (
00424 ) { return (LPOINT2D(-x,-y)); }
00425
00427 LPOINT2D operator+ (
00428 const LPOINT2D& rhs
00429 ) const { return (LPOINT2D(x+rhs.x,y+rhs.y)); }
00430
00432 LPOINT2D operator- (
00433 const LPOINT2D& rhs
00434 ) const { return (LPOINT2D(x-rhs.x,y-rhs.y)); }
00435
00437 LPOINT2D operator+= (
00438 const LPOINT2D& rhs
00439 ) { x += rhs.x; y += rhs.y; return (*this); }
00440
00442 LPOINT2D operator-= (
00443 const LPOINT2D& rhs
00444 ) { x -= rhs.x; y -= rhs.y; return (*this); }
00445
00448 DEPRECATED_MSG("Use GetDistance2D") double GetDistance (
00449 const LPOINT2D& pt
00450 ) const { return (GetDistance2D(pt)); }
00451
00453 double GetDistance2D (
00454 const LPOINT2D& pt
00455 ) const {
00456 double dx(pt.x - x);
00457 double dy(pt.y - y);
00458 return (sqrt(dx*dx + dy*dy));
00459 }
00460
00461
00462 void Set (
00463 INT32 ix,
00464 INT32 iy
00465 ) { x = ix; y = iy; }
00466
00468 void SwapBytes (
00469 ) { ::SwapBytes(x); ::SwapBytes(y); }
00470
00471 #ifndef GENERATING_DOXYGEN_OUTPUT
00472 CHECKSIZE(8);
00473 #endif
00474 };
00475
00477 inline bool operator== (
00478 const LPOINT2D& lhs,
00479 const LPOINT2D& rhs
00480 ) {
00481 return (lhs.x == rhs.x && lhs.y == rhs.y);
00482 }
00483
00485 inline bool operator!= (
00486 const LPOINT2D& lhs,
00487 const LPOINT2D& rhs
00488 ) {
00489 return (lhs.x != rhs.x || lhs.y != rhs.y);
00490 }
00491
00493 inline void SwapBytes (
00494 LPOINT2D& pt
00495 ) {
00496 pt.SwapBytes();
00497 }
00498
00499
00500
00501
00503 struct LPOINT3D : public LPOINT2D {
00504
00505 INT32 z;
00506
00508 LPOINT3D (
00509 ) { }
00510
00512 LPOINT3D (
00513 const INT32 dx,
00514 const INT32 dy,
00515 const INT32 dz
00516 ) : LPOINT2D(dx,dy), z(dz) { }
00517
00519 explicit LPOINT3D (
00520 const LPOINT2D& rhs,
00521 INT32 iz = 0
00522 ) : LPOINT2D(rhs), z(iz) { }
00523
00525 void SwapBytes (
00526 ) { ::SwapBytes(x); ::SwapBytes(y); ::SwapBytes(z); }
00527
00528 #ifndef GENERATING_DOXYGEN_OUTPUT
00529 CHECKSIZE(12);
00530 #endif
00531 };
00532
00534 inline void SwapBytes (
00535 LPOINT3D& pt
00536 ) {
00537 pt.SwapBytes();
00538 }
00539
00540
00541
00542
00544 struct FPOINT2D {
00545
00546 float x;
00547 float y;
00548
00550 FPOINT2D (
00551 ) { }
00552
00554 FPOINT2D (
00555 float dx,
00556 float dy
00557 ) : x(dx), y(dy) { }
00558
00560 FPOINT2D (
00561 const WPOINT2D& pt
00562 ) : x(pt.x), y(pt.y) { }
00563
00565 FPOINT2D& operator= (
00566 const WPOINT2D& rhs
00567 ) { x = rhs.x; y = rhs.y; return (*this); }
00568
00570 FPOINT2D& operator= (
00571 const DPOINT2D& rhs
00572 );
00573
00575 FPOINT2D operator- (
00576 ) const { return (FPOINT2D(-x,-y)); }
00577
00579 FPOINT2D operator+ (
00580 const FPOINT2D& rhs
00581 ) const { return (FPOINT2D(x+rhs.x,y+rhs.y)); }
00582
00584 FPOINT2D operator- (
00585 const FPOINT2D& rhs
00586 ) const { return (FPOINT2D(x-rhs.x,y-rhs.y)); }
00587
00589 FPOINT2D operator* (
00590 const float rhs
00591 ) const { return (FPOINT2D(x*rhs,y*rhs)); }
00592
00594 FPOINT2D operator/ (
00595 const float rhs
00596 ) const { return (FPOINT2D(x/rhs,y/rhs)); }
00597
00599 FPOINT2D operator+= (
00600 const FPOINT2D& rhs
00601 ) { x += rhs.x; y += rhs.y; return (*this); }
00602
00604 FPOINT2D operator-= (
00605 const FPOINT2D& rhs
00606 ) { x -= rhs.x; y -= rhs.y; return (*this); }
00607
00609 FPOINT2D operator*= (
00610 const float rhs
00611 ) { x *= rhs; y *= rhs; return (*this); }
00612
00614 FPOINT2D operator/= (
00615 const float rhs
00616 ) { x /= rhs; y /= rhs; return (*this); }
00617
00619 DEPRECATED_MSG("Use GetDistance2D") float GetDistance (
00620 const FPOINT2D& pt
00621 ) const { return (GetDistance2D(pt)); }
00622
00624 DEPRECATED_MSG("Use GetDistanceSquared2D") float GetDistanceSquared (
00625 const FPOINT2D& pt
00626 ) const { return (GetDistanceSquared2D(pt)); }
00627
00629 float GetDistance2D (
00630 const FPOINT2D& pt
00631 ) const { return (static_cast<float>(sqrt(GetDistanceSquared2D(pt)))); }
00632
00634 float GetDistanceSquared2D (
00635 const FPOINT2D& pt
00636 ) const {
00637 float dx(pt.x - x);
00638 float dy(pt.y - y);
00639 return (static_cast<float>(dx*dx + dy*dy));
00640 }
00641
00643 float GetMagnitude2D (
00644 ) const { return (static_cast<float>(sqrt(GetMagnitudeSquared2D()))); }
00645
00647 float GetMagnitudeSquared2D (
00648 ) const { return (static_cast<float>(x*x + y*y)); }
00649
00651 bool Normalize (
00652 ) {
00653 const float m = GetMagnitude2D();
00654 if (m == 0.0F) return (false);
00655 *this /= m;
00656 return (true);
00657 }
00658
00660 static bool Normalize (
00661 FPOINT2D& pt
00662 ) {
00663 const float d = pt.GetMagnitude2D();
00664 if (d == 0.0F) return false;
00665 pt /= d;
00666 return true;
00667 }
00668
00670 float DotProduct (
00671 const FPOINT2D& pt
00672 ) const { return (x*pt.x + y*pt.y); }
00673
00675 float CrossProduct (
00676 const FPOINT2D& pt
00677 ) const { return (x*pt.y - y*pt.x); }
00678
00680 void SwapBytes (
00681 ) { ::SwapBytes(x); ::SwapBytes(y); }
00682
00683 #ifndef GENERATING_DOXYGEN_OUTPUT
00684 CHECKSIZE(8);
00685 #endif
00686 };
00687
00689 inline bool operator== (
00690 const FPOINT2D& lhs,
00691 const FPOINT2D& rhs
00692 ) {
00693 return (lhs.x == rhs.x && lhs.y == rhs.y);
00694 }
00695
00697 inline bool operator!= (
00698 const FPOINT2D& lhs,
00699 const FPOINT2D& rhs
00700 ) {
00701 return (lhs.x != rhs.x || lhs.y != rhs.y);
00702 }
00703
00705 inline void SwapBytes (
00706 FPOINT2D& pt
00707 ) {
00708 pt.SwapBytes();
00709 }
00710
00711
00712
00713
00715 struct FPOINT3D : public FPOINT2D {
00716
00717 float z;
00718
00720 FPOINT3D (
00721 ) {
00722 }
00723
00725 FPOINT3D (
00726 const FPOINT3D& rhs
00727 ) : FPOINT2D(rhs.x, rhs.y), z(rhs.z) { }
00728
00730 FPOINT3D (
00731 const float dx,
00732 const float dy,
00733 const float dz
00734 ) : FPOINT2D(dx,dy), z(dz) {
00735 }
00736
00738 FPOINT3D (
00739 const FPOINT2D& rhs
00740 ) : FPOINT2D(rhs), z(0.0F) {
00741 }
00742
00744 FPOINT3D& operator= (
00745 const DPOINT3D& rhs
00746 );
00747
00749 FPOINT3D operator- (
00750 ) const { return (FPOINT3D(-x,-y,-z)); }
00751
00753 FPOINT3D operator+ (
00754 const FPOINT3D& rhs
00755 ) const { return (FPOINT3D(x+rhs.x,y+rhs.y,z+rhs.z)); }
00756
00758 FPOINT3D operator- (
00759 const FPOINT3D& rhs
00760 ) const { return (FPOINT3D(x-rhs.x,y-rhs.y,z-rhs.z)); }
00761
00763 FPOINT3D operator* (
00764 const float rhs
00765 ) const { return (FPOINT3D(x*rhs,y*rhs,z*rhs)); }
00766
00768 FPOINT3D operator/ (
00769 const float rhs
00770 ) const { return (FPOINT3D(x/rhs,y/rhs,z/rhs)); }
00771
00773 FPOINT3D operator+= (
00774 const FPOINT3D& rhs
00775 ) { x += rhs.x; y += rhs.y; z += rhs.z; return (*this); }
00776
00778 FPOINT3D operator-= (
00779 const FPOINT3D& rhs
00780 ) { x -= rhs.x; y -= rhs.y; z -= rhs.z; return (*this); }
00781
00783 FPOINT3D operator*= (
00784 const float rhs
00785 ) { x *= rhs; y *= rhs; z *= rhs; return (*this); }
00786
00788 FPOINT3D operator/= (
00789 const float rhs
00790 ) { x /= rhs; y /= rhs; z /= rhs; return (*this); }
00791
00793 DEPRECATED_MSG("Use GetDistance3D/2D to avoid ambiguity") float GetDistance (
00794 const FPOINT3D& pt
00795 ) const { return (GetDistance3D(pt)); }
00796
00798 DEPRECATED_MSG("Use GetDistanceSquared3D/2D to avoid ambiguity") float GetDistanceSquared (
00799 const FPOINT3D& pt
00800 ) const { return (GetDistanceSquared3D(pt)); }
00801
00803 float GetDistance3D (
00804 const FPOINT3D& pt
00805 ) const { return (static_cast<float>(sqrt(GetDistanceSquared3D(pt)))); }
00806
00808 float GetDistanceSquared3D (
00809 const FPOINT3D& pt
00810 ) const {
00811 float dx(pt.x - x);
00812 float dy(pt.y - y);
00813 float dz(pt.z - z);
00814 return (static_cast<float>(dx*dx + dy*dy + dz*dz));
00815 }
00816
00818 float GetMagnitude3D (
00819 ) const { return (static_cast<float>(sqrt(GetMagnitudeSquared3D()))); }
00820
00822 float GetMagnitudeSquared3D (
00823 ) const { return (static_cast<float>(x*x + y*y + z*z)); }
00824
00826 bool Normalize (
00827 ) {
00828 const float d = GetMagnitude3D();
00829 if (d == 0.0F) return false;
00830 *this /= d;
00831 return true;
00832 }
00833
00835 static bool Normalize (
00836 FPOINT3D& pt
00837 ) {
00838 const float d = pt.GetMagnitude3D();
00839 if (d == 0.0F) return false;
00840 pt /= d;
00841 return true;
00842 }
00843
00845 float DotProduct (
00846 const FPOINT3D& pt
00847 ) const { return (x*pt.x + y*pt.y + z*pt.z); }
00848
00850 FPOINT3D CrossProduct (
00851 const FPOINT3D& pt
00852 ) const { return (FPOINT3D(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x)); }
00853
00855 void SwapBytes (
00856 ) { ::SwapBytes(x); ::SwapBytes(y); ::SwapBytes(z); }
00857
00858 #ifndef GENERATING_DOXYGEN_OUTPUT
00859 CHECKSIZE(12);
00860 #endif
00861 };
00862
00864 inline bool operator== (
00865 const FPOINT3D& lhs,
00866 const FPOINT3D& rhs
00867 ) {
00868 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
00869 }
00870
00872 inline bool operator!= (
00873 const FPOINT3D& lhs,
00874 const FPOINT3D& rhs
00875 ) {
00876 return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z);
00877 }
00878
00880 inline void SwapBytes (
00881 FPOINT3D& pt
00882 ) {
00883 pt.SwapBytes();
00884 }
00885
00886
00887
00888
00890 struct DPOINT2D {
00891
00892 double x;
00893 double y;
00894
00896 DPOINT2D (
00897 ) { }
00898
00900 DPOINT2D (
00901 const double dx,
00902 const double dy
00903 ) : x(dx), y(dy) { }
00904
00906 DPOINT2D (
00907 const WPOINT2D& pt
00908 ) : x(pt.x), y(pt.y) { }
00909
00911 DPOINT2D (
00912 const LPOINT2D& pt
00913 ) : x(pt.x), y(pt.y) { }
00914
00916 DPOINT2D (
00917 const FPOINT2D& pt
00918 ) : x(pt.x), y(pt.y) { }
00919
00921 DPOINT2D (
00922 const DPOINT2D_OLD& pt
00923 ) : x(pt.x), y(pt.y) { }
00924
00926 DPOINT2D& operator= (
00927 const WPOINT2D& rhs
00928 ) { x = rhs.x; y = rhs.y; return (*this); }
00929
00931 DPOINT2D& operator= (
00932 const LPOINT2D& rhs
00933 ) { x = rhs.x; y = rhs.y; return (*this); }
00934
00936 DPOINT2D& operator= (
00937 const FPOINT2D& rhs
00938 ) { x = rhs.x; y = rhs.y; return (*this); }
00939
00941 DPOINT2D& operator= (
00942 const DPOINT2D_OLD& rhs
00943 ) { x = rhs.x; y = rhs.y; return (*this); }
00944
00946 DPOINT2D operator- (
00947 ) { return (DPOINT2D(-x,-y)); }
00948
00950 DPOINT2D operator+ (
00951 const DPOINT2D& rhs
00952 ) const { return (DPOINT2D(x+rhs.x,y+rhs.y)); }
00953
00955 DPOINT2D operator- (
00956 const DPOINT2D& rhs
00957 ) const { return (DPOINT2D(x-rhs.x,y-rhs.y)); }
00958
00960 DPOINT2D operator* (
00961 const double rhs
00962 ) const { return (DPOINT2D(x*rhs,y*rhs)); }
00963
00965 DPOINT2D operator/ (
00966 const double rhs
00967 ) const { return (DPOINT2D(x/rhs,y/rhs)); }
00968
00970 DPOINT2D operator+= (
00971 const DPOINT2D& rhs
00972 ) { x += rhs.x; y += rhs.y; return (*this); }
00973
00975 DPOINT2D operator-= (
00976 const DPOINT2D& rhs
00977 ) { x -= rhs.x; y -= rhs.y; return (*this); }
00978
00980 DPOINT2D operator*= (
00981 const double rhs
00982 ) { x *= rhs; y *= rhs; return (*this); }
00983
00985 DPOINT2D operator/= (
00986 const double rhs
00987 ) { x /= rhs; y /= rhs; return (*this); }
00988
00990 DPOINT2D ComputeMidpoint (
00991 const DPOINT2D& rhs
00992 ) const { return (DPOINT2D((x + rhs.x)/2.0, (y + rhs.y)/2.0)); }
00993
00995 double DotProduct (
00996 const DPOINT2D& pt
00997 ) const { return (x*pt.x + y*pt.y); }
00998
01000 double GetAngle (
01001 const DPOINT2D& pt
01002 ) const {
01003 double dx(pt.x - x);
01004 double dy(pt.y - y);
01005 if (dx == 0.0 && dy == 0.0) return (0.0);
01006 return (atan2(dy, dx));
01007 }
01008
01010 double GetAngle (
01011 ) const {
01012 if (x == 0.0 && y == 0.0) return (0.0);
01013 return (atan2(y, x));
01014 }
01015
01017 DEPRECATED_MSG("Use GetDistance2D") double GetDistance (
01018 const DPOINT2D& pt
01019 ) const { return (GetDistance2D(pt)); }
01020
01022 DEPRECATED_MSG("Use GetDistanceSquared2D") double GetDistanceSquared (
01023 const DPOINT2D& pt
01024 ) const { return (GetDistanceSquared2D(pt)); }
01025
01027 double GetDistance2D (
01028 const DPOINT2D& pt
01029 ) const { return (sqrt(GetDistanceSquared2D(pt))); }
01030
01032 double GetDistanceSquared2D (
01033 const DPOINT2D& pt
01034 ) const {
01035 double dx(pt.x - x);
01036 double dy(pt.y - y);
01037 return (dx*dx + dy*dy);
01038 }
01039
01041 double GetMagnitude2D (
01042 ) const { return (sqrt(GetMagnitudeSquared2D())); }
01043
01045 double GetMagnitudeSquared2D (
01046 ) const { return (x*x + y*y); }
01047
01050 double GetOrdinate (
01051 int index
01052 ) const { return (reinterpret_cast<const double*>(this)[index]); }
01053
01055 double GetX () const
01056 { return (x); }
01057
01059 double GetY () const
01060 { return (y); }
01061
01063 void Move (
01064 const double distance,
01065 const double azimuth
01066 ) {
01067 x += sin(azimuth * PI / 180) * distance;
01068 y += cos(azimuth * PI / 180) * distance;
01069 return;
01070 }
01071
01073 void Normalize (
01074 ) {
01075 double d = GetMagnitude2D();
01076 if (d != 0.0) {
01077 x /= d;
01078 y /= d;
01079 }
01080 }
01081
01083 LPOINT2D RoundToLongExact (
01084 ) const {
01085 return (LPOINT2D(FAST_ROUND_EXACT(x), FAST_ROUND_EXACT(y)));
01086 }
01087
01089 LPOINT2D RoundToLongLimited (
01090 ) const {
01091 return (LPOINT2D(FAST_ROUND_LIMITED(x), FAST_ROUND_LIMITED(y)));
01092 }
01093
01095 LPOINT2D RoundToLongNoLimit (
01096 ) const {
01097 return (LPOINT2D(FAST_ROUND_NOLIMIT(x), FAST_ROUND_NOLIMIT(y)));
01098 }
01099
01102 LPOINT2D RoundToLongPositive (
01103 ) const {
01104 return (LPOINT2D(FAST_ROUND_POSITIVE(x), FAST_ROUND_POSITIVE(y)));
01105 }
01106
01108 void Set (
01109 double ix,
01110 double iy
01111 ) { x = ix; y = iy; }
01112
01115 void SetOrdinate (
01116 int index,
01117 double value
01118 ) { reinterpret_cast<double*>(this)[index] = value; }
01119
01121 void SetX (
01122 double p_x
01123 ) { x = p_x; }
01124
01126 void SetY (
01127 double p_y
01128 ) { y = p_y; }
01129
01131 void Shift (
01132 const DPOINT2D& value
01133 ) {
01134 x += value.x;
01135 y += value.y;
01136 return;
01137 }
01138
01140 void Shift (
01141 const double xval,
01142 const double yval
01143 ) {
01144 x += xval;
01145 y += yval;
01146 return;
01147 }
01148
01150 void SwapBytes (
01151 ) { ::SwapBytes(x); ::SwapBytes(y); }
01152
01154 LPOINT2D TruncateToLong (
01155 ) const {
01156 return (LPOINT2D(FAST_TRUNCATE(x), FAST_TRUNCATE(y)));
01157 }
01158
01159 #ifndef GENERATING_DOXYGEN_OUTPUT
01160 CHECKSIZE(16);
01161 #endif
01162 };
01163
01164
01166 inline bool operator== (
01167 const DPOINT2D& lhs,
01168 const DPOINT2D& rhs
01169 ) {
01170 return (lhs.x == rhs.x && lhs.y == rhs.y);
01171 }
01172
01174 inline bool operator!= (
01175 const DPOINT2D& lhs,
01176 const DPOINT2D& rhs
01177 ) {
01178 return (lhs.x != rhs.x || lhs.y != rhs.y);
01179 }
01180
01182 inline bool operator< (
01183 const DPOINT2D& lhs,
01184 const DPOINT2D& rhs
01185 ) {
01186 return (lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y));
01187 }
01188
01190 inline bool operator> (
01191 const DPOINT2D& lhs,
01192 const DPOINT2D& rhs
01193 ) {
01194 return (lhs.x > rhs.x || (lhs.x == rhs.x && lhs.y > rhs.y));
01195 }
01196
01198 inline bool operator<= (
01199 const DPOINT2D& lhs,
01200 const DPOINT2D& rhs
01201 ) {
01202 return (lhs == rhs || lhs < rhs);
01203 }
01204
01206 inline bool operator>= (
01207 const DPOINT2D& lhs,
01208 const DPOINT2D& rhs
01209 ) {
01210 return (lhs == rhs || lhs > rhs);
01211 }
01212
01214 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, DPOINT2D& value) { return (_iniRead(hdl,group,field,INITYPE_DPOINT2D,&value,1)); }
01215
01217 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, DPOINT2D& value, const DPOINT2D& dft) { value = dft; return (IniRead(hdl,group,field,value)); }
01218
01220 inline int IniWrite (INIHANDLE hdl, const char *group, const char *field, const DPOINT2D& value) { return (_iniWrite(hdl,group,field,INITYPE_DPOINT2D,&value,1)); }
01221
01223 inline void SwapBytes (
01224 DPOINT2D& pt
01225 ) {
01226 pt.SwapBytes();
01227 }
01228
01229
01230
01231
01233 struct DPOINT3D : public DPOINT2D {
01234
01235 double z;
01236
01238 DPOINT3D (
01239 ) {
01240 }
01241
01243 DPOINT3D (
01244 const DPOINT3D& rhs
01245 ) : DPOINT2D(rhs.x, rhs.y), z(rhs.z) { }
01246
01248 DPOINT3D (
01249 const double dx,
01250 const double dy,
01251 const double dz
01252 ) : DPOINT2D(dx, dy), z(dz) { }
01253
01255 DPOINT3D (
01256 const DPOINT2D& rhs
01257 ) : DPOINT2D(rhs), z(0.0) { }
01258
01260 DPOINT3D (
01261 const DPOINT3D_OLD& rhs
01262 ) : DPOINT2D(rhs.x,rhs.y), z(rhs.z) { }
01263
01265 DPOINT3D& operator= (
01266 const DPOINT2D& rhs
01267 ) { x = rhs.x; y = rhs.y; z = 0.0; return (*this); }
01268
01270 DPOINT3D& operator= (
01271 const FPOINT3D& rhs
01272 ) { x = rhs.x; y = rhs.y; z = rhs.z; return (*this); }
01273
01275 DPOINT3D& operator= (
01276 const DPOINT3D_OLD& rhs
01277 ) { x = rhs.x; y = rhs.y; z = rhs.z; return (*this); }
01278
01280 DPOINT3D operator- (
01281 ) const { return (DPOINT3D(-x,-y,-z)); }
01282
01284 DPOINT3D operator+ (
01285 const DPOINT3D& rhs
01286 ) const { return (DPOINT3D(x+rhs.x,y+rhs.y,z+rhs.z)); }
01287
01289 DPOINT3D operator- (
01290 const DPOINT3D& rhs
01291 ) const { return (DPOINT3D(x-rhs.x,y-rhs.y,z-rhs.z)); }
01292
01294 DPOINT3D operator* (
01295 const double rhs
01296 ) const { return (DPOINT3D(x*rhs,y*rhs,z*rhs)); }
01297
01299 DPOINT3D operator/ (
01300 const double rhs
01301 ) const { return (DPOINT3D(x/rhs,y/rhs,z/rhs)); }
01302
01304 DPOINT3D operator+= (
01305 const DPOINT3D& rhs
01306 ) { x += rhs.x; y += rhs.y; z += rhs.z; return (*this); }
01307
01309 DPOINT3D operator-= (
01310 const DPOINT3D& rhs
01311 ) { x -= rhs.x; y -= rhs.y; z -= rhs.z; return (*this); }
01312
01314 DPOINT3D operator*= (
01315 const double rhs
01316 ) { x *= rhs; y *= rhs; z *= rhs; return (*this); }
01317
01319 DPOINT3D operator/= (
01320 const double rhs
01321 ) { x /= rhs; y /= rhs; z /= rhs; return (*this); }
01322
01324 DPOINT3D ComputeMidpoint (
01325 const DPOINT3D& rhs
01326 ) const { return (DPOINT3D((x + rhs.x)/2.0, (y + rhs.y)/2.0, (z + rhs.z)/2.0)); }
01327
01330 void CrossProduct (
01331 const DPOINT3D& in1,
01332 const DPOINT3D& in2
01333 ) {
01334 x = in1.y * in2.z - in2.y * in1.z;
01335 y = in1.z * in2.x - in2.z * in1.x;
01336 z = in1.x * in2.y - in2.x * in1.y;
01337 }
01338
01340 static double DotProduct (
01341 const DPOINT3D& in1,
01342 const DPOINT3D& in2
01343 ) {
01344 return (in1.x * in2.x + in1.y * in2.y + in1.z * in2.z);
01345 }
01346
01348 DEPRECATED_MSG("Use GetDistance3D/2D to avoid ambiguity") double GetDistance (
01349 const DPOINT3D& pt
01350 ) const { return (GetDistance3D(pt)); }
01351
01353 DEPRECATED_MSG("Use GetDistanceSquared3D/2D to avoid ambiguity") double GetDistanceSquared (
01354 const DPOINT3D& pt
01355 ) const { return (GetDistanceSquared3D(pt)); }
01356
01358 double GetDistance3D (
01359 const DPOINT3D& pt
01360 ) const { return (sqrt(GetDistanceSquared3D(pt))); }
01361
01363 double GetDistanceSquared3D (
01364 const DPOINT3D& pt
01365 ) const {
01366 double dx(pt.x - x);
01367 double dy(pt.y - y);
01368 double dz(pt.z - z);
01369 return (dx*dx + dy*dy + dz*dz);
01370 }
01371
01373 double GetMagnitude3D (
01374 ) const { return (sqrt(GetMagnitudeSquared3D())); }
01375
01377 double GetMagnitudeSquared3D (
01378 ) const { return (x*x + y*y + z*z); }
01379
01381 double GetZ () const
01382 { return (z); }
01383
01385 void Move (
01386 const double distance,
01387 const double azimuth,
01388 const double elevation
01389 ) {
01390 double delta = sqrt(distance*distance - elevation*elevation);
01391 x += sin(azimuth * PI / 180) * delta;
01392 y += cos(azimuth * PI / 180) * delta;
01393 z += elevation;
01394 return;
01395 }
01396
01398 void Normalize (
01399 ) {
01400 double d = GetMagnitude3D();
01401 if (d != 0.0) {
01402 x /= d;
01403 y /= d;
01404 z /= d;
01405 }
01406 }
01407
01408
01409 void Set (
01410 double ix,
01411 double iy,
01412 double iz
01413 ) { x = ix; y = iy; z = iz; }
01414
01416 void SetZ (
01417 double p_z
01418 ) { z = p_z; }
01419
01421 void Shift (
01422 const DPOINT3D& value
01423 ) { DPOINT2D::Shift(value); z += value.z; }
01424
01426 void Shift (
01427 const double xval,
01428 const double yval,
01429 const double zval
01430 ) { DPOINT2D::Shift(xval, yval); z += zval; }
01431
01433 void SwapBytes (
01434 ) { ::SwapBytes(x); ::SwapBytes(y); ::SwapBytes(z); }
01435
01436 #ifndef GENERATING_DOXYGEN_OUTPUT
01437 CHECKSIZE(24);
01438 #endif
01439 };
01440
01442 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, DPOINT3D& value) { return (_iniRead(hdl,group,field,INITYPE_DPOINT3D,&value,1)); }
01443
01445 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, DPOINT3D& value, const DPOINT3D& dft) { value = dft; return (IniRead(hdl,group,field,value)); }
01446
01448 inline int IniWrite (INIHANDLE hdl, const char *group, const char *field, const DPOINT3D& value) { return (_iniWrite(hdl,group,field,INITYPE_DPOINT3D,&value,1)); }
01449
01450
01451
01452
01454 struct FPOINT3DH {
01455
01456 float x;
01457 float y;
01458 float z;
01459 float w;
01460
01462 FPOINT3DH (
01463 ) : x(0.0F), y(0.0F), z(0.0F), w(1.0F) { }
01464
01466 FPOINT3DH (
01467 const float dx,
01468 const float dy,
01469 const float dz,
01470 const float dw = 1.0F
01471 ) : x(dx), y(dy), z(dz), w(dw) { }
01472
01474 FPOINT3DH (
01475 const FPOINT3D& p
01476 ) : x(p.x), y(p.y), z(p.z), w(1.0F) { }
01477
01479 FPOINT3DH& operator= (
01480 const FPOINT3D& rhs
01481 ) { x = rhs.x; y = rhs.y; z = rhs.z; w = 1.0F; return (*this); }
01482
01484 inline FPOINT3DH& operator= (
01485 const DPOINT3DH& rhs
01486 );
01487
01489 FPOINT3DH operator- (
01490 ) const { return (FPOINT3DH(-x,-y,-z,-w)); }
01491
01493 FPOINT3DH operator+ (
01494 const FPOINT3DH& rhs
01495 ) const { return (FPOINT3DH(x+rhs.x,y+rhs.y,z+rhs.z,w+rhs.w)); }
01496
01498 FPOINT3DH operator- (
01499 const FPOINT3DH& rhs
01500 ) const { return (FPOINT3DH(x-rhs.x,y-rhs.y,z-rhs.z,w-rhs.w)); }
01501
01503 FPOINT3DH operator* (
01504 const float rhs
01505 ) const { return (FPOINT3DH(x*rhs,y*rhs,z*rhs,w*rhs)); }
01506
01508 FPOINT3DH operator/ (
01509 const float rhs
01510 ) const { return (FPOINT3DH(x/rhs,y/rhs,z/rhs,w/rhs)); }
01511
01513 FPOINT3DH operator+= (
01514 const FPOINT3DH& rhs
01515 ) { x += rhs.x; y += rhs.y; z += rhs.z; w += rhs.w; return (*this); }
01516
01518 FPOINT3DH operator-= (
01519 const FPOINT3DH& rhs
01520 ) { x -= rhs.x; y -= rhs.y; z -= rhs.z; w -= rhs.w; return (*this); }
01521
01523 FPOINT3DH operator*= (
01524 const float rhs
01525 ) { x *= rhs; y *= rhs; z *= rhs; w *= rhs; return (*this); }
01526
01528 FPOINT3DH operator/= (
01529 const float rhs
01530 ) { x /= rhs; y /= rhs; z /= rhs; w /= rhs; return (*this); }
01531
01533 bool Get3D (
01534 FPOINT3D& point
01535 ) {
01536 if (w == 0.0F) return false;
01537 point.x = x / w;
01538 point.y = y / w;
01539 point.z = z / w;
01540 return true;
01541 }
01542
01544 bool Project (
01545 ) {
01546 if (w == 0.0F) return false;
01547 x /= w;
01548 y /= w;
01549 z /= w;
01550 w = 1.0F;
01551 return true;
01552 }
01553
01554 #ifndef GENERATING_DOXYGEN_OUTPUT
01555 CHECKSIZE(16);
01556 #endif
01557 };
01558
01559
01560
01561
01563 struct DPOINT3DH {
01564
01565 double x;
01566 double y;
01567 double z;
01568 double w;
01569
01571 DPOINT3DH (
01572 ) : x(0.0), y(0.0), z(0.0), w(1.0) { }
01573
01575 DPOINT3DH (
01576 const double dx,
01577 const double dy,
01578 const double dz,
01579 const double dw = 1.0
01580 ) : x(dx), y(dy), z(dz), w(dw) { }
01581
01583 DPOINT3DH (
01584 const DPOINT3D& p
01585 ) : x(p.x), y(p.y), z(p.z), w(1.0) { }
01586
01588 DPOINT3DH& operator= (
01589 const DPOINT3D& rhs
01590 ) { x = rhs.x; y = rhs.y; z = rhs.z; w = 1.0; return (*this); }
01591
01593 DPOINT3DH& operator= (
01594 const FPOINT3DH& rhs
01595 ) { x = rhs.x; y = rhs.y; z = rhs.z; w = rhs.w; return (*this); }
01596
01598 DPOINT3DH operator- (
01599 ) const { return (DPOINT3DH(-x,-y,-z,-w)); }
01600
01602 DPOINT3DH operator+ (
01603 const DPOINT3DH& rhs
01604 ) const { return (DPOINT3DH(x+rhs.x,y+rhs.y,z+rhs.z,w+rhs.w)); }
01605
01607 DPOINT3DH operator- (
01608 const DPOINT3DH& rhs
01609 ) const { return (DPOINT3DH(x-rhs.x,y-rhs.y,z-rhs.z,w-rhs.w)); }
01610
01612 DPOINT3DH operator* (
01613 const double rhs
01614 ) const { return (DPOINT3DH(x*rhs,y*rhs,z*rhs,w*rhs)); }
01615
01617 DPOINT3DH operator/ (
01618 const double rhs
01619 ) const { return (DPOINT3DH(x/rhs,y/rhs,z/rhs,w/rhs)); }
01620
01622 DPOINT3DH operator+= (
01623 const DPOINT3DH& rhs
01624 ) { x += rhs.x; y += rhs.y; z += rhs.z; w += rhs.w; return (*this); }
01625
01627 DPOINT3DH operator-= (
01628 const DPOINT3DH& rhs
01629 ) { x -= rhs.x; y -= rhs.y; z -= rhs.z; w -= rhs.w; return (*this); }
01630
01632 DPOINT3DH operator*= (
01633 const double rhs
01634 ) { x *= rhs; y *= rhs; z *= rhs; w *= rhs; return (*this); }
01635
01637 DPOINT3DH operator/= (
01638 const double rhs
01639 ) { x /= rhs; y /= rhs; z /= rhs; w /= rhs; return (*this); }
01640
01642 bool Get3D (
01643 DPOINT3D& point
01644 ) {
01645 if (w == 0.0) return false;
01646 point.x = x / w;
01647 point.y = y / w;
01648 point.z = z / w;
01649 return true;
01650 }
01651
01653 bool Project (
01654 ) {
01655 if (w == 0.0) return false;
01656 x /= w;
01657 y /= w;
01658 z /= w;
01659 w = 1.0;
01660 return true;
01661 }
01662
01663 #ifndef GENERATING_DOXYGEN_OUTPUT
01664 CHECKSIZE(32);
01665 #endif
01666 };
01667
01668
01670 inline bool operator== (
01671 const DPOINT3D& lhs,
01672 const DPOINT3D& rhs
01673 ) {
01674 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
01675 }
01676
01678 inline bool operator!= (
01679 const DPOINT3D& lhs,
01680 const DPOINT3D& rhs
01681 ) {
01682 return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z);
01683 }
01684
01686 inline bool operator< (
01687 const DPOINT3D& lhs,
01688 const DPOINT3D& rhs
01689 ) {
01690 return (lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y) || (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z < rhs.z));
01691 }
01692
01694 inline bool operator> (
01695 const DPOINT3D& lhs,
01696 const DPOINT3D& rhs
01697 ) {
01698 return (lhs.x > rhs.x || (lhs.x == rhs.x && lhs.y > rhs.y) || (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z > rhs.z));
01699 }
01700
01702 inline bool operator<= (
01703 const DPOINT3D& lhs,
01704 const DPOINT3D& rhs
01705 ) {
01706 return (lhs == rhs || lhs < rhs);
01707 }
01708
01710 inline bool operator>= (
01711 const DPOINT3D& lhs,
01712 const DPOINT3D& rhs
01713 ) {
01714 return (lhs == rhs || lhs > rhs);
01715 }
01716
01718 inline void SwapBytes (
01719 DPOINT3D& pt
01720 ) {
01721 pt.SwapBytes();
01722 }
01723
01724
01725
01726
01727 #ifndef GENERATING_DOXYGEN_OUTPUT
01728
01730 inline LPOINT2D::LPOINT2D (
01731 const DPOINT2D& pt
01732 ) : x(static_cast<INT32>(pt.x)), y(static_cast<INT32>(pt.y)) {
01733 }
01734
01736 inline LPOINT2D& LPOINT2D::operator= (
01737 const DPOINT2D& pt
01738 ) {
01739 x = static_cast<INT32>(pt.x);
01740 y = static_cast<INT32>(pt.y);
01741 return (*this);
01742 }
01743
01745 inline DPOINT2D_OLD& DPOINT2D_OLD::operator= (
01746 const DPOINT2D& rhs
01747 ) {
01748 x = rhs.x;
01749 y = rhs.y;
01750 return (*this);
01751 }
01752
01754 inline DPOINT3D_OLD& DPOINT3D_OLD::operator= (
01755 const DPOINT3D& rhs
01756 ) {
01757 x = rhs.x;
01758 y = rhs.y;
01759 z = rhs.z;
01760 return (*this);
01761 }
01762
01764 inline FPOINT2D& FPOINT2D::operator= (
01765 const DPOINT2D& rhs
01766 ) {
01767 x = static_cast<float>(rhs.x);
01768 y = static_cast<float>(rhs.y);
01769 return (*this);
01770 }
01771
01773 inline FPOINT3D& FPOINT3D::operator= (
01774 const DPOINT3D& rhs
01775 ) {
01776 x = static_cast<float>(rhs.x);
01777 y = static_cast<float>(rhs.y);
01778 z = static_cast<float>(rhs.z);
01779 return (*this);
01780 }
01781
01783 inline FPOINT3DH& FPOINT3DH::operator= (
01784 const DPOINT3DH& rhs
01785 ) {
01786 x = static_cast<float>(rhs.x);
01787 y = static_cast<float>(rhs.y);
01788 z = static_cast<float>(rhs.z);
01789 w = static_cast<float>(rhs.w);
01790 return (*this);
01791 }
01792
01793 #endif
01794
01795
01796
01797 #endif