Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
2DPoint.h
Go to the documentation of this file.
1//! @file 2DPoint.h
2//! @brief C2DTPoint template class for handling x, y 2D point coordinate
3//
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_2DPOINT_H__15665001_0D39_11D3_A380_9A856250DB28__INCLUDED_)
7#define AFX_2DPOINT_H__15665001_0D39_11D3_A380_9A856250DB28__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "Point.h"
14
15BEGIN_MOOTOOLS_NAMESPACE
16
17//! @class C2DTPoint
18//! @brief The class defines an x, y 2D point which can use int, float or double
19//!
20//! @tparam TYPE
21//! Can be int (C2DPointI), float (C2DPoint or C2DPointF) or double (C2DPointD)
22 template<class TYPE> class C2DTPoint : public CPt
23{
24public:
25 TYPE x, y;
26
27public:
28 C2DTPoint();
29 C2DTPoint(int refx, int refy);
30 C2DTPoint(float refx, float refy);
31 C2DTPoint(double refx, double refy);
32
33 virtual void Serialize(CXArchive& ar);
34 virtual CPt& operator=(const CPt& refpoint);
35 virtual void To4DPoint(C4DPoint& pt) const;
36
37 virtual CPt& operator=(const C4DPoint& pt);
38 bool operator==(const C2DTPoint& src) const;
39
40#ifdef _DEBUG
41 virtual bool IsKindOf(unsigned int classid) const;
42 virtual unsigned int ClassID() const;
43#endif
44};
45
46
47/////////////////////////////////////////////////////////////////////
48// Specialization
49//////////////////////////////////////////////////////////////////////
50#ifdef _DEBUG
51template<> inline unsigned int C2DTPoint<float>::ClassID() const
52{
53 return MAKE_CUSTOM_ID('2', 'D', 'P', 'F');
54}
55
56template<> inline unsigned int C2DTPoint<double>::ClassID() const
57{
58 return MAKE_CUSTOM_ID('2', 'D', 'P', 'D');
59}
60
61template<> inline bool C2DTPoint<float>::IsKindOf(unsigned int classid) const
62{
63 if (C2DTPoint<float>::ClassID() == classid)
64 return true;
65
66 return CPt::IsKindOf(classid);
67}
68
69template<> inline bool C2DTPoint<double>::IsKindOf(unsigned int classid) const
70{
71 if (C2DTPoint<double>::ClassID() == classid)
72 return true;
73
74 return CPt::IsKindOf(classid);
75}
76
77//template unsigned int C2DTPoint<float>::ClassID() const;
78//template unsigned int C2DTPoint<double>::ClassID() const;
79//template bool C2DTPoint<float>::IsKindOf(unsigned int classid) const;
80//template bool C2DTPoint<double>::IsKindOf(unsigned int classid) const;
81#endif
82
83//////////////////////////////////////////////////////////////////////
84// Implementation
85//////////////////////////////////////////////////////////////////////
86
87template<class TYPE>
89{
90 x = (TYPE)0.0;
91 y = (TYPE)0.0;
92}
93
94template<class TYPE>
95inline C2DTPoint<TYPE>::C2DTPoint(int refx, int refy)
96{
97 x = (TYPE)refx;
98 y = (TYPE)refy;
99}
100
101template<class TYPE>
102inline C2DTPoint<TYPE>::C2DTPoint(float refx, float refy)
103{
104 x = (TYPE)refx;
105 y = (TYPE)refy;
106}
107
108template<class TYPE>
109inline C2DTPoint<TYPE>::C2DTPoint(double refx, double refy)
110{
111 x = (TYPE)refx;
112 y = (TYPE)refy;
113}
114
115template<class TYPE> void C2DTPoint<TYPE>::Serialize(CXArchive& ar)
116{
117 CPt::Serialize(ar);
118
119 if(ar.IsStoring())
120 {
121 ar << x;
122 ar << y;
123 }
124 else
125 {
126 ar >> x;
127 ar >> y;
128 }
129}
130
131template<class TYPE> CPt& C2DTPoint<TYPE>::operator=(const CPt& refpoint)
132{
133 XASSERT(refpoint.IsKindOf(C2DTPoint::ClassID()));
134
135 x = ((C2DTPoint&)refpoint).x;
136 y = ((C2DTPoint&)refpoint).y;
137
138 return CPt::operator=(refpoint);
139}
140
141template<class TYPE>
142inline bool C2DTPoint<TYPE>::operator==(const C2DTPoint & src) const
143{
144 if (x != src.x || y != src.y)
145 return false;
146
147 return true;
148}
149
150template<class TYPE>
151inline void C2DTPoint<TYPE>::To4DPoint(C4DPoint& pt) const
152{
153 pt.size = 2;
154 pt.value[0] = x;
155 pt.value[1] = y;
156}
157
158template<class TYPE>
159inline CPt& C2DTPoint<TYPE>::operator=(const C4DPoint& pt)
160{
161 XASSERT(pt.size == 2);
162 x = (TYPE)pt.value[0];
163 y = (TYPE)pt.value[1];
164 return *this;
165}
166
167#ifdef _DEBUG
168template<class TYPE> bool C2DTPoint<TYPE>::IsKindOf(unsigned int classid) const
169{
170 if (C2DTPoint::ClassID() == classid)
171 return true;
172
173 return CPt::IsKindOf(classid);
174}
175
176template<class TYPE> unsigned int C2DTPoint<TYPE>::ClassID() const
177{
178 return MAKE_CUSTOM_ID('2', 'D', 'P', 'T');
179}
180
181#endif
182
183END_MOOTOOLS_NAMESPACE
184
185#endif // !defined(AFX_2DPOINT_H__15665001_0D39_11D3_A380_9A856250DB28__INCLUDED_)
CPt class is the base class for different class of points (C3DPoint, CUVWPoint...)
The class defines an x, y 2D point which can use int, float or double.
Definition 2DPoint.h:23
Definition 4DPoint.h:17
CPt base only contains some flags that are used by the derived class.
Definition Point.h:60
Definition XArchive.h:17