HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Vector4.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Utility Library (C++)
7  *
8  * COMMENTS:
9  * This class handles fpreal vectors of dimension 4.
10  *
11  * WARNING:
12  * This class should NOT contain any virtual methods, nor should it
13  * define more member data. The size of UT_Vector4 must always be
14  * 16 bytes (4 floats).
15  *
16  */
17 
18 #pragma once
19 
20 #ifndef __UT_Vector4_h__
21 #define __UT_Vector4_h__
22 
23 #include "UT_API.h"
24 #include "UT_Assert.h"
25 #include "UT_FixedVectorTraits.h"
26 #include "UT_Storage.h"
27 #include "UT_FixedArrayMath.h"
28 #include "UT_VectorTypes.h"
29 #include <SYS/SYS_Deprecated.h>
30 #include <SYS/SYS_Inline.h>
31 #include <SYS/SYS_Math.h>
32 #include <iosfwd>
33 #include <limits>
34 
35 #ifndef UT_DISABLE_VECTORIZE_MATRIX
36 #include <VM/VM_SIMD.h>
37 #endif
38 
39 class UT_IStream;
40 class UT_JSONWriter;
41 class UT_JSONValue;
42 class UT_JSONParser;
43 
44 // Free floating functions:
45 
46 // Right-multiply operators (M*v) have been removed. They had previously
47 // been defined to return v*M, which was too counterintuitive. Once HDK
48 // etc. users have a chance to update their code (post 7.0) we could
49 // reintroduce a right-multiply operator that does a colVecMult.
50 
51 template <typename T, typename S>
52 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, const UT_Matrix4T<S> &m);
53 template <typename T>
54 constexpr UT_Vector4T<T> operator+(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept;
55 template <typename T>
56 constexpr UT_Vector4T<T> operator-(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept;
57 template <typename T, typename S>
58 inline UT_Vector4T<T> operator+(const UT_Vector4T<T> &v, S scalar);
59 template <typename T, typename S>
60 inline UT_Vector4T<T> operator-(const UT_Vector4T<T> &v, S scalar);
61 template <typename T, typename S>
62 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, S scalar);
63 template <typename T, typename S>
64 inline UT_Vector4T<T> operator/(const UT_Vector4T<T> &v, S scalar);
65 template <typename T, typename S>
66 inline UT_Vector4T<T> operator+(S scalar, const UT_Vector4T<T> &v);
67 template <typename T, typename S>
68 inline UT_Vector4T<T> operator-(S scalar, const UT_Vector4T<T> &v);
69 template <typename T, typename S>
70 constexpr UT_Vector4T<T> operator*(S scalar, const UT_Vector4T<T> &v) noexcept;
71 template <typename T, typename S>
72 inline UT_Vector4T<T> operator/(S scalar, const UT_Vector4T<T> &v);
73 
74 /// Although the cross product is undefined for 4D vectors, we believe it's
75 /// useful in practice to define a function that takes two 4D vectors and
76 /// computes the cross-product of their first 3 components
77 template <typename T>
79 template <typename T>
81 template <typename T>
83 
84 /// The dot product between two vectors
85 // @{
86 template <typename T>
87 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector3T<T> &v2);
88 template <typename T>
89 inline T dot(const UT_Vector3T<T> &v1, const UT_Vector4T<T> &v2);
90 // @}
91 
92 /// Componentwise min and maximum
93 template <typename T>
94 inline UT_Vector4T<T> SYSmin (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
95 template <typename T>
96 inline UT_Vector4T<T> SYSmax (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
97 /// Componentwise equality.
98 template <typename T, typename S>
99 inline bool SYSisEqual(const UT_Vector4T<T> &a, const UT_Vector4T<T> &b, S tol = SYS_FTOLERANCE);
100 
101 /// Componentwise integer test
102 template <typename T>
103 inline bool SYSisInteger(const UT_Vector4T<T> &v1)
104 { return SYSisInteger(v1.x()) && SYSisInteger(v1.y()) && SYSisInteger(v1.z()) && SYSisInteger(v1.w()); }
105 
106 /// Componentwise linear interpolation
107 template <typename T,typename S>
108 inline UT_Vector4T<T> SYSlerp(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S t);
109 
110 template <typename T>
112 
113 /// Bilinear interpolation
114 template <typename T,typename S>
115 inline UT_Vector4T<T> SYSbilerp(const UT_Vector4T<T> &u0v0, const UT_Vector4T<T> &u1v0,
116  const UT_Vector4T<T> &u0v1, const UT_Vector4T<T> &u1v1,
117  S u, S v)
118 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
119 
120 /// Barycentric interpolation
121 template <typename T, typename S>
123  const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S u, S v)
124 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
125 
126 
127 /// Multiplication of a row or column vector by a matrix (ie. right vs. left
128 /// multiplication respectively). The operator*() declared above is an alias
129 /// for rowVecMult().
130 // @{
131 //
132 // Notes on optimisation of matrix/vector multiplies:
133 // - multiply(dest, mat) functions have been deprecated in favour of
134 // rowVecMult/colVecMult routines, which produce temporaries. For these to
135 // offer comparable performance, the compiler has to optimize away the
136 // temporary, but most modern compilers can do this. Performance tests with
137 // gcc3.3 indicate that this is a realistic expectation for modern
138 // compilers.
139 // - since matrix/vector multiplies cannot be done without temporary data,
140 // the "primary" functions are the global matrix/vector
141 // rowVecMult/colVecMult routines, rather than the member functions.
142 // - inlining is explicitly requested only for functions involving the
143 // native types (UT_Vector4 and UT_Matrix4)
144 template <typename T, typename S>
146 template <typename T, typename S>
148 
149 template <typename T, typename S>
151 template <typename T, typename S>
153 // @}
154 
155 /// Compute the distance between two points
156 // @{
157 template <typename T>
158 inline T distance4(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
159 template <typename T>
160 inline T distance3(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
161 template <typename T>
162 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2)
163 { return distance3(p1, p2); }
164 template <typename T>
165 inline T distance3d(const UT_Vector3T<T> &p1, const UT_Vector4T<T> &p2)
166 { return distance3d(p1, UT_Vector3T<T>(p2)); }
167 template <typename T>
168 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector3T<T> &p2)
169 { return distance3d(UT_Vector3T<T>(p1), p2); }
170 // @}
171 
172 /// 4D Vector class.
173 template <typename T>
175 {
176 public:
177  typedef T value_type;
178  static constexpr int tuple_size = 4;
179 
180  /// Default constructor.
181  /// No data is initialized! Use it for extra speed.
182  constexpr SYS_FORCE_INLINE UT_Vector4T() = default;
183 
184  constexpr SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T<T> &that) = default;
185  constexpr SYS_FORCE_INLINE UT_Vector4T(UT_Vector4T<T> &&that) = default;
186 
187  constexpr SYS_FORCE_INLINE UT_Vector4T(const T vx, const T vy, const T vz, const T vw = 1.0f) :
188  vec{ vx, vy, vz, vw }
189  {}
190 
191  constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[]) noexcept :
192  UT_Vector4T( v[0], v[1], v[2], v[3] )
193  {}
194  constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[]) noexcept :
195  UT_Vector4T( v[0], v[1], v[2], v[3] )
196  {}
197  constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[]) noexcept :
198  UT_Vector4T( v[0], v[1], v[2], v[3] )
199  {}
200  constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[]) noexcept :
201  UT_Vector4T( v[0], v[1], v[2], v[3] )
202  {}
203 
204  // Initialises the vector as [x,y,0,1]
206  constexpr explicit UT_Vector4T(const UT_Vector2T<T> &v) noexcept;
207 
208  constexpr explicit UT_Vector4T(const UT_Vector3T<T> &v, T w = 1.f) noexcept;
209 
210  /// Our own type of any given value_type.
211  template <typename S>
212  constexpr SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T<S>& v) noexcept :
213  UT_Vector4T( v[0], v[1], v[2], v[3] )
214  {}
215 
216  SYS_FORCE_INLINE UT_Vector4T<T> &operator=(const UT_Vector4T<T> &that) = default;
217  SYS_FORCE_INLINE UT_Vector4T<T> &operator=(UT_Vector4T<T> &&that) = default;
218 
219  template <typename S>
221  { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3];
222  return *this; }
223 
224  constexpr SYS_FORCE_INLINE const T* data() const noexcept
225  {
226  return vec;
227  }
228 
229  constexpr SYS_FORCE_INLINE T* data() noexcept
230  {
231  return vec;
232  }
233 
234  constexpr SYS_FORCE_INLINE const T& operator[]( exint i ) const noexcept
235  {
236  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
237 
238  return vec[ i ];
239  }
240 
241  constexpr SYS_FORCE_INLINE T& operator[]( exint i ) noexcept
242  {
243  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
244 
245  return vec[ i ];
246  }
247 
248  constexpr SYS_FORCE_INLINE UT_Vector4T& operator+=( const UT_Vector4T& a ) noexcept
249  {
250  UT::FA::Add< T, tuple_size >{}( vec, a.vec );
251  return *this;
252  }
253 
254  constexpr SYS_FORCE_INLINE UT_Vector4T& operator-=( const UT_Vector4T& a ) noexcept
255  {
256  UT::FA::Subtract< T, tuple_size >{}( vec, a.vec );
257  return *this;
258  }
259 
260  constexpr SYS_FORCE_INLINE UT_Vector4T& operator*=( const T& a ) noexcept
261  {
263  return *this;
264  }
265 
266  constexpr SYS_FORCE_INLINE UT_Vector4T& operator/=( const T& a ) noexcept
267  {
268  using MF = UT_StorageMathFloat_t< T >;
269  UT::FA::Scale< T, tuple_size, MF >{}( vec, MF{1} / a );
270  return *this;
271  }
272 
273  constexpr SYS_FORCE_INLINE UT_Vector4T& operator*=( const UT_Vector4T& a ) noexcept
274  {
276  return *this;
277  }
278 
279  constexpr SYS_FORCE_INLINE void negate() noexcept
280  {
282  }
283 
284  constexpr SYS_FORCE_INLINE T length2() const noexcept
285  {
286  return UT::FA::Length2< T, tuple_size >{}( vec );
287  }
288 
289  constexpr SYS_FORCE_INLINE T length() const noexcept
290  {
291  return SYSsqrt( length2() );
292  }
293 
294  constexpr SYS_FORCE_INLINE T distance2( const UT_Vector4T& b ) const noexcept
295  {
296  return UT::FA::Distance2< T, tuple_size >{}( vec, b.vec );
297  }
298 
299  constexpr SYS_FORCE_INLINE T distance( const UT_Vector4T& b ) const noexcept
300  {
301  return SYSsqrt( distance2( b ) );
302  }
303 
305  {
306  using MF = UT_StorageMathFloat_t< T >;
309  }
310 
311  constexpr SYS_FORCE_INLINE bool isZero() const noexcept
312  {
314  }
315 
316  constexpr SYS_FORCE_INLINE UT_Vector4T& operator=( const T a ) noexcept;
317 
318  // TODO: We could remove this. It's not as error-prone as some other
319  // conversions, but it might still be better to force the user to do
320  // an explicit cast i.e., v4 = UT_Vector4(v3)
321 
322  /// Assignment operator that creates a V4 from a V3 by adding a '1'
323  /// element.
324  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit UT_Vector4 constructor to avoid implicit conversion from UT_Vector3)
325  UT_Vector4T<T> &operator=(const UT_Vector3T<T> &v);
326 
327  int equalZero3(T tol = 0.00001f) const
328  {
329  return (vec[0] >= -tol && vec[0] <= tol) &&
330  (vec[1] >= -tol && vec[1] <= tol) &&
331  (vec[2] >= -tol && vec[2] <= tol);
332  }
333 
334  void clampZero(T tol = 0.00001f)
335  {
336  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
337  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
338  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
339  if (vec[3] >= -tol && vec[3] <= tol) vec[3] = 0;
340  }
341 
342  void clampZero3(T tol = 0.00001f)
343  {
344  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
345  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
346  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
347  }
348 
349  void negate3()
350  { vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2]; }
351 
353  {
354  vec[0] *= v.vec[0];
355  vec[1] *= v.vec[1];
356  vec[2] *= v.vec[2];
357  vec[3] *= v.vec[3];
358  }
359 
360  constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
361  {
362  return UT::FA::AllOf< T, tuple_size >{}( vec, [ & ]( const T& a ) { return SYSisFinite( a ); } );
363  }
364 
365  constexpr SYS_FORCE_INLINE bool equalZero( const T tolerance = SYS_FTOLERANCE ) const noexcept
366  {
367  return UT::FA::MaxNormIsLEQ< T, tuple_size >{}( vec, tolerance );
368  }
369 
370  constexpr SYS_FORCE_INLINE bool isEqual( const UT_Vector4T& b, const T tolerance = SYS_FTOLERANCE ) const noexcept
371  {
372  return UT::FA::MaxMetricIsLEQ< T, tuple_size >{}( vec, b.vec, tolerance );
373  }
374 
375  constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
376  {
377  return UT::FA::Max< T, tuple_size >{}( vec );
378  }
379 
380  constexpr SYS_FORCE_INLINE T minComponent() const noexcept
381  {
382  return UT::FA::Min< T, tuple_size >{}( vec );
383  }
384 
385  constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
386  {
387  return UT::FA::Sum< T, tuple_size >{}( vec ) / T{ tuple_size };
388  }
389 
390  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit conversion to UT_Vector3 followed by isEqual)
391  inline int isEqual(const UT_Vector3T<T> &vect, T tol = 0.00001f) const;
392 
393  /// If you need a multiplication operator that left multiplies the vector
394  /// by a matrix (M * v), use the following colVecMult() functions. If
395  /// you'd rather not use operator*=() for right-multiplications (v * M),
396  /// use the following rowVecMult() functions.
397  // @{
398  template <typename S>
399  inline void rowVecMult(const UT_Matrix4T<S> &m)
400  { operator=(::rowVecMult(*this, m)); }
401  template <typename S>
402  inline void colVecMult(const UT_Matrix4T<S> &m)
403  { operator=(::colVecMult(m, *this)); }
404  // @}
405 
406  /// This multiply will ignore the 4th component both in the vector an in
407  /// the matrix. This helps when you want to avoid affecting the 'w'
408  /// component. This in turns annihilates the translation components (row 4)
409  /// in mat, so be careful.
410  // @{
411  template <typename S>
413  { operator=(::rowVecMult3(*this, m)); }
414  // @}
415 
416  // The *= and multiply3 routines are provided for
417  // legacy reasons. They all assume that *this is a row vector. Generally,
418  // the rowVecMult and colVecMult methods are preferred, since they're
419  // more explicit about the row vector assumption.
420  // @{
421  template <typename S>
422  inline
424  { rowVecMult(mat); return *this; }
425 
426  template <typename S>
427  inline void multiply3(const UT_Matrix4T<S> &mat)
428  { rowVecMult3(mat); }
429  template <typename S>
430  inline void multiply3(UT_Vector4T<T> &dest, const UT_Matrix4T<S> &mat) const
431  { dest = ::rowVecMult3(*this, mat); }
432  // @}
433 
434  /// These allow you to find out what indices to use for different axes
435  // @{
436  int findMinAbsAxis() const
437  {
438  if (SYSabs(x()) < SYSabs(y()))
439  if (SYSabs(z()) < SYSabs(x()))
440  if (SYSabs(w()) < SYSabs(z()))
441  return 3;
442  else
443  return 2;
444  else
445  if (SYSabs(w()) < SYSabs(x()))
446  return 3;
447  else
448  return 0;
449  else
450  if (SYSabs(z()) < SYSabs(y()))
451  if (SYSabs(w()) < SYSabs(z()))
452  return 3;
453  else
454  return 2;
455  else
456  if (SYSabs(w()) < SYSabs(y()))
457  return 3;
458  else
459  return 1;
460  }
461  int findMaxAbsAxis() const
462  {
463  if (SYSabs(x()) >= SYSabs(y()))
464  if (SYSabs(z()) >= SYSabs(x()))
465  if (SYSabs(w()) >= SYSabs(z()))
466  return 3;
467  else
468  return 2;
469  else
470  if (SYSabs(w()) >= SYSabs(x()))
471  return 3;
472  else
473  return 0;
474  else
475  if (SYSabs(z()) >= SYSabs(y()))
476  if (SYSabs(w()) >= SYSabs(z()))
477  return 3;
478  else
479  return 2;
480  else
481  if (SYSabs(w()) >= SYSabs(y()))
482  return 3;
483  else
484  return 1;
485  }
486  // @}
487 
488  /// Return the components of the vector. The () operator does NOT check
489  /// for the boundary condition.
490  // @{
491  constexpr SYS_FORCE_INLINE T &x() noexcept { return vec[0]; }
492  constexpr SYS_FORCE_INLINE T x() const noexcept { return vec[0]; }
493  constexpr SYS_FORCE_INLINE T &y() noexcept { return vec[1]; }
494  constexpr SYS_FORCE_INLINE T y() const noexcept { return vec[1]; }
495  constexpr SYS_FORCE_INLINE T &z() noexcept { return vec[2]; }
496  constexpr SYS_FORCE_INLINE T z() const noexcept { return vec[2]; }
497  constexpr SYS_FORCE_INLINE T &w() noexcept { return vec[3]; }
498  constexpr SYS_FORCE_INLINE T w() const noexcept { return vec[3]; }
499 
500  inline T &operator()(unsigned i)
501  {
502  UT_ASSERT_P(i < tuple_size);
503  return vec[i];
504  }
505  inline T operator()(unsigned i) const
506  {
507  UT_ASSERT_P(i < tuple_size);
508  return vec[i];
509  }
510  // @}
511 
512  constexpr SYS_FORCE_INLINE T dot( const UT_Vector4T& b ) const noexcept
513  {
514  return UT::FA::Dot< T, tuple_size >{}( vec, b.vec );
515  }
516 
517  /// Compute a hash
518  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
519 
520  // TODO: eliminate these methods. They're redundant, given good inline
521  // constructors.
522  /// Set the values of the vector components
523  void assign(T xx = 0.0f, T yy = 0.0f, T zz = 0.0f,
524  T ww = 1.0f)
525  {
526  vec[0] = xx; vec[1] = yy; vec[2] = zz; vec[3] = ww;
527  }
528  /// Set the values of the vector components
529  void assign(const T *v, int size = tuple_size)
530  {
531  vec[0] = v[0];
532  vec[1] = v[1];
533  vec[2] = v[2];
534  if (size == tuple_size) vec[3] = v[3];
535  }
536 
537  /// Express the point in homogeneous coordinates or vice-versa
538  // @{
539  void homogenize()
540  {
541  vec[0] *= vec[3];
542  vec[1] *= vec[3];
543  vec[2] *= vec[3];
544  }
546  {
547  if (vec[3] != 0)
548  {
549  T denom = 1.0f / vec[3];
550  vec[0] *= denom;
551  vec[1] *= denom;
552  vec[2] *= denom;
553  }
554  }
555  // @}
556 
557  void save(std::ostream &os, int binary=0) const;
558  bool load(UT_IStream &is);
559 
560  /// @{
561  /// Methods to serialize to a JSON stream. The vector is stored as an
562  /// array of 4 reals.
563  bool save(UT_JSONWriter &w) const;
564  bool save(UT_JSONValue &v) const;
565  bool load(UT_JSONParser &p);
566  /// @}
567 
568  /// Returns the vector size
569  static int entries() { return tuple_size; }
570 
571  T vec[tuple_size];
572 
573 private:
574 
575  friend constexpr bool isZero( const UT_Vector4T& a ) noexcept
576  {
578  }
579 
580  friend constexpr auto dot( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
581  {
582 #ifndef UT_DISABLE_VECTORIZE_MATRIX
583  if constexpr( SYS_IsSame_v< T, float > )
584  {
585  return dot4( v4uf( a.data() ), v4uf( b.data() ) );
586  }
587  else // constexpr
588  {
589  return UT::FA::Dot< T, tuple_size >{}( a.vec, b.vec );
590  }
591 #else
592  return UT::FA::Dot< T, tuple_size >{}( a.vec, b.vec );
593 #endif
594  }
595 
596  friend constexpr auto length2( const UT_Vector4T& a ) noexcept
597  {
598  return UT::FA::Length2< T, tuple_size >{}( a.vec );
599  }
600 
601  friend constexpr auto distance2( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
602  {
603  return UT::FA::Distance2< T, tuple_size >{}( a.vec, b.vec );
604  }
605 
606  friend constexpr bool operator==( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
607  {
608  return UT::FA::AreEqual< T, tuple_size >{}( a.vec, b.vec );
609  }
610 
611  friend constexpr bool operator!=( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
612  {
613  return ! UT::FA::AreEqual< T, tuple_size >{}( a.vec, b.vec );
614  }
615 
616  /// Lexicographic order comparison operators
617  /// @{
618  friend constexpr bool operator<( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
619  {
620  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) < 0;
621  }
622 
623  friend constexpr bool operator<=( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
624  {
625  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) <= 0;
626  }
627 
628  friend constexpr bool operator>( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
629  {
630  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) > 0;
631  }
632 
633  friend constexpr bool operator>=( const UT_Vector4T& a, const UT_Vector4T& b ) noexcept
634  {
635  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) >= 0;
636  }
637  /// @}
638 
639  /// I/O friends
640  // @{
641  friend std::ostream &operator<<(std::ostream &os, const UT_Vector4T<T> &v)
642  {
643  v.save(os);
644  return os;
645  }
646  // @}
647 
648  /// The negate operator is not provided, because of potentially
649  /// unintuitive behaviour: you very rarely actually want to negate the
650  /// w component.
651  UT_Vector4T<T> operator-() const
652  {
653  UT_ASSERT(0);
654  UT_Vector4T a(*this);
655  a.negate();
656  return a;
657  }
658 };
659 
660 #include "UT_Vector2.h"
661 #include "UT_Vector3.h"
662 
663 template <typename T>
664 constexpr UT_Vector4T<T>::UT_Vector4T(const UT_Vector2T<T> &v) noexcept
665 {
666  vec[0] = v.x();
667  vec[1] = v.y();
668  vec[2] = T(0);
669  vec[3] = T(1);
670 }
671 template <typename T>
672 constexpr UT_Vector4T<T>::UT_Vector4T(const UT_Vector3T<T> &v, T vw) noexcept
673 {
674  vec[0] = v.x();
675  vec[1] = v.y();
676  vec[2] = v.z();
677  vec[3] = vw;
678 }
679 
680 template <typename T>
682 {
683  for ( int i = 0; i != tuple_size; ++i )
684  {
685  vec[i] = a;
686  }
687 
688  return *this;
689 }
690 
691 #ifndef UT_DISABLE_VECTORIZE_MATRIX
692 template <> inline void
694 {
695  v4uf l(this->data());
696  const v4uf r(v.data());
697  l *= r;
698 
699  vm_store(this->data(), l.vector);
700 }
701 #endif
702 
703 template <typename T>
704 inline int
705 UT_Vector4T<T>::isEqual(const UT_Vector3T<T> &vect, T tol) const
706 {
707  return ((vec[0]>=vect.x()-tol) && (vec[0]<=vect.x()+tol) &&
708  (vec[1]>=vect.y()-tol) && (vec[1]<=vect.y()+tol) &&
709  (vec[2]>=vect.z()-tol) && (vec[2]<=vect.z()+tol));
710 }
711 
712 // Free floating functions:
713 template <typename T>
714 constexpr UT_Vector4T<T> operator+(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept
715 {
716  return UT_Vector4T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
717  v1.z()+v2.z(), v1.w()+v2.w());
718 }
719 template <typename T>
721 {
722  return UT_Vector3T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
723  v1.z()+v2.z());
724 }
725 template <typename T>
727 {
728  return UT_Vector3T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
729  v1.z()+v2.z());
730 }
731 template <typename T>
732 constexpr UT_Vector4T<T> operator-(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept
733 {
734  return UT_Vector4T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
735  v1.z()-v2.z(), v1.w()-v2.w());
736 }
737 template <typename T>
739 {
740  return UT_Vector3T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
741  v1.z()-v2.z());
742 }
743 template <typename T>
745 {
746  return UT_Vector3T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
747  v1.z()-v2.z());
748 }
749 template <typename T>
751 {
752  return UT_Vector4T<T>(v1.x()*v2.x(), v1.y()*v2.y(), v1.z()*v2.z(), v1.w()*v2.w());
753 }
754 
755 template <typename T>
757 {
758  return UT_Vector4T<T>(v1.x()/v2.x(), v1.y()/v2.y(), v1.z()/v2.z(), v1.w()/v2.w());
759 }
760 #ifndef UT_DISABLE_VECTORIZE_MATRIX
761 template <>
763 {
764  const v4uf l(v1.data());
765  const v4uf r(v2.data());
766  const v4uf result = l * r;
767  return UT_Vector4T<float>((float*) &result);
768 }
769 template <>
771 {
772  const v4uf l(v1.data());
773  const v4uf r(v2.data());
774  const v4uf result = l / r;
775  return UT_Vector4T<float>((float*) &result);
776 }
777 #endif
778 
779 template <typename T, typename S>
780 inline UT_Vector4T<T> operator+(const UT_Vector4T<T> &v, S scalar)
781 {
782  return UT_Vector4T<T>(v.x()+scalar, v.y()+scalar, v.z()+scalar, v.w()+scalar);
783 }
784 template <typename T, typename S>
785 inline UT_Vector4T<T> operator+(S scalar, const UT_Vector4T<T> &v)
786 {
787  return UT_Vector4T<T>(v.x()+scalar, v.y()+scalar, v.z()+scalar, v.w()+scalar);
788 }
789 template <typename T, typename S>
790 inline UT_Vector4T<T> operator-(const UT_Vector4T<T> &v, S scalar)
791 {
792  return UT_Vector4T<T>(v.x()-scalar, v.y()-scalar, v.z()-scalar, v.w()-scalar);
793 }
794 template <typename T, typename S>
795 inline UT_Vector4T<T> operator-(S scalar, const UT_Vector4T<T> &v)
796 {
797  return UT_Vector4T<T>(scalar-v.x(), scalar-v.y(), scalar-v.z(), v.w()-scalar);
798 }
799 template <typename T, typename S>
800 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, S scalar)
801 {
802  return UT_Vector4T<T>(v.x()*scalar, v.y()*scalar, v.z()*scalar, v.w()*scalar);
803 }
804 template <typename T, typename S>
805 constexpr UT_Vector4T<T> operator*(S scalar, const UT_Vector4T<T> &v) noexcept
806 {
807  return UT_Vector4T<T>(v.x()*scalar, v.y()*scalar, v.z()*scalar, v.w()*scalar);
808 }
809 template <typename T, typename S>
810 inline UT_Vector4T<T> operator/(const UT_Vector4T<T> &v, S scalar)
811 {
812  // This has to be T because S may be int for "v = v/2" code
813  // For the same reason we must cast the 1
814  T inv = ((T)1) / scalar;
815  return UT_Vector4T<T>(v.x()*inv, v.y()*inv, v.z()*inv, v.w()*inv);
816 }
817 template <typename T, typename S>
818 inline UT_Vector4T<T> operator/(S scalar, const UT_Vector4T<T> &v)
819 {
820  return UT_Vector4T<T>(scalar/v.x(), scalar/v.y(), scalar/v.z(), scalar/v.w());
821 }
822 
823 template <typename T>
824 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector3T<T> &v2)
825 {
826  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
827 }
828 template <typename T>
829 inline T dot(const UT_Vector3T<T> &v1, const UT_Vector4T<T> &v2)
830 {
831  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
832 }
833 template <typename T>
834 inline
836 {
837  return UT_Vector4T<T>(
838  SYSabs(v.x()),
839  SYSabs(v.y()),
840  SYSabs(v.z()),
841  SYSabs(v.w())
842  );
843 }
844 
845 template <typename T>
846 inline
848 {
849  return UT_Vector4T<T>(
850  SYSmin(v1.x(), v2.x()),
851  SYSmin(v1.y(), v2.y()),
852  SYSmin(v1.z(), v2.z()),
853  SYSmin(v1.w(), v2.w())
854  );
855 }
856 
857 template <typename T>
858 inline
860 {
861  return UT_Vector4T<T>(
862  SYSmax(v1.x(), v2.x()),
863  SYSmax(v1.y(), v2.y()),
864  SYSmax(v1.z(), v2.z()),
865  SYSmax(v1.w(), v2.w())
866  );
867 }
868 
869 template <typename T, typename S>
870 inline bool
872 {
873  return a.isEqual(b, tol);
874 }
875 
876 template <typename T,typename S>
877 inline
879 {
880  return UT_Vector4T<T>(
881  SYSlerp(v1.x(), v2.x(), t),
882  SYSlerp(v1.y(), v2.y(), t),
883  SYSlerp(v1.z(), v2.z(), t),
884  SYSlerp(v1.w(), v2.w(), t));
885 }
886 #ifndef UT_DISABLE_VECTORIZE_MATRIX
887 template <>
888 inline
890 {
891  const v4uf l(v1.data());
892  const v4uf r(v2.data());
893  const v4uf result = SYSlerp(l, r, t);
894  return UT_Vector4T<float>((float*) &result);
895 }
896 #endif
897 
898 template <typename T>
899 inline
901  const UT_Vector4T<T> &v1,
902  const UT_Vector4T<T> &v2)
903 {
904  return UT_Vector4T<T>(
905  SYSinvlerp(a.x(), v1.x(), v2.x()),
906  SYSinvlerp(a.y(), v1.y(), v2.y()),
907  SYSinvlerp(a.z(), v1.z(), v2.z()),
908  SYSinvlerp(a.w(), v1.w(), v2.w()));
909 }
910 
911 
912 template <typename T, typename S>
914 {
915  return rowVecMult(v, m);
916 }
917 template <typename T>
918 inline T distance(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2)
919 {
920  T x = v1.x()-v2.x();
921  T y = v1.y()-v2.y();
922  T z = v1.z()-v2.z();
923  T w = v1.w()-v2.w();
924  return SYSsqrt(x*x + y*y + z*z + w*w);
925 }
926 template <typename T>
928 {
929  T x = v1.x()-v2.x();
930  T y = v1.y()-v2.y();
931  T z = v1.z()-v2.z();
932  return SYSsqrt(x*x + y*y + z*z);
933 }
934 
935 #ifndef UT_DISABLE_VECTORIZE_MATRIX
936 template <>
937 inline float distance(const UT_Vector4T<float> &v1, const UT_Vector4T<float> &v2)
938 {
939  const v4uf l(v1.data());
940  const v4uf r(v2.data());
941  v4uf result = l - r;
942  result *= result;
943 
944  return SYSsqrt(result[0] + result[1] + result[2] + result[3]);
945 }
946 template <>
948 {
949  const v4uf l(v1.data());
950  const v4uf r(v2.data());
951  v4uf result = l - r;
952  result *= result;
953 
954  return SYSsqrt(result[0] + result[1] + result[2]);
955 }
956 #endif
957 
958 template <typename T>
959 inline size_t hash_value(const UT_Vector4T<T> &val)
960 {
961  return val.hash();
962 }
963 
964 // Overload for custom formatting of UT_Vector4T<T> with UTformat.
965 template<typename T>
966 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T<T> &v);
967 
968 template< typename T, exint D >
969 class UT_FixedVector;
970 
971 template<typename T>
973 {
975  typedef T DataType;
976  static const exint TupleSize = 4;
977  static const bool isVectorType = true;
978 };
979 
980 // UT_Vector4T in the role of a fixed array-like type.
981 
982 template< typename T >
984 
985 template< typename T >
987 
988 template< typename T >
989 struct SYS_FixedArraySizeNoCVRef< UT_Vector4T< T > > : std::integral_constant< std::size_t, 4 > {};
990 
991 
992 // UT_Vector4TFromUnbounded<T> is a function object that
993 // creates a UT_Vector2T<T> from an unbounded array-like type 'as'.
994 // 'as' must have at size at least 4.
995 template <typename T>
997 {
998  template< typename TS >
999  constexpr SYS_FORCE_INLINE UT_Vector4T<T> operator()(const TS& as) const noexcept
1000  {
1001  return UT_Vector4T<T>( as[0], as[1], as[2], as[3] );
1002  }
1003 };
1004 
1005 // UT_FromUnbounded<V> creates a V from an unbounded array-like type
1006 
1007 // Primary
1008 template <typename V >
1009 struct UT_FromUnbounded;
1010 
1011 // Partial specialization for UT_Vector4T
1012 template <typename T>
1014 
1015 
1016 // UT_Vector4TFromFixed<T> is a function object that
1017 // creates a UT_Vector4T<T> from a fixed array-like type TS,
1018 // examples of which include T[3], UT_FixedVector<T,3> and UT_FixedArray<T,3> (AKA std::array<T,3>)
1019 template <typename T>
1021 {
1022  template< typename TS >
1023  constexpr SYS_FORCE_INLINE UT_Vector4T<T> operator()(const TS& as) const noexcept
1024  {
1025  SYS_STATIC_ASSERT( SYS_IsFixedArrayOf_v< TS, T, 4 > );
1026 
1027  return UT_Vector4TFromUnbounded<T>{}( as );
1028  }
1029 };
1030 
1031 // Convert a fixed array-like type TS into a UT_Vector4T< T >.
1032 // This allows conversion to UT_Vector4T without fixing T.
1033 // Instead, the element type of TS determines the type T.
1034 template< typename TS >
1036 UTmakeVector4T( const TS& as ) noexcept
1037 {
1039 
1040  return UT_Vector4TFromFixed< T >{}( as );
1041 }
1042 
1043 // UT_FromFixed<V> creates a V from a flat, fixed array-like representation
1044 
1045 // Primary
1046 template <typename V >
1047 struct UT_FromFixed;
1048 
1049 // Partial specialization for UT_Vector4T
1050 template <typename T>
1052 
1053 // Relocation traits for UT_Vector4T are defined in UT_VectorTypes.h
1054 
1055 #endif
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T< T > &v)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:561
UT_Vector4T< T > operator/(const UT_Vector4T< T > &v, S scalar)
Definition: UT_Vector4.h:810
typename UT_StorageNum< T >::MathFloat UT_StorageMathFloat_t
Definition: UT_Storage.h:176
#define SYS_STATIC_ASSERT(expr)
constexpr SYS_FORCE_INLINE T distance(const UT_Vector4T &b) const noexcept
Definition: UT_Vector4.h:299
class UT_API UT_Vector4T
int int32
Definition: SYS_Types.h:39
UT_FromUnbounded creates a V from an unbounded array-like type.
Definition: UT_Vector2.h:795
UT_Vector4T< T > SYSlerp(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S t)
Componentwise linear interpolation.
Definition: UT_Vector4.h:878
friend constexpr bool operator>=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:633
UT_Vector4T< T > SYSmin(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Componentwise min and maximum.
Definition: UT_Vector4.h:847
unsigned hash() const
Compute a hash.
Definition: UT_Vector4.h:518
T operator()(unsigned i) const
Definition: UT_Vector4.h:505
GLboolean * data
Definition: glcorearb.h:131
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector4.h:493
const GLdouble * v
Definition: glcorearb.h:837
void multiplyComponents(const UT_Vector4T< T > &v)
Definition: UT_Vector4.h:352
constexpr SYS_FORCE_INLINE T w() const noexcept
Definition: UT_Vector4.h:498
constexpr SYS_FORCE_INLINE T y() const noexcept
Definition: UT_Vector4.h:494
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:577
bool SYSisFinite(fpreal64 f)
Definition: SYS_Math.h:198
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:539
friend constexpr auto dot(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:580
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
void colVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:402
fpreal64 distance2(const UT_VectorD &v1, const UT_VectorD &v2)
Distance squared (L2) aka quadrance.
Definition: UT_Vector.h:399
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
int64 exint
Definition: SYS_Types.h:125
constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
Definition: UT_Vector4.h:360
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[]) noexcept
Definition: UT_Vector4.h:197
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define UT_API
Definition: UT_API.h:14
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLint y
Definition: glcorearb.h:103
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
**But if you need a result
Definition: thread.h:613
static const exint TupleSize
friend constexpr bool operator<=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:623
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
size_t hash_value(const UT_Vector4T< T > &val)
Definition: UT_Vector4.h:959
constexpr UT_Vector4T< SYS_FixedArrayElement_t< TS > > UTmakeVector4T(const TS &as) noexcept
Definition: UT_Vector4.h:1036
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:174
2D Vector class.
Definition: UT_Vector2.h:159
float fpreal32
Definition: SYS_Types.h:200
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector4.h:491
void negate3()
Definition: UT_Vector4.h:349
double fpreal64
Definition: SYS_Types.h:201
friend constexpr bool operator!=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:611
UT_Vector4T< T > SYSmax(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:859
GLfloat f
Definition: glcorearb.h:1926
UT_API UT_Vector4T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
constexpr SYS_FORCE_INLINE bool isEqual(const UT_Vector4T &b, const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector4.h:370
constexpr SYS_FORCE_INLINE UT_Vector4T(const T vx, const T vy, const T vz, const T vw=1.0f)
Definition: UT_Vector4.h:187
Definition: core.h:760
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< T > &that)=default
UT_API UT_Vector4T< T > rowVecMult3(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
bool SYSisEqual(const UT_Vector4T< T > &a, const UT_Vector4T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
Definition: UT_Vector4.h:871
void clampZero(T tol=0.00001f)
Definition: UT_Vector4.h:334
friend constexpr bool operator<(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:618
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:587
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
Definition: UT_Vector4.h:311
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:918
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector4.h:495
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
Definition: UT_Storage.h:265
constexpr SYS_FORCE_INLINE T x() const noexcept
Definition: UT_Vector4.h:492
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[]) noexcept
Definition: UT_Vector4.h:200
static const bool isVectorType
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
Definition: UT_Vector4.h:380
void multiply3(UT_Vector4T< T > &dest, const UT_Matrix4T< S > &mat) const
Definition: UT_Vector4.h:430
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
constexpr SYS_FORCE_INLINE UT_Vector4T & operator-=(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:254
friend constexpr bool operator==(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:606
UT_Vector4T< T > SYSinvlerp(const UT_Vector4T< T > &a, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:900
constexpr SYS_FORCE_INLINE T z() const noexcept
Definition: UT_Vector4.h:496
Definition: VM_SIMD.h:188
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[]) noexcept
Definition: UT_Vector4.h:191
constexpr SYS_FORCE_INLINE T dot(const UT_Vector4T &b) const noexcept
Definition: UT_Vector4.h:512
long long int64
Definition: SYS_Types.h:116
UT_API UT_Vector3T< T > cross(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
T & operator()(unsigned i)
Definition: UT_Vector4.h:500
constexpr SYS_FORCE_INLINE const T & operator[](exint i) const noexcept
Definition: UT_Vector4.h:234
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[]) noexcept
Definition: UT_Vector4.h:194
constexpr SYS_FORCE_INLINE UT_Vector4T & operator*=(const T &a) noexcept
Definition: UT_Vector4.h:260
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector4.h:436
GLdouble t
Definition: glad.h:2397
constexpr SYS_FORCE_INLINE bool equalZero(const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector4.h:365
UT_Vector4T< T > & operator*=(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:423
GLfloat v0
Definition: glcorearb.h:816
T distance4(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
constexpr SYS_FORCE_INLINE UT_Vector4T< T > operator()(const TS &as) const noexcept
Definition: UT_Vector4.h:1023
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< S > &v)
Definition: UT_Vector4.h:220
GLsizeiptr size
Definition: glcorearb.h:664
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f, T ww=1.0f)
Set the values of the vector components.
Definition: UT_Vector4.h:523
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector4.h:461
UT_Vector4T< T > SYSbilerp(const UT_Vector4T< T > &u0v0, const UT_Vector4T< T > &u1v0, const UT_Vector4T< T > &u0v1, const UT_Vector4T< T > &u1v1, S u, S v)
Bilinear interpolation.
Definition: UT_Vector4.h:115
constexpr SYS_FORCE_INLINE UT_Vector4T()=default
UT_FixedVector< T, 4 > FixedVectorType
Definition: UT_Vector4.h:974
void rowVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:399
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
Definition: UT_Vector4.h:375
constexpr SYS_FORCE_INLINE T distance2(const UT_Vector4T &b) const noexcept
Definition: UT_Vector4.h:294
static int entries()
Returns the vector size.
Definition: UT_Vector4.h:569
friend constexpr auto distance2(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:601
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:224
constexpr UT_Vector4T< T > operator-(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2) noexcept
Definition: UT_Vector4.h:732
constexpr SYS_FORCE_INLINE UT_Vector4T & operator/=(const T &a) noexcept
Definition: UT_Vector4.h:266
constexpr SYS_FORCE_INLINE T & w() noexcept
Definition: UT_Vector4.h:497
constexpr SYS_FORCE_INLINE T length2() const noexcept
Definition: UT_Vector4.h:284
UT_API UT_Vector4T< T > rowVecMult(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
constexpr SYS_FORCE_INLINE UT_Vector4T & operator+=(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:248
UT_Vector4T< T > SYSabs(const UT_Vector4T< T > &v)
Definition: UT_Vector4.h:835
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
Definition: UT_Vector4.h:304
constexpr SYS_FORCE_INLINE T & operator[](exint i) noexcept
Definition: UT_Vector4.h:241
void assign(const T *v, int size=tuple_size)
Set the values of the vector components.
Definition: UT_Vector4.h:529
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
constexpr SYS_FORCE_INLINE T * data() noexcept
Definition: UT_Vector4.h:229
void multiply3(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:427
UT_Vector4T< T > SYSbarycentric(const UT_Vector4T< T > &v0, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S u, S v)
Barycentric interpolation.
Definition: UT_Vector4.h:122
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
T distance3d(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:162
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
T vec[tuple_size]
Definition: UT_Vector4.h:571
GLboolean r
Definition: glcorearb.h:1222
#define const
Definition: zconf.h:214
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:545
void clampZero3(T tol=0.00001f)
Definition: UT_Vector4.h:342
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
int equalZero3(T tol=0.00001f) const
Definition: UT_Vector4.h:327
constexpr SYS_FORCE_INLINE UT_Vector4T< T > operator()(const TS &as) const noexcept
Definition: UT_Vector4.h:999
T dot(const UT_Vector4T< T > &v1, const UT_Vector3T< T > &v2)
The dot product between two vectors.
Definition: UT_Vector4.h:824
friend constexpr bool isZero(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:575
constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
Definition: UT_Vector4.h:385
friend constexpr bool operator>(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:628
constexpr SYS_FORCE_INLINE UT_Vector4T & operator*=(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:273
void rowVecMult3(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:412
bool SYSisInteger(const UT_Vector4T< T > &v1)
Componentwise integer test.
Definition: UT_Vector4.h:103
T distance3(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:927
constexpr SYS_FORCE_INLINE T length() const noexcept
Definition: UT_Vector4.h:289
constexpr SYS_FORCE_INLINE void negate() noexcept
Definition: UT_Vector4.h:279
friend constexpr auto length2(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:596
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663