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