Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cPoint3.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cPoint3_H
8 #define _INC_cPoint3_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cPoint2.h"
14 #include "cRectI.h"
15 
16 namespace GrayLib
17 {
18  template <typename TYPE = float>
19  class GRAYLIB_LINK cPoint3T : public cVecT3<TYPE>
20  {
28 
29  typedef cVecT3<TYPE> SUPER_t;
30  typedef cPoint3T<TYPE> THIS_t;
31 
32  public:
34  {
35  // ASSUME TYPE = float ?
36  this->SetZero();
37  }
38 #if 1
39  cPoint3T(const SUPER_t& ptVal)
40  : cVecT3<TYPE>(ptVal)
41  {
42  }
43 #endif
44  cPoint3T(TYPE x, TYPE y, TYPE z = 0)
45  : cVecT3<TYPE>(x, y, z)
46  {
47  }
48  cPoint3T(const cVariant& vVal, int iArrayIndexStart = 0)
49  {
50  v_SetPoint(vVal, iArrayIndexStart);
51  }
52 
53  // validate the point
54  void InitInvalid()
55  {
56  this->m_x = this->m_y = this->m_z = k_FLT_MAX2;
57  }
58  bool IsValid2d() const
59  {
60  return this->m_x != k_FLT_MAX2 && this->m_y != k_FLT_MAX2;
61  }
62  bool IsValid() const
63  {
64  return this->m_x != k_FLT_MAX2 && this->m_y != k_FLT_MAX2 && this->m_z != k_FLT_MAX2;
65  }
66 
67  // compare the point.
68 
69  void Set(POINT pt)
70  {
71  this->m_x = (TYPE)pt.x;
72  this->m_y = (TYPE)pt.y;
73  this->m_z = 0; // NOTE: remember this is a nonsense value.
74  }
75  void Set(POINTS pt)
76  {
77  this->m_x = (TYPE)pt.x;
78  this->m_y = (TYPE)pt.y;
79  this->m_z = 0; // NOTE: remember this is a nonsense value.
80  }
81  POINT get_POINT() const
82  {
83  // int point.
84  POINT pt;
85  pt.x = (LONG)this->m_x;
86  pt.y = (LONG)this->m_y;
87  return pt;
88  }
89  operator POINT() const
90  {
91  return get_POINT();
92  }
93  POINTS get_POINTS() const
94  {
96  POINTS pt;
97  pt.x = (short)this->m_x;
98  pt.y = (short)this->m_y;
99  return pt;
100  }
101  operator POINTS() const
102  {
103  return get_POINTS();
104  }
105 
107  {
108  return cVecT2<TYPE>(this->m_x, this->m_y);
109  }
110 
111  void MoveDir(DIR_TYPE eDir)
112  {
114  ASSERT(IS_INDEX_GOOD(eDir, DIR_QTY + 1));
115  this->m_x += cDirectionDef::k_Directions[eDir].m_dx;
116  this->m_y += cDirectionDef::k_Directions[eDir].m_dy;
117  }
118  void MoveDirN(DIR_TYPE eDir, float nSteps)
119  {
121  ASSERT(IS_INDEX_GOOD(eDir, DIR_QTY + 1));
122  this->m_x += cDirectionDef::k_Directions[eDir].m_dx * nSteps;
123  this->m_y += cDirectionDef::k_Directions[eDir].m_dy * nSteps;
124  }
125 
126  TYPE GetDirZ(const SUPER_t& pt) const
127  {
129  TYPE dx = pt.m_x - this->m_x;
130  TYPE dy = pt.m_y - this->m_y;
131  return Calc::ATan2(dx, dy);
132  }
134  {
135  // Downcast to 2d point. reinterpret_cast
136  return (cVecT2<TYPE>&)(this->m_x);
137  }
138 
139  ITERATE_t v_SetPoint(const cVariant& vVal, ITERATE_t iArrayIndexStart = 0); // set this from a variant, x,y,z
140  ITERATE_t v_AddPoint(OUT cVariant& vVal) const; // get this as a variant
141 
142  cString get_StringI3() const;
143  bool put_MapCoord(cString sVal);
144 
146  {
147  // If the point is the index for a Hash Table (2D).
148  return((((HASHCODE_t)this->m_y) << 16) | ((HASHCODE_t)this->m_x));
149  }
150  };
151 
154 
155 }
156 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
#define TYPE
Definition: StrT.cpp:38
#define ASSERT(exp)
Definition: cDebugAssert.h:87
short m_dx
-1,0,+1 = Cos(angle)
Definition: cDirectionDef.h:56
static const cDirectionDef k_Directions[DIR_QTY+1]
Definition: cDirectionDef.h:51
short m_dy
-1,0,+1 = Sin(angle)
Definition: cDirectionDef.h:57
Definition: cPoint3.h:20
cPoint3T(TYPE x, TYPE y, TYPE z=0)
Definition: cPoint3.h:44
POINT get_POINT() const
Definition: cPoint3.h:81
cPoint3T()
Definition: cPoint3.h:33
HASHCODE_t get_HashCode2() const
Definition: cPoint3.h:145
void MoveDirN(DIR_TYPE eDir, float nSteps)
Definition: cPoint3.h:118
void MoveDir(DIR_TYPE eDir)
Definition: cPoint3.h:111
cVecT2< TYPE > get_Point2() const
Definition: cPoint3.h:106
void Set(POINT pt)
Definition: cPoint3.h:69
cVecT2< TYPE > & get_Point2f()
Definition: cPoint3.h:133
cPoint3T(const SUPER_t &ptVal)
Definition: cPoint3.h:39
void InitInvalid()
Definition: cPoint3.h:54
cPoint3T(const cVariant &vVal, int iArrayIndexStart=0)
Definition: cPoint3.h:48
bool IsValid() const
Definition: cPoint3.h:62
bool IsValid2d() const
Definition: cPoint3.h:58
POINTS get_POINTS() const
Definition: cPoint3.h:93
TYPE GetDirZ(const SUPER_t &pt) const
Definition: cPoint3.h:126
void Set(POINTS pt)
Definition: cPoint3.h:75
Definition: cVariant.h:26
Definition: cVecT.h:473
Definition: cVecT.h:530
TYPE m_x
Definition: cVecT.h:544
TYPE m_y
Definition: cVecT.h:544
Definition: cMesh.h:22
cPoint3T< double > cPoint3d
Definition: cPoint3.h:153
DIR_TYPE
Definition: cDirectionDef.h:25
@ DIR_QTY
Also means "Center".
Definition: cDirectionDef.h:38
cPoint3T< float > cPoint3f
Definition: cPoint3.h:152
int ITERATE_t
like size_t but signed
Definition: Index.h:28
UINT_PTR HASHCODE_t
could hold a pointer converted to a number? maybe 64 or 32 bit ? same as size_t.
Definition: GrayCore.h:116
static TYPE ATan2(TYPE y, TYPE x)