xmscore  1.0
functors.h
Go to the documentation of this file.
1 #pragma once
2 //------------------------------------------------------------------------------
7 //------------------------------------------------------------------------------
8 
9 //----- Less than functors that use tolerances ---------------------------------
10 
11 #include <xmscore/math/math.h>
12 #include <xmscore/points/pt.h>
13 
14 namespace xms
15 {
19 template <typename T>
20 class ltPt3
21 {
22 private:
23  T m_xytol;
24  T m_ztol;
25 
26 public:
27  //----------------------------------------------------------------------------
31  //----------------------------------------------------------------------------
32  ltPt3(T a_xytol, T a_ztol)
33  : m_xytol(a_xytol)
34  , m_ztol(a_ztol)
35  {
36  } // ltPt3::ltPt3
37  //----------------------------------------------------------------------------
42  //----------------------------------------------------------------------------
43  bool operator()(const Pt3<T> lhs, const Pt3<T> rhs) const
44  {
45  if (EQ_TOL(lhs.x, rhs.x, m_xytol))
46  {
47  if (EQ_TOL(lhs.y, rhs.y, m_xytol))
48  {
49  if (EQ_TOL(lhs.z, rhs.z, m_ztol))
50  {
51  return false;
52  }
53  else if (LT_TOL(lhs.z, rhs.z, m_ztol))
54  return true;
55  else
56  return false;
57  }
58  else if (LT_TOL(lhs.y, rhs.y, m_xytol))
59  return true;
60  else
61  return false;
62  }
63  else if (LT_TOL(lhs.x, rhs.x, m_xytol))
64  return true;
65  else
66  return false;
67  } // operator()
68 }; // ltPt3
69 
73 template <typename T>
74 class ltPt3_2D
75 {
76 private:
77  double m_xytol;
78 
79 public:
80  //----------------------------------------------------------------------------
83  //----------------------------------------------------------------------------
84  ltPt3_2D(T a_xytol)
85  : m_xytol(a_xytol)
86  {
87  } // ltPt3_2D::ltPt3_2D
88  //----------------------------------------------------------------------------
93  //----------------------------------------------------------------------------
94  bool operator()(const Pt3<T> a_lhs, const Pt3<T> a_rhs) const
95  {
96  if (EQ_TOL(a_lhs.x, a_rhs.x, m_xytol))
97  {
98  if (EQ_TOL(a_lhs.y, a_rhs.y, m_xytol))
99  {
100  return false;
101  }
102  else if (LT_TOL(a_lhs.y, a_rhs.y, m_xytol))
103  return true;
104  else
105  return false;
106  }
107  else if (LT_TOL(a_lhs.x, a_rhs.x, m_xytol))
108  return true;
109  else
110  return false;
111  } // ltPt3_2D::operator()
112 }; // ltPt3_2D
113 
117 template <typename T>
118 class ltPt2
119 {
120 private:
121  double m_xytol;
122 
123 public:
124  //----------------------------------------------------------------------------
127  //----------------------------------------------------------------------------
128  ltPt2(T a_xytol)
129  : m_xytol(a_xytol)
130  {
131  } // ltPt2::ltPt2
132  //----------------------------------------------------------------------------
137  //----------------------------------------------------------------------------
138  bool operator()(const Pt2<T> a_lhs, const Pt2<T> a_rhs) const
139  {
140  if (EQ_TOL(a_lhs.x, a_rhs.x, m_xytol))
141  {
142  if (EQ_TOL(a_lhs.y, a_rhs.y, m_xytol))
143  {
144  return false;
145  }
146  else if (LT_TOL(a_lhs.y, a_rhs.y, m_xytol))
147  return true;
148  else
149  return false;
150  }
151  else if (LT_TOL(a_lhs.x, a_rhs.x, m_xytol))
152  return true;
153  else
154  return false;
155  } // ltPt2::operator()
156 }; // ltPt2
157 
161 
162 //------------------------------------------------------------------------------
166 //------------------------------------------------------------------------------
167 template <typename _T>
169 {
170  Pt2<_T> out;
171  out.x = static_cast<int>(a_in.x);
172  out.y = static_cast<int>(a_in.y);
173  return out;
174 }
175 //------------------------------------------------------------------------------
179 //------------------------------------------------------------------------------
180 template <typename _T>
182 {
183  Pt3<_T> out;
184  out.x = static_cast<int>(a_in.x);
185  out.y = static_cast<int>(a_in.y);
186  out.z = static_cast<int>(a_in.z);
187  return out;
188 }
189 //------------------------------------------------------------------------------
193 //------------------------------------------------------------------------------
194 template <typename _T>
196 {
197  Pt4<_T> out;
198  out.x = static_cast<int>(a_in.x);
199  out.y = static_cast<int>(a_in.y);
200  out.z = static_cast<int>(a_in.z);
201  out.w = static_cast<int>(a_in.w);
202  return out;
203 }
204 
205 } // namespace xms
T z
z coordinate
Definition: pt.h:799
double m_xytol
xy tolerance
Definition: functors.h:121
T z
z coordinate
Definition: pt.h:1584
ltPt2(T a_xytol)
constructor
Definition: functors.h:128
T x
x coordinate
Definition: pt.h:797
double m_xytol
xy tolerance
Definition: functors.h:77
ltPt3(T a_xytol, T a_ztol)
constructor
Definition: functors.h:32
less than Pt3 comparing in 2D, or, only x and y
Definition: functors.h:74
T x
x coordinate
Definition: pt.h:88
ltPt3_2D(T a_xytol)
constructor
Definition: functors.h:84
T w
w coordinate
Definition: pt.h:1585
T x
x coordinate
Definition: pt.h:1582
bool operator()(const Pt2< T > a_lhs, const Pt2< T > a_rhs) const
Tests only x and y.
Definition: functors.h:138
2D Point template class
Definition: pt.h:82
bool EQ_TOL(const _T &A, const _U &B, const _V &tolerance)
Returns true if A == B equal within a tolerance.
Definition: math.h:265
3d point template class
Definition: pt.h:791
T y
y coordinate
Definition: pt.h:89
T m_xytol
xy tolerance
Definition: functors.h:23
bool operator()(const Pt3< T > a_lhs, const Pt3< T > a_rhs) const
Tests only x and y.
Definition: functors.h:94
T m_ztol
z tolerance
Definition: functors.h:24
bool LT_TOL(_T A, _U B, _V tolerance)
Returns true if A < B equal within a tolerance.
Definition: math.h:277
T y
y coordinate
Definition: pt.h:798
less than Pt2
Definition: functors.h:118
T y
y coordinate
Definition: pt.h:1583
4D point template class
Definition: pt.h:1576
Pt2< _T > ptTruncate(Pt2< _T > const &a_in)
Truncate to an integer.
Definition: functors.h:168
bool operator()(const Pt3< T > lhs, const Pt3< T > rhs) const
does comparison
Definition: functors.h:43
less than Pt3
Definition: functors.h:20