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_FixedVector.h"
26 #include "UT_FixedVectorTraits.h"
27 #include "UT_Storage.h"
28 #include "UT_FixedArrayMath.h"
29 #include "UT_VectorTypes.h"
30 #include <SYS/SYS_Deprecated.h>
31 #include <SYS/SYS_Inline.h>
32 #include <SYS/SYS_Math.h>
33 #include <iosfwd>
34 #include <limits>
35 
36 #ifndef UT_DISABLE_VECTORIZE_MATRIX
37 #include <VM/VM_SIMD.h>
38 #endif
39 
40 class UT_IStream;
41 class UT_JSONWriter;
42 class UT_JSONValue;
43 class UT_JSONParser;
44 
45 // Free floating functions:
46 
47 // Right-multiply operators (M*v) have been removed. They had previously
48 // been defined to return v*M, which was too counterintuitive. Once HDK
49 // etc. users have a chance to update their code (post 7.0) we could
50 // reintroduce a right-multiply operator that does a colVecMult.
51 
52 template <typename T, typename S>
54 template <typename T>
55 constexpr UT_Vector4T<T> operator+(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept;
56 template <typename T>
57 constexpr UT_Vector4T<T> operator-(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2) noexcept;
58 template <typename T, typename S>
59 inline UT_Vector4T<T> operator+(const UT_Vector4T<T> &v, S scalar);
60 template <typename T, typename S>
61 inline UT_Vector4T<T> operator-(const UT_Vector4T<T> &v, S scalar);
62 template <typename T, typename S>
63 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, S scalar);
64 template <typename T, typename S>
65 inline UT_Vector4T<T> operator/(const UT_Vector4T<T> &v, S scalar);
66 template <typename T, typename S>
67 inline UT_Vector4T<T> operator+(S scalar, const UT_Vector4T<T> &v);
68 template <typename T, typename S>
69 inline UT_Vector4T<T> operator-(S scalar, const UT_Vector4T<T> &v);
70 template <typename T, typename S>
71 constexpr UT_Vector4T<T> operator*(S scalar, const UT_Vector4T<T> &v) noexcept;
72 template <typename T, typename S>
73 inline UT_Vector4T<T> operator/(S scalar, const UT_Vector4T<T> &v);
74 
75 /// Although the cross product is undefined for 4D vectors, we believe it's
76 /// useful in practice to define a function that takes two 4D vectors and
77 /// computes the cross-product of their first 3 components
78 template <typename T>
80 template <typename T>
82 template <typename T>
84 
85 /// The dot product between two vectors
86 // @{
87 template <typename T>
88 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector3T<T> &v2);
89 template <typename T>
90 inline T dot(const UT_Vector3T<T> &v1, const UT_Vector4T<T> &v2);
91 // @}
92 
93 /// Componentwise min and maximum
94 template <typename T>
95 inline UT_Vector4T<T> SYSmin (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
96 template <typename T>
97 inline UT_Vector4T<T> SYSmax (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
98 
99 /// Componentwise integer test
100 template <typename T>
101 inline bool SYSisInteger(const UT_Vector4T<T> &v1)
102 { return SYSisInteger(v1.x()) && SYSisInteger(v1.y()) && SYSisInteger(v1.z()) && SYSisInteger(v1.w()); }
103 
104 /// Componentwise linear interpolation
105 template <typename T,typename S>
106 inline UT_Vector4T<T> SYSlerp(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S t);
107 
108 template <typename T>
110 
111 /// Bilinear interpolation
112 template <typename T,typename S>
113 inline UT_Vector4T<T> SYSbilerp(const UT_Vector4T<T> &u0v0, const UT_Vector4T<T> &u1v0,
114  const UT_Vector4T<T> &u0v1, const UT_Vector4T<T> &u1v1,
115  S u, S v)
116 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
117 
118 /// Barycentric interpolation
119 template <typename T, typename S>
121  const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S u, S v)
122 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
123 
124 
125 /// Multiplication of a row or column vector by a matrix (ie. right vs. left
126 /// multiplication respectively). The operator*() declared above is an alias
127 /// for rowVecMult().
128 // @{
129 //
130 // Notes on optimisation of matrix/vector multiplies:
131 // - multiply(dest, mat) functions have been deprecated in favour of
132 // rowVecMult/colVecMult routines, which produce temporaries. For these to
133 // offer comparable performance, the compiler has to optimize away the
134 // temporary, but most modern compilers can do this. Performance tests with
135 // gcc3.3 indicate that this is a realistic expectation for modern
136 // compilers.
137 // - since matrix/vector multiplies cannot be done without temporary data,
138 // the "primary" functions are the global matrix/vector
139 // rowVecMult/colVecMult routines, rather than the member functions.
140 // - inlining is explicitly requested only for functions involving the
141 // native types (UT_Vector4 and UT_Matrix4)
142 template <typename T, typename S>
144 template <typename T, typename S>
146 
147 template <typename T, typename S>
149 template <typename T, typename S>
151 // @}
152 
153 /// Compute the distance between two points
154 // @{
155 template <typename T>
156 inline T distance4(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
157 template <typename T>
158 inline T distance3(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
159 template <typename T>
160 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2)
161 { return distance3(p1, p2); }
162 template <typename T>
163 inline T distance3d(const UT_Vector3T<T> &p1, const UT_Vector4T<T> &p2)
164 { return distance3d(p1, UT_Vector3T<T>(p2)); }
165 template <typename T>
166 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector3T<T> &p2)
167 { return distance3d(UT_Vector3T<T>(p1), p2); }
168 // @}
169 
170 /// 4D Vector class.
171 template <typename T>
173 {
174 public:
175  typedef T value_type;
176  static constexpr int tuple_size = 4;
177 
178  /// Default constructor.
179  /// No data is initialized! Use it for extra speed.
180  constexpr SYS_FORCE_INLINE UT_Vector4T() = default;
181 
182  constexpr SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T<T> &that) = default;
183  constexpr SYS_FORCE_INLINE UT_Vector4T(UT_Vector4T<T> &&that) = default;
184 
185  constexpr SYS_FORCE_INLINE UT_Vector4T(const T vx, const T vy, const T vz, const T vw = 1.0f) :
186  vec{ vx, vy, vz, vw }
187  {}
188 
189  constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[]) noexcept :
190  UT_Vector4T( v[0], v[1], v[2], v[3] )
191  {}
192  constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[]) noexcept :
193  UT_Vector4T( v[0], v[1], v[2], v[3] )
194  {}
195  constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[]) noexcept :
196  UT_Vector4T( v[0], v[1], v[2], v[3] )
197  {}
198  constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[]) noexcept :
199  UT_Vector4T( v[0], v[1], v[2], v[3] )
200  {}
201 
202  // Initialises the vector as [x,y,0,1]
204  constexpr explicit UT_Vector4T(const UT_Vector2T<T> &v) noexcept;
205 
206  constexpr explicit UT_Vector4T(const UT_Vector3T<T> &v, T w = 1.f) noexcept;
207 
208  /// Our own type of any given value_type.
209  template <typename S>
210  constexpr SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T<S>& v) noexcept :
211  UT_Vector4T( v[0], v[1], v[2], v[3] )
212  {}
213 
214  /// UT_FixedVector of the same size
215  constexpr explicit SYS_FORCE_INLINE UT_Vector4T(const UT_FixedVector<T,tuple_size>& v) noexcept :
216  UT_Vector4T( v[0], v[1], v[2], v[3] )
217  {}
218 
219  SYS_FORCE_INLINE UT_Vector4T<T> &operator=(const UT_Vector4T<T> &that) = default;
220  SYS_FORCE_INLINE UT_Vector4T<T> &operator=(UT_Vector4T<T> &&that) = default;
221 
222  template <typename S>
224  { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3];
225  return *this; }
226 
227  constexpr SYS_FORCE_INLINE const T* data() const noexcept
228  {
229  return vec;
230  }
231 
232  constexpr SYS_FORCE_INLINE T* data() noexcept
233  {
234  return vec;
235  }
236 
237  constexpr SYS_FORCE_INLINE const T& operator[]( exint i ) const noexcept
238  {
239  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
240 
241  return vec[ i ];
242  }
243 
244  constexpr SYS_FORCE_INLINE T& operator[]( exint i ) noexcept
245  {
246  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
247 
248  return vec[ i ];
249  }
250 
251  constexpr SYS_FORCE_INLINE UT_Vector4T& operator+=( const UT_Vector4T& a ) noexcept
252  {
253  UT::FA::Add< T, tuple_size >{}( vec, a.vec );
254  return *this;
255  }
256 
257  constexpr SYS_FORCE_INLINE UT_Vector4T& operator-=( const UT_Vector4T& a ) noexcept
258  {
259  UT::FA::Subtract< T, tuple_size >{}( vec, a.vec );
260  return *this;
261  }
262 
263  constexpr SYS_FORCE_INLINE UT_Vector4T& operator*=( const T& a ) noexcept
264  {
266  return *this;
267  }
268 
269  constexpr SYS_FORCE_INLINE UT_Vector4T& operator/=( const T& a ) noexcept
270  {
271  using MF = UT_StorageMathFloat_t< T >;
272  UT::FA::Scale< T, tuple_size, MF >{}( vec, MF{1} / a );
273  return *this;
274  }
275 
276  constexpr SYS_FORCE_INLINE UT_Vector4T& operator*=( const UT_Vector4T& a ) noexcept
277  {
279  return *this;
280  }
281 
282  constexpr SYS_FORCE_INLINE void negate() noexcept
283  {
285  }
286 
287  constexpr SYS_FORCE_INLINE T length2() const noexcept
288  {
289  return UT::FA::Length2< T, tuple_size >{}( vec );
290  }
291 
292  constexpr SYS_FORCE_INLINE T length() const noexcept
293  {
294  return SYSsqrt( length2() );
295  }
296 
297  constexpr SYS_FORCE_INLINE T distance2( const UT_Vector4T& b ) const noexcept
298  {
299  return UT::FA::Distance2< T, tuple_size >{}( vec, b.vec );
300  }
301 
302  constexpr SYS_FORCE_INLINE T distance( const UT_Vector4T& b ) const noexcept
303  {
304  return SYSsqrt( distance2( b ) );
305  }
306 
308  {
309  using MF = UT_StorageMathFloat_t< T >;
312  }
313 
314  constexpr SYS_FORCE_INLINE bool isZero() const noexcept
315  {
317  }
318 
319  constexpr SYS_FORCE_INLINE UT_Vector4T& operator=( const T a ) noexcept;
320 
321  // TODO: We could remove this. It's not as error-prone as some other
322  // conversions, but it might still be better to force the user to do
323  // an explicit cast i.e., v4 = UT_Vector4(v3)
324 
325  /// Assignment operator that creates a V4 from a V3 by adding a '1'
326  /// element.
327  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit UT_Vector4 constructor to avoid implicit conversion from UT_Vector3)
328  UT_Vector4T<T> &operator=(const UT_Vector3T<T> &v);
329 
330  int equalZero3(T tol = 0.00001f) const
331  {
332  return (vec[0] >= -tol && vec[0] <= tol) &&
333  (vec[1] >= -tol && vec[1] <= tol) &&
334  (vec[2] >= -tol && vec[2] <= tol);
335  }
336 
337  void clampZero(T tol = 0.00001f)
338  {
339  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
340  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
341  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
342  if (vec[3] >= -tol && vec[3] <= tol) vec[3] = 0;
343  }
344 
345  void clampZero3(T tol = 0.00001f)
346  {
347  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
348  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
349  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
350  }
351 
352  void negate3()
353  { vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2]; }
354 
356  {
357  vec[0] *= v.vec[0];
358  vec[1] *= v.vec[1];
359  vec[2] *= v.vec[2];
360  vec[3] *= v.vec[3];
361  }
362 
363  constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
364  {
365  return UT::FA::AllOf< T, tuple_size >{}( vec, [ & ]( const T& a ) { return SYSisFinite( a ); } );
366  }
367 
368  constexpr SYS_FORCE_INLINE bool equalZero( const T tolerance = SYS_FTOLERANCE ) const noexcept
369  {
370  return UT::FA::MaxNormIsLEQ< T, tuple_size >{}( vec, tolerance );
371  }
372 
373  constexpr SYS_FORCE_INLINE bool isEqual( const UT_Vector4T& b, const T tolerance = SYS_FTOLERANCE ) const noexcept
374  {
375  return UT::FA::MaxMetricIsLEQ< T, tuple_size >{}( vec, b.vec, tolerance );
376  }
377 
378  constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
379  {
380  return UT::FA::Max< T, tuple_size >{}( vec );
381  }
382 
383  constexpr SYS_FORCE_INLINE T minComponent() const noexcept
384  {
385  return UT::FA::Min< T, tuple_size >{}( vec );
386  }
387 
388  constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
389  {
390  return UT::FA::Sum< T, tuple_size >{}( vec ) / T{ tuple_size };
391  }
392 
393  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit conversion to UT_Vector3 followed by isEqual)
394  inline int isEqual(const UT_Vector3T<T> &vect, T tol = 0.00001f) const;
395 
396  /// If you need a multiplication operator that left multiplies the vector
397  /// by a matrix (M * v), use the following colVecMult() functions. If
398  /// you'd rather not use operator*=() for right-multiplications (v * M),
399  /// use the following rowVecMult() functions.
400  // @{
401  template <typename S>
402  inline void rowVecMult(const UT_Matrix4T<S> &m)
403  { operator=(::rowVecMult(*this, m)); }
404  template <typename S>
405  inline void colVecMult(const UT_Matrix4T<S> &m)
406  { operator=(::colVecMult(m, *this)); }
407  // @}
408 
409  /// This multiply will ignore the 4th component both in the vector an in
410  /// the matrix. This helps when you want to avoid affecting the 'w'
411  /// component. This in turns annihilates the translation components (row 4)
412  /// in mat, so be careful.
413  // @{
414  template <typename S>
416  { operator=(::rowVecMult3(*this, m)); }
417  // @}
418 
419  // The *= and multiply3 routines are provided for
420  // legacy reasons. They all assume that *this is a row vector. Generally,
421  // the rowVecMult and colVecMult methods are preferred, since they're
422  // more explicit about the row vector assumption.
423  // @{
424  template <typename S>
425  inline
427  { rowVecMult(mat); return *this; }
428 
429  template <typename S>
430  inline void multiply3(const UT_Matrix4T<S> &mat)
431  { rowVecMult3(mat); }
432  template <typename S>
433  inline void multiply3(UT_Vector4T<T> &dest, const UT_Matrix4T<S> &mat) const
434  { dest = ::rowVecMult3(*this, mat); }
435  // @}
436 
437  /// These allow you to find out what indices to use for different axes
438  // @{
439  int findMinAbsAxis() const
440  {
441  if (SYSabs(x()) < SYSabs(y()))
442  if (SYSabs(z()) < SYSabs(x()))
443  if (SYSabs(w()) < SYSabs(z()))
444  return 3;
445  else
446  return 2;
447  else
448  if (SYSabs(w()) < SYSabs(x()))
449  return 3;
450  else
451  return 0;
452  else
453  if (SYSabs(z()) < SYSabs(y()))
454  if (SYSabs(w()) < SYSabs(z()))
455  return 3;
456  else
457  return 2;
458  else
459  if (SYSabs(w()) < SYSabs(y()))
460  return 3;
461  else
462  return 1;
463  }
464  int findMaxAbsAxis() const
465  {
466  if (SYSabs(x()) >= SYSabs(y()))
467  if (SYSabs(z()) >= SYSabs(x()))
468  if (SYSabs(w()) >= SYSabs(z()))
469  return 3;
470  else
471  return 2;
472  else
473  if (SYSabs(w()) >= SYSabs(x()))
474  return 3;
475  else
476  return 0;
477  else
478  if (SYSabs(z()) >= SYSabs(y()))
479  if (SYSabs(w()) >= SYSabs(z()))
480  return 3;
481  else
482  return 2;
483  else
484  if (SYSabs(w()) >= SYSabs(y()))
485  return 3;
486  else
487  return 1;
488  }
489  // @}
490 
491  /// Return the components of the vector. The () operator does NOT check
492  /// for the boundary condition.
493  // @{
494  inline T &x() { return vec[0]; }
495  constexpr T x() const noexcept { return vec[0]; }
496  inline T &y() { return vec[1]; }
497  constexpr T y() const noexcept { return vec[1]; }
498  inline T &z() { return vec[2]; }
499  constexpr T z() const noexcept { return vec[2]; }
500  inline T &w() { return vec[3]; }
501  constexpr T w() const noexcept { return vec[3]; }
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 T 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 T length2( const UT_Vector4T& a ) noexcept
599  {
600  return UT::FA::Length2< T, tuple_size >{}( a.vec );
601  }
602 
603  friend constexpr T 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
874 {
875  return UT_Vector4T<T>(
876  SYSlerp(v1.x(), v2.x(), t),
877  SYSlerp(v1.y(), v2.y(), t),
878  SYSlerp(v1.z(), v2.z(), t),
879  SYSlerp(v1.w(), v2.w(), t));
880 }
881 #ifndef UT_DISABLE_VECTORIZE_MATRIX
882 template <>
883 inline
885 {
886  const v4uf l(v1.data());
887  const v4uf r(v2.data());
888  const v4uf result = SYSlerp(l, r, t);
889  return UT_Vector4T<float>((float*) &result);
890 }
891 #endif
892 
893 template <typename T>
894 inline
896  const UT_Vector4T<T> &v1,
897  const UT_Vector4T<T> &v2)
898 {
899  return UT_Vector4T<T>(
900  SYSinvlerp(a.x(), v1.x(), v2.x()),
901  SYSinvlerp(a.y(), v1.y(), v2.y()),
902  SYSinvlerp(a.z(), v1.z(), v2.z()),
903  SYSinvlerp(a.w(), v1.w(), v2.w()));
904 }
905 
906 
907 template <typename T, typename S>
909 {
910  return rowVecMult(v, m);
911 }
912 template <typename T>
913 inline T distance(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2)
914 {
915  T x = v1.x()-v2.x();
916  T y = v1.y()-v2.y();
917  T z = v1.z()-v2.z();
918  T w = v1.w()-v2.w();
919  return SYSsqrt(x*x + y*y + z*z + w*w);
920 }
921 template <typename T>
923 {
924  T x = v1.x()-v2.x();
925  T y = v1.y()-v2.y();
926  T z = v1.z()-v2.z();
927  return SYSsqrt(x*x + y*y + z*z);
928 }
929 
930 #ifndef UT_DISABLE_VECTORIZE_MATRIX
931 template <>
932 inline float distance(const UT_Vector4T<float> &v1, const UT_Vector4T<float> &v2)
933 {
934  const v4uf l(v1.data());
935  const v4uf r(v2.data());
936  v4uf result = l - r;
937  result *= result;
938 
939  return SYSsqrt(result[0] + result[1] + result[2] + result[3]);
940 }
941 template <>
943 {
944  const v4uf l(v1.data());
945  const v4uf r(v2.data());
946  v4uf result = l - r;
947  result *= result;
948 
949  return SYSsqrt(result[0] + result[1] + result[2]);
950 }
951 #endif
952 
953 template <typename T>
954 inline size_t hash_value(const UT_Vector4T<T> &val)
955 {
956  return val.hash();
957 }
958 
959 // Overload for custom formatting of UT_Vector4T<T> with UTformat.
960 template<typename T>
961 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T<T> &v);
962 
963 template< typename T, exint D >
964 class UT_FixedVector;
965 
966 template<typename T>
968 {
970  typedef T DataType;
971  static const exint TupleSize = 4;
972  static const bool isVectorType = true;
973 };
974 
975 // UT_Vector4T in the role of a fixed array-like type.
976 
977 template< typename T >
979 
980 template< typename T >
982 
983 template< typename T >
984 struct SYS_FixedArraySizeNoCVRef< UT_Vector4T< T > > : std::integral_constant< std::size_t, 4 > {};
985 
986 // UT_Vector4TFromFixed<T> is a function object that
987 // creates a UT_Vector4T<T> from a fixed array-like type TS,
988 // examples of which include T[3], UT_FixedVector<T,3> and UT_FixedArray<T,3> (AKA std::array<T,3>)
989 template <typename T>
991 {
992  template< typename TS >
993  constexpr SYS_FORCE_INLINE UT_Vector4T<T> operator()(const TS& as) const noexcept
994  {
995  SYS_STATIC_ASSERT( SYS_IsFixedArrayOf_v< TS, T, 4 > );
996 
997  return UT_Vector4T<T>{as[0], as[1], as[2], as[3]};
998  }
999 };
1000 
1001 // Convert a fixed array-like type TS into a UT_Vector4T< T >.
1002 // This allows conversion to UT_Vector4T without fixing T.
1003 // Instead, the element type of TS determines the type T.
1004 template< typename TS >
1006 UTmakeVector4T( const TS& as ) noexcept
1007 {
1009 
1010  return UT_Vector4TFromFixed< T >{}( as );
1011 }
1012 
1013 // UT_FromFixed<V> creates a V from a flat, fixed array-like representation
1014 
1015 // Primary
1016 template <typename V >
1017 struct UT_FromFixed;
1018 
1019 // Partial specialization for UT_Vector4T
1020 template <typename T>
1022 
1023 // Relocation traits for UT_Vector4T are defined in UT_VectorTypes.h
1024 
1025 #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:575
UT_Vector4T< T > operator/(const UT_Vector4T< T > &v, S scalar)
Definition: UT_Vector4.h:812
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
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:302
class UT_API UT_Vector4T
int int32
Definition: SYS_Types.h:39
UT_Vector4T< T > SYSlerp(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S t)
Componentwise linear interpolation.
Definition: UT_Vector4.h:873
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
constexpr SYS_FORCE_INLINE UT_Vector4T(const UT_FixedVector< T, tuple_size > &v) noexcept
UT_FixedVector of the same size.
Definition: UT_Vector4.h:215
constexpr T w() const noexcept
Definition: UT_Vector4.h:501
void multiplyComponents(const UT_Vector4T< T > &v)
Definition: UT_Vector4.h:355
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:591
bool SYSisFinite(fpreal64 f)
Definition: SYS_Math.h:194
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:541
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
void colVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:405
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:656
int64 exint
Definition: SYS_Types.h:125
constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
Definition: UT_Vector4.h:363
constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[]) noexcept
Definition: UT_Vector4.h:195
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
#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)
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
static const exint TupleSize
friend constexpr bool operator<=(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:625
size_t hash_value(const UT_Vector4T< T > &val)
Definition: UT_Vector4.h:954
constexpr UT_Vector4T< SYS_FixedArrayElement_t< TS > > UTmakeVector4T(const TS &as) noexcept
Definition: UT_Vector4.h:1006
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:172
2D Vector class.
Definition: UT_Vector2.h:157
float fpreal32
Definition: SYS_Types.h:200
GLdouble GLdouble t
Definition: glew.h:1403
constexpr T y() const noexcept
Definition: UT_Vector4.h:497
GLdouble l
Definition: glew.h:9164
void negate3()
Definition: UT_Vector4.h:352
GLint GLenum GLint x
Definition: glcorearb.h:409
GLsizeiptr size
Definition: glcorearb.h:664
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
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
UT_API UT_Vector4T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
GLuint64EXT * result
Definition: glew.h:14311
constexpr SYS_FORCE_INLINE bool isEqual(const UT_Vector4T &b, const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector4.h:373
constexpr SYS_FORCE_INLINE UT_Vector4T(const T vx, const T vy, const T vz, const T vw=1.0f)
Definition: UT_Vector4.h:185
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)
void clampZero(T tol=0.00001f)
Definition: UT_Vector4.h:337
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:601
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
Definition: UT_Vector4.h:314
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:913
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
Definition: UT_Storage.h:265
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:152
constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[]) noexcept
Definition: UT_Vector4.h:198
const GLdouble * v
Definition: glcorearb.h:837
static const bool isVectorType
constexpr T z() const noexcept
Definition: UT_Vector4.h:499
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
Definition: UT_Vector4.h:383
void multiply3(UT_Vector4T< T > &dest, const UT_Matrix4T< S > &mat) const
Definition: UT_Vector4.h:433
#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:257
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:895
Definition: VM_SIMD.h:188
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[]) noexcept
Definition: UT_Vector4.h:189
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
friend constexpr T dot(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:582
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)
GLfloat GLfloat p
Definition: glew.h:16656
T & operator()(unsigned i)
Definition: UT_Vector4.h:502
constexpr SYS_FORCE_INLINE const T & operator[](exint i) const noexcept
Definition: UT_Vector4.h:237
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[]) noexcept
Definition: UT_Vector4.h:192
constexpr SYS_FORCE_INLINE UT_Vector4T & operator*=(const T &a) noexcept
Definition: UT_Vector4.h:263
GLfloat v0
Definition: glcorearb.h:816
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector4.h:439
constexpr SYS_FORCE_INLINE bool equalZero(const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector4.h:368
UT_Vector4T< T > & operator*=(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:426
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:993
GLboolean * data
Definition: glcorearb.h:131
GLuint GLfloat * val
Definition: glcorearb.h:1608
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< S > &v)
Definition: UT_Vector4.h:223
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:464
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:113
constexpr SYS_FORCE_INLINE UT_Vector4T()=default
UT_FixedVector< T, 4 > FixedVectorType
Definition: UT_Vector4.h:969
void rowVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:402
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
Definition: UT_Vector4.h:378
constexpr SYS_FORCE_INLINE T distance2(const UT_Vector4T &b) const noexcept
Definition: UT_Vector4.h:297
static int entries()
Returns the vector size.
Definition: UT_Vector4.h:571
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:227
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:269
constexpr SYS_FORCE_INLINE T length2() const noexcept
Definition: UT_Vector4.h:287
UT_API UT_Vector4T< T > rowVecMult(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
friend constexpr T distance2(const UT_Vector4T &a, const UT_Vector4T &b) noexcept
Definition: UT_Vector4.h:603
constexpr SYS_FORCE_INLINE UT_Vector4T & operator+=(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:251
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:307
constexpr SYS_FORCE_INLINE T & operator[](exint i) noexcept
Definition: UT_Vector4.h:244
void assign(const T *v, int size=tuple_size)
Set the values of the vector components.
Definition: UT_Vector4.h:531
const GLdouble * m
Definition: glew.h:9166
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:77
GLfloat f
Definition: glcorearb.h:1926
constexpr SYS_FORCE_INLINE T * data() noexcept
Definition: UT_Vector4.h:232
void multiply3(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:430
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:120
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
T distance3d(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:160
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:153
T vec[tuple_size]
Definition: UT_Vector4.h:573
constexpr T x() const noexcept
Definition: UT_Vector4.h:495
#define const
Definition: zconf.h:214
GLfloat GLfloat v1
Definition: glcorearb.h:817
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:345
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:654
GLboolean r
Definition: glcorearb.h:1222
int equalZero3(T tol=0.00001f) const
Definition: UT_Vector4.h:330
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:388
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:276
friend constexpr T length2(const UT_Vector4T &a) noexcept
Definition: UT_Vector4.h:598
void rowVecMult3(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:415
bool SYSisInteger(const UT_Vector4T< T > &v1)
Componentwise integer test.
Definition: UT_Vector4.h:101
GLint y
Definition: glcorearb.h:103
T distance3(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:922
constexpr SYS_FORCE_INLINE T length() const noexcept
Definition: UT_Vector4.h:292
constexpr SYS_FORCE_INLINE void negate() noexcept
Definition: UT_Vector4.h:282
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:652