QUAOAR STUDIO // Mobius API
core_XYZ.h
1 //-----------------------------------------------------------------------------
2 // Created on: 02 November 2013
3 //-----------------------------------------------------------------------------
4 // Copyright (c) 2017, Sergey Slyadnev
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Sergey Slyadnev nor the
16 // names of all contributors may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 // DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
23 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //-----------------------------------------------------------------------------
30 
31 #ifndef core_XYZ_HeaderFile
32 #define core_XYZ_HeaderFile
33 
34 // core includes
35 #include <mobius/core_Precision.h>
36 
37 // STL includes
38 #include <float.h>
39 
40 namespace mobius {
41 
45 class core_XYZ
46 {
47 // Static API:
48 public:
49 
51  static int num_coordinates()
52  {
53  return 3;
54  }
55 
56  mobiusCore_EXPORT static core_XYZ
57  O();
58 
59  mobiusCore_EXPORT static core_XYZ
60  OX();
61 
62  mobiusCore_EXPORT static core_XYZ
63  OY();
64 
65  mobiusCore_EXPORT static core_XYZ
66  OZ();
67 
68  mobiusCore_EXPORT static bool
69  AreSamePlane(const std::vector<core_XYZ>& dirs,
70  const double prec = core_Precision::Resolution3D());
71 
72  mobiusCore_EXPORT static bool
73  AreSpanningWholeSpace(const std::vector<core_XYZ>& dirs,
74  const double prec = core_Precision::Resolution3D());
75 
76 // Construction & destruction:
77 public:
78 
82  {
83  m_fX = m_fY = m_fZ = 0.0;
84  }
85 
90  core_XYZ(const double x,
91  const double y,
92  const double z)
93  {
94  m_fX = x;
95  m_fY = y;
96  m_fZ = z;
97  }
98 
101  core_XYZ(const core_XYZ& XYZ)
102  {
103  m_fX = XYZ.X();
104  m_fY = XYZ.Y();
105  m_fZ = XYZ.Z();
106  }
107 
110 
111 public:
112 
115  double X() const
116  {
117  return m_fX;
118  }
119 
122  void SetX(const double x)
123  {
124  m_fX = x;
125  }
126 
129  double Y() const
130  {
131  return m_fY;
132  }
133 
136  void SetY(const double y)
137  {
138  m_fY = y;
139  }
140 
143  double Z() const
144  {
145  return m_fZ;
146  }
147 
150  void SetZ(const double z)
151  {
152  m_fZ = z;
153  }
154 
158  void SetXYZ(const core_XYZ& other)
159  {
160  m_fX = other.m_fX;
161  m_fY = other.m_fY;
162  m_fZ = other.m_fZ;
163  }
164 
168  double Coord(const int idx) const
169  {
170  if ( idx == 0 )
171  return this->X();
172 
173  if ( idx == 1 )
174  return this->Y();
175 
176  if ( idx == 2 )
177  return this->Z();
178 
179  return FLT_MAX;
180  }
181 
186  double SetCoord(const int idx,
187  const double val)
188  {
189  double* coord = nullptr;
190 
191  if ( idx == 0 )
192  coord = &m_fX;
193  if ( idx == 1 )
194  coord = &m_fY;
195  if ( idx == 2 )
196  coord = &m_fZ;
197 
198  if ( coord )
199  *coord = val;
200 
201  return FLT_MAX;
202  }
203 
207  bool IsOrigin(const double tol3D = 0.) const
208  {
209  return ( fabs(m_fX) <= tol3D ) &&
210  ( fabs(m_fY) <= tol3D ) &&
211  ( fabs(m_fZ) <= tol3D );
212  }
213 
218  bool IsEqual(const core_XYZ& XYZ,
219  const double tol3D = 0.) const
220  {
221  return ( fabs( m_fX - XYZ.X() ) <= tol3D ) &&
222  ( fabs( m_fY - XYZ.Y() ) <= tol3D ) &&
223  ( fabs( m_fZ - XYZ.Z() ) <= tol3D );
224  }
225 
229  core_XYZ CWiseMin(const core_XYZ& XYZ) const
230  {
231  return core_XYZ(m_fX < XYZ.m_fX ? m_fX : XYZ.m_fX,
232  m_fY < XYZ.m_fY ? m_fY : XYZ.m_fY,
233  m_fZ < XYZ.m_fZ ? m_fZ : XYZ.m_fZ);
234  }
235 
239  core_XYZ CWiseMax(const core_XYZ& XYZ) const
240  {
241  return core_XYZ(m_fX > XYZ.m_fX ? m_fX : XYZ.m_fX,
242  m_fY > XYZ.m_fY ? m_fY : XYZ.m_fY,
243  m_fZ > XYZ.m_fZ ? m_fZ : XYZ.m_fZ);
244  }
245 
247  double GetMaxComponent() const
248  {
249  return m_fX > m_fY ? (m_fX > m_fZ ? m_fX : m_fZ)
250  : (m_fY > m_fZ ? m_fY : m_fZ);
251  }
252 
253 public:
254 
255  mobiusCore_EXPORT double
256  Modulus() const;
257 
258  mobiusCore_EXPORT double
259  SquaredModulus() const;
260 
261  mobiusCore_EXPORT core_XYZ
262  Multiplied(const double coeff) const;
263 
264  mobiusCore_EXPORT void
265  Normalize();
266 
267  mobiusCore_EXPORT core_XYZ
268  Normalized() const;
269 
270  mobiusCore_EXPORT void
271  Reverse();
272 
273  mobiusCore_EXPORT core_XYZ
274  Reversed() const;
275 
276  mobiusCore_EXPORT double
277  Dot(const core_XYZ& XYZ) const;
278 
279  mobiusCore_EXPORT core_XYZ
280  Cross(const core_XYZ& XYZ) const;
281 
282  mobiusCore_EXPORT double
283  Angle(const core_XYZ& XYZ) const;
284 
285  mobiusCore_EXPORT double
286  AngleWithRef(const core_XYZ& other,
287  const core_XYZ& ref) const;
288 
289 public:
290 
291  mobiusCore_EXPORT bool
292  operator==(const core_XYZ& XYZ) const;
293 
294  mobiusCore_EXPORT core_XYZ&
295  operator=(const core_XYZ& XYZ);
296 
297  mobiusCore_EXPORT core_XYZ
298  operator*(const double coeff) const;
299 
300  mobiusCore_EXPORT core_XYZ
301  operator*=(const double coeff);
302 
303  mobiusCore_EXPORT double
304  operator*(const core_XYZ& XYZ) const;
305 
306  mobiusCore_EXPORT core_XYZ
307  operator^(const core_XYZ& XYZ) const;
308 
309  mobiusCore_EXPORT core_XYZ
310  operator/(const double coeff) const;
311 
312  mobiusCore_EXPORT core_XYZ
313  operator/=(const double coeff);
314 
315  mobiusCore_EXPORT core_XYZ
316  operator+(const core_XYZ& XYZ) const;
317 
318  mobiusCore_EXPORT core_XYZ&
319  operator+=(const core_XYZ& XYZ);
320 
321  mobiusCore_EXPORT core_XYZ
322  Invert() const;
323 
324  mobiusCore_EXPORT core_XYZ
325  operator-(const core_XYZ& XYZ) const;
326 
327  mobiusCore_EXPORT core_XYZ&
328  operator-=(const core_XYZ& XYZ);
329 
330  mobiusCore_EXPORT void
331  Transform(const double (&mx)[3][3]);
332 
333 private:
334 
335  double m_fX;
336  double m_fY;
337  double m_fZ;
338 
339 };
340 
347 inline core_XYZ operator*(const double coeff, const core_XYZ& coords)
348 {
349  core_XYZ r = coords*coeff;
350  return r;
351 }
352 
356 typedef core_XYZ t_xyz;
357 
358 }
359 
360 #endif
mobius::core_XYZ::~core_XYZ
~core_XYZ()
Destructor.
Definition: core_XYZ.h:109
mobius
Defines an exception class C1 that inherits an exception class C2.
Definition: bspl_Decompose.h:41
mobius::core_XYZ
Definition: core_XYZ.h:45
mobius::core_XYZ::num_coordinates
static int num_coordinates()
Definition: core_XYZ.h:51
mobius::core_XYZ::core_XYZ
core_XYZ(const double x, const double y, const double z)
Definition: core_XYZ.h:90
mobius::core_XYZ::core_XYZ
core_XYZ()
Definition: core_XYZ.h:81
mobius::core_XYZ::Y
double Y() const
Definition: core_XYZ.h:129
mobius::operator*
core_UV operator*(const double coeff, const core_UV &coords)
Definition: core_UV.h:193
mobius::core_XYZ::IsOrigin
bool IsOrigin(const double tol3D=0.) const
Definition: core_XYZ.h:207
mobius::core_XYZ::SetY
void SetY(const double y)
Definition: core_XYZ.h:136
mobius::core_XYZ::SetXYZ
void SetXYZ(const core_XYZ &other)
Definition: core_XYZ.h:158
mobius::core_XYZ::core_XYZ
core_XYZ(const core_XYZ &XYZ)
Definition: core_XYZ.h:101
mobius::core_XYZ::Z
double Z() const
Definition: core_XYZ.h:143
mobius::t_xyz
core_XYZ t_xyz
Definition: core_XYZ.h:356
mobius::core_XYZ::CWiseMax
core_XYZ CWiseMax(const core_XYZ &XYZ) const
Definition: core_XYZ.h:239
mobius::core_XYZ::GetMaxComponent
double GetMaxComponent() const
Definition: core_XYZ.h:247
mobius::core_XYZ::SetCoord
double SetCoord(const int idx, const double val)
Definition: core_XYZ.h:186
mobius::core_XYZ::CWiseMin
core_XYZ CWiseMin(const core_XYZ &XYZ) const
Definition: core_XYZ.h:229
mobius::core_XYZ::SetZ
void SetZ(const double z)
Definition: core_XYZ.h:150
mobius::core_XYZ::Coord
double Coord(const int idx) const
Definition: core_XYZ.h:168
mobius::core_XYZ::IsEqual
bool IsEqual(const core_XYZ &XYZ, const double tol3D=0.) const
Definition: core_XYZ.h:218
mobius::core_XYZ::X
double X() const
Definition: core_XYZ.h:115
mobius::core_XYZ::SetX
void SetX(const double x)
Definition: core_XYZ.h:122