Atoms Crowd  7.0.0
ImathShear.h
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 //
7 // A representation of a shear transformation
8 //
9 
10 #ifndef INCLUDED_ATOMSMATHSHEAR_H
11 #define INCLUDED_ATOMSMATHSHEAR_H
12 
13 #include <AtomsMath/ImathMath.h>
14 #include <AtomsMath/ImathNamespace.h>
15 #include <AtomsMath/ImathVec.h>
16 #include <iostream>
17 
18 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
19 
112 
113 template <class T> class Shear6
114 {
115  public:
116 
119 
120  T xy, xz, yz, yx, zx, zy;
121 
123 
125  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T& operator[] (int i);
126 
128  ATOMSMATH_HOSTDEVICE constexpr const T& operator[] (int i) const;
129 
132 
134  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6();
135 
137  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (T XY, T XZ, T YZ);
138 
140  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (const Vec3<T>& v);
141 
143  template <class S>
144  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (const Vec3<S>& v);
145 
147  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (T XY,
148  T XZ,
149  T YZ,
150  T YX,
151  T ZX,
152  T ZY);
153 
155  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (const Shear6& h);
156 
158  template <class S> ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6 (const Shear6<S>& h);
159 
161  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator= (const Shear6& h);
162 
164  template <class S>
165  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator= (const Vec3<S>& v);
166 
168  ~Shear6() = default;
169 
171 
174 
176  template <class S> ATOMSMATH_HOSTDEVICE void setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY);
177 
179  template <class S> ATOMSMATH_HOSTDEVICE void setValue (const Shear6<S>& h);
180 
182  template <class S>
183  ATOMSMATH_HOSTDEVICE void getValue (S& XY, S& XZ, S& YZ, S& YX, S& ZX, S& ZY) const;
184 
186  template <class S> ATOMSMATH_HOSTDEVICE void getValue (Shear6<S>& h) const;
187 
189  ATOMSMATH_HOSTDEVICE T* getValue();
190 
192  ATOMSMATH_HOSTDEVICE const T* getValue() const;
193 
195 
198 
200  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator== (const Shear6<S>& h) const;
201 
203  template <class S> ATOMSMATH_HOSTDEVICE constexpr bool operator!= (const Shear6<S>& h) const;
204 
209  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError (const Shear6<T>& h, T e) const;
210 
215  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError (const Shear6<T>& h, T e) const;
216 
218  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator+= (const Shear6& h);
219 
221  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator+ (const Shear6& h) const;
222 
224  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator-= (const Shear6& h);
225 
227  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator- (const Shear6& h) const;
228 
230  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator-() const;
231 
233  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& negate();
234 
236  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator*= (const Shear6& h);
238  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator*= (T a);
239 
241  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator* (const Shear6& h) const;
242 
244  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator* (T a) const;
245 
247  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator/= (const Shear6& h);
248 
250  ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6& operator/= (T a);
251 
253  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator/ (const Shear6& h) const;
254 
256  ATOMSMATH_HOSTDEVICE constexpr Shear6 operator/ (T a) const;
257 
259 
262 
264  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeLowest() noexcept { return std::numeric_limits<T>::lowest(); }
265 
267  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeMax() noexcept { return std::numeric_limits<T>::max(); }
268 
270  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeSmallest() noexcept { return std::numeric_limits<T>::min(); }
271 
273  ATOMSMATH_HOSTDEVICE constexpr static T baseTypeEpsilon() noexcept { return std::numeric_limits<T>::epsilon(); }
274 
276 
278  ATOMSMATH_HOSTDEVICE constexpr static unsigned int dimensions() { return 6; }
279 
282  typedef T BaseType;
283 };
284 
286 template <class T> std::ostream& operator<< (std::ostream& s, const Shear6<T>& h);
287 
289 template <class S, class T>
290 ATOMSMATH_HOSTDEVICE constexpr Shear6<T> operator* (S a, const Shear6<T>& h);
291 
293 typedef Vec3<float> Shear3f;
294 
296 typedef Vec3<double> Shear3d;
297 
299 typedef Shear6<float> Shear6f;
300 
302 typedef Shear6<double> Shear6d;
303 
304 //-----------------------
305 // Implementation of Shear6
306 //-----------------------
307 
308 template <class T>
309 ATOMSMATH_CONSTEXPR14 inline T&
311 {
312  return (&xy)[i]; // NOSONAR - suppress SonarCloud bug report.
313 }
314 
315 template <class T>
316 constexpr inline const T&
318 {
319  return (&xy)[i]; // NOSONAR - suppress SonarCloud bug report.
320 }
321 
322 template <class T> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6()
323 {
324  xy = xz = yz = yx = zx = zy = 0;
325 }
326 
327 template <class T> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (T XY, T XZ, T YZ)
328 {
329  xy = XY;
330  xz = XZ;
331  yz = YZ;
332  yx = 0;
333  zx = 0;
334  zy = 0;
335 }
336 
337 template <class T> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (const Vec3<T>& v)
338 {
339  xy = v.x;
340  xz = v.y;
341  yz = v.z;
342  yx = 0;
343  zx = 0;
344  zy = 0;
345 }
346 
347 template <class T> template <class S> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (const Vec3<S>& v)
348 {
349  xy = T (v.x);
350  xz = T (v.y);
351  yz = T (v.z);
352  yx = 0;
353  zx = 0;
354  zy = 0;
355 }
356 
357 template <class T> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (T XY, T XZ, T YZ, T YX, T ZX, T ZY)
358 {
359  xy = XY;
360  xz = XZ;
361  yz = YZ;
362  yx = YX;
363  zx = ZX;
364  zy = ZY;
365 }
366 
367 template <class T> ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (const Shear6& h)
368 {
369  xy = h.xy;
370  xz = h.xz;
371  yz = h.yz;
372  yx = h.yx;
373  zx = h.zx;
374  zy = h.zy;
375 }
376 
377 template <class T>
378 template <class S>
379 ATOMSMATH_CONSTEXPR14 inline Shear6<T>::Shear6 (const Shear6<S>& h)
380 {
381  xy = T (h.xy);
382  xz = T (h.xz);
383  yz = T (h.yz);
384  yx = T (h.yx);
385  zx = T (h.zx);
386  zy = T (h.zy);
387 }
388 
389 template <class T>
390 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
392 {
393  xy = h.xy;
394  xz = h.xz;
395  yz = h.yz;
396  yx = h.yx;
397  zx = h.zx;
398  zy = h.zy;
399  return *this;
400 }
401 
402 template <class T>
403 template <class S>
404 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
406 {
407  xy = T (v.x);
408  xz = T (v.y);
409  yz = T (v.z);
410  yx = 0;
411  zx = 0;
412  zy = 0;
413  return *this;
414 }
415 
416 template <class T>
417 template <class S>
418 inline void
419 Shear6<T>::setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY)
420 {
421  xy = T (XY);
422  xz = T (XZ);
423  yz = T (YZ);
424  yx = T (YX);
425  zx = T (ZX);
426  zy = T (ZY);
427 }
428 
429 template <class T>
430 template <class S>
431 inline void
433 {
434  xy = T (h.xy);
435  xz = T (h.xz);
436  yz = T (h.yz);
437  yx = T (h.yx);
438  zx = T (h.zx);
439  zy = T (h.zy);
440 }
441 
442 template <class T>
443 template <class S>
444 inline void
445 Shear6<T>::getValue (S& XY, S& XZ, S& YZ, S& YX, S& ZX, S& ZY) const
446 {
447  XY = S (xy);
448  XZ = S (xz);
449  YZ = S (yz);
450  YX = S (yx);
451  ZX = S (zx);
452  ZY = S (zy);
453 }
454 
455 template <class T>
456 template <class S>
457 inline void
459 {
460  h.xy = S (xy);
461  h.xz = S (xz);
462  h.yz = S (yz);
463  h.yx = S (yx);
464  h.zx = S (zx);
465  h.zy = S (zy);
466 }
467 
468 template <class T>
469 inline T*
471 {
472  return (T*) &xy;
473 }
474 
475 template <class T>
476 inline const T*
478 {
479  return (const T*) &xy;
480 }
481 
482 template <class T>
483 template <class S>
484 constexpr inline bool
485 Shear6<T>::operator== (const Shear6<S>& h) const
486 {
487  return xy == h.xy && xz == h.xz && yz == h.yz && yx == h.yx && zx == h.zx && zy == h.zy;
488 }
489 
490 template <class T>
491 template <class S>
492 constexpr inline bool
493 Shear6<T>::operator!= (const Shear6<S>& h) const
494 {
495  return xy != h.xy || xz != h.xz || yz != h.yz || yx != h.yx || zx != h.zx || zy != h.zy;
496 }
497 
498 template <class T>
499 ATOMSMATH_CONSTEXPR14 inline bool
501 {
502  for (int i = 0; i < 6; i++)
503  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], h[i], e))
504  return false;
505 
506  return true;
507 }
508 
509 template <class T>
510 ATOMSMATH_CONSTEXPR14 inline bool
512 {
513  for (int i = 0; i < 6; i++)
514  if (!ATOMSMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], h[i], e))
515  return false;
516 
517  return true;
518 }
519 
520 template <class T>
521 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
523 {
524  xy += h.xy;
525  xz += h.xz;
526  yz += h.yz;
527  yx += h.yx;
528  zx += h.zx;
529  zy += h.zy;
530  return *this;
531 }
532 
533 template <class T>
534 constexpr inline Shear6<T>
536 {
537  return Shear6 (xy + h.xy, xz + h.xz, yz + h.yz, yx + h.yx, zx + h.zx, zy + h.zy);
538 }
539 
540 template <class T>
541 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
543 {
544  xy -= h.xy;
545  xz -= h.xz;
546  yz -= h.yz;
547  yx -= h.yx;
548  zx -= h.zx;
549  zy -= h.zy;
550  return *this;
551 }
552 
553 template <class T>
554 constexpr inline Shear6<T>
556 {
557  return Shear6 (xy - h.xy, xz - h.xz, yz - h.yz, yx - h.yx, zx - h.zx, zy - h.zy);
558 }
559 
560 template <class T>
561 constexpr inline Shear6<T>
563 {
564  return Shear6 (-xy, -xz, -yz, -yx, -zx, -zy);
565 }
566 
567 template <class T>
568 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
570 {
571  xy = -xy;
572  xz = -xz;
573  yz = -yz;
574  yx = -yx;
575  zx = -zx;
576  zy = -zy;
577  return *this;
578 }
579 
580 template <class T>
581 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
583 {
584  xy *= h.xy;
585  xz *= h.xz;
586  yz *= h.yz;
587  yx *= h.yx;
588  zx *= h.zx;
589  zy *= h.zy;
590  return *this;
591 }
592 
593 template <class T>
594 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
596 {
597  xy *= a;
598  xz *= a;
599  yz *= a;
600  yx *= a;
601  zx *= a;
602  zy *= a;
603  return *this;
604 }
605 
606 template <class T>
607 constexpr inline Shear6<T>
609 {
610  return Shear6 (xy * h.xy, xz * h.xz, yz * h.yz, yx * h.yx, zx * h.zx, zy * h.zy);
611 }
612 
613 template <class T>
614 constexpr inline Shear6<T>
616 {
617  return Shear6 (xy * a, xz * a, yz * a, yx * a, zx * a, zy * a);
618 }
619 
620 template <class T>
621 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
623 {
624  xy /= h.xy;
625  xz /= h.xz;
626  yz /= h.yz;
627  yx /= h.yx;
628  zx /= h.zx;
629  zy /= h.zy;
630  return *this;
631 }
632 
633 template <class T>
634 ATOMSMATH_CONSTEXPR14 inline const Shear6<T>&
636 {
637  xy /= a;
638  xz /= a;
639  yz /= a;
640  yx /= a;
641  zx /= a;
642  zy /= a;
643  return *this;
644 }
645 
646 template <class T>
647 constexpr inline Shear6<T>
649 {
650  return Shear6 (xy / h.xy, xz / h.xz, yz / h.yz, yx / h.yx, zx / h.zx, zy / h.zy);
651 }
652 
653 template <class T>
654 constexpr inline Shear6<T>
656 {
657  return Shear6 (xy / a, xz / a, yz / a, yx / a, zx / a, zy / a);
658 }
659 
660 //-----------------------------
661 // Stream output implementation
662 //-----------------------------
663 
664 template <class T>
665 std::ostream&
666 operator<< (std::ostream& s, const Shear6<T>& h)
667 {
668  return s << '(' << h.xy << ' ' << h.xz << ' ' << h.yz << h.yx << ' ' << h.zx << ' ' << h.zy
669  << ')';
670 }
671 
672 //-----------------------------------------
673 // Implementation of reverse multiplication
674 //-----------------------------------------
675 
676 template <class S, class T>
677 constexpr inline Shear6<T>
678 operator* (S a, const Shear6<T>& h)
679 {
680  return Shear6<T> (a * h.xy, a * h.xz, a * h.yz, a * h.yx, a * h.zx, a * h.zy);
681 }
682 
683 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
684 
685 #endif // INCLUDED_ATOMSMATHSHEAR_H
Definition: ImathShear.h:114
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeLowest() noexcept
Largest possible negative value.
Definition: ImathShear.h:264
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithAbsError(const Shear6< T > &h, T e) const
Definition: ImathShear.h:500
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeSmallest() noexcept
Smallest possible positive value.
Definition: ImathShear.h:270
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6(const Vec3< S > &v)
Initialize to the given XY, XZ, YZ values held in (v.x, v.y, v.z)
constexpr static ATOMSMATH_HOSTDEVICE unsigned int dimensions()
Return the number of dimensions, i.e. 6.
Definition: ImathShear.h:278
~Shear6()=default
Destructor.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & operator-=(const Shear6 &h)
Component-wise subtraction.
Definition: ImathShear.h:542
constexpr ATOMSMATH_HOSTDEVICE Shear6 operator*(const Shear6 &h) const
Component-wise multiplication.
Definition: ImathShear.h:608
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & operator=(const Shear6 &h)
Assignment.
Definition: ImathShear.h:391
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & operator*=(const Shear6 &h)
Component-wise multiplication.
Definition: ImathShear.h:582
constexpr ATOMSMATH_HOSTDEVICE Shear6 operator/(const Shear6 &h) const
Component-wise division.
Definition: ImathShear.h:648
constexpr ATOMSMATH_HOSTDEVICE bool operator!=(const Shear6< S > &h) const
Inequality.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 T & operator[](int i)
Element access.
Definition: ImathShear.h:310
constexpr ATOMSMATH_HOSTDEVICE Shear6 operator+(const Shear6 &h) const
Component-wise addition.
Definition: ImathShear.h:535
ATOMSMATH_HOSTDEVICE T * getValue()
Return a raw pointer to the array of values.
Definition: ImathShear.h:470
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6()
Initialize to 0.
Definition: ImathShear.h:322
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & operator/=(const Shear6 &h)
Component-wise division.
Definition: ImathShear.h:622
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeMax() noexcept
Largest possible positive value.
Definition: ImathShear.h:267
ATOMSMATH_HOSTDEVICE void setValue(S XY, S XZ, S YZ, S YX, S ZX, S ZY)
Set the value.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & negate()
Component-wise multiplication by -1.
Definition: ImathShear.h:569
ATOMSMATH_HOSTDEVICE void getValue(Shear6< S > &h) const
Return the value in h
constexpr ATOMSMATH_HOSTDEVICE bool operator==(const Shear6< S > &h) const
Equality.
constexpr static ATOMSMATH_HOSTDEVICE T baseTypeEpsilon() noexcept
Smallest possible e for which 1+e != 1.
Definition: ImathShear.h:273
T BaseType
Definition: ImathShear.h:282
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Shear6(const Shear6< S > &h)
Construct from a Shear6 object of another base type.
ATOMSMATH_HOSTDEVICE void getValue(S &XY, S &XZ, S &YZ, S &YX, S &ZX, S &ZY) const
Return the values.
constexpr ATOMSMATH_HOSTDEVICE Shear6 operator-() const
Component-wise multiplication by -1.
Definition: ImathShear.h:562
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool equalWithRelError(const Shear6< T > &h, T e) const
Definition: ImathShear.h:511
ATOMSMATH_HOSTDEVICE void setValue(const Shear6< S > &h)
Set the value.
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Shear6 & operator+=(const Shear6 &h)
Component-wise addition.
Definition: ImathShear.h:522
Definition: ImathVec.h:260