Fermat
vector.h
1 /*
2  * cugar
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <cugar/basic/types.h>
31 #include <cugar/basic/numbers.h>
32 #include <cmath>
33 #include <limits>
34 
35 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
36  // suppress exception specification warnings
37 #pragma warning(push)
38 #pragma warning(disable:4068)
39 #endif
40 
41 namespace cugar {
42 
45 
49 
53 template <typename T, uint32 DIM>
54 struct Vector
55 {
56  typedef T value_type;
57 
58  static const uint32 DIMENSION = DIM;
59 
60  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
61  Vector() {}
62 
63  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
64  Vector(const T v)
65  {
66  #pragma unroll
67  for (uint32 d = 0; d < DIM; ++d)
68  data[d] = v;
69  }
70 
71  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
72  Vector(const T* v)
73  {
74  #pragma unroll
75  for (uint32 d = 0; d < DIM; ++d)
76  data[d] = v[d];
77  }
78 
79  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
80  uint32 dimension() const { return DIM; }
81 
82  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
83  const T& operator[] (const uint32 i) const { return data[i]; }
84 
85  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
86  T& operator[] (const uint32 i) { return data[i]; }
87 
88  T data[DIM];
89 };
90 
94 template <typename T>
95 struct Vector<T,1>
96 {
97  typedef T base_type;
98  typedef T value_type;
99 
100  static const uint32 DIMENSION = 1;
101 
102  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
103  Vector<T,1>() {}
104 
105  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
106  Vector<T,1>(const T v0)
107  {
108  data = v0;
109  }
110 
111  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
112  uint32 dimension() const { return 1; }
113 
114  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
115  const T& operator[] (const uint32 i) const { return data; }
116 
117  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
118  T& operator[] (const uint32 i) { return data; }
119 
120  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
121  operator base_type() const { return data; }
122 
123  base_type data;
124 };
125 
129 template <typename T>
130 struct Vector<T, 2> : vector_type<T, 2>::type
131 {
132  typedef typename vector_type<T,2>::type base_type;
133  typedef T value_type;
134 
135  static const uint32 DIMENSION = 2;
136 
137  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
138  Vector<T,2>() {}
139 
140  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
141  Vector<T,2>(const T v)
142  {
143  base_type::x = base_type::y = v;
144  }
145 
146  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
147  Vector<T,2>(const T v0, const T v1)
148  {
149  base_type::x = v0;
150  base_type::y = v1;
151  }
152 
153  template <typename U>
154  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
155  explicit Vector<T, 2>(const Vector<U, 2> op)
156  {
157  base_type::x = T(op[0]);
158  base_type::y = T(op[1]);
159  }
160 
161  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
162  Vector<T, 2>(const base_type v) : base_type(v) {}
163 
164  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
165  uint32 dimension() const { return 2; }
166 
167  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
168  const T& operator[] (const uint32 i) const { return (&this->base_type::x)[i]; }
169 
170  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
171  T& operator[] (const uint32 i) { return (&this->base_type::x)[i]; }
172 
173  //CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
174  //operator base_type() const { return data; }
175 
176  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
177  Vector<T, 2> xy() const { return Vector<T,2>(base_type::x, base_type::y); }
178 
179  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
180  Vector<T, 2> yx() const { return Vector<T, 2>(base_type::y, base_type::x); }
181 };
182 
186 template <typename T>
187 struct Vector<T, 3> : vector_type<T, 3>::type
188 {
189  typedef typename vector_type<T,3>::type base_type;
190  typedef T value_type;
191 
192  static const uint32 DIMENSION = 3;
193 
194  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
195  Vector<T,3>() {}
196 
197  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
198  Vector<T, 3>(const T v)
199  {
200  base_type::x = base_type::y = base_type::z = v;
201  }
202 
203  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
204  Vector<T,3>(const T v0, const T v1, const T v2)
205  {
206  base_type::x = v0;
207  base_type::y = v1;
208  base_type::z = v2;
209  }
210 
211  template <typename U>
212  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
213  explicit Vector<T, 3>(const Vector<U,3> op)
214  {
215  base_type::x = T(op[0]);
216  base_type::y = T(op[1]);
217  base_type::z = T(op[2]);
218  }
219 
220  template <typename U>
221  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
222  explicit Vector<T, 3>(const Vector<U, 2> op, const U v2 = 0.0f)
223  {
224  base_type::x = T(op[0]);
225  base_type::y = T(op[1]);
226  base_type::z = T(v2);
227  }
228 
229  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
230  Vector<T, 3>(const base_type v) : base_type(v) {}
231 
232  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
233  uint32 dimension() const { return 3; }
234 
235  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
236  const T& operator[] (const uint32 i) const { return (&this->base_type::x)[i]; }
237 
238  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
239  T& operator[] (const uint32 i) { return (&this->base_type::x)[i]; }
240 
241  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
242  Vector<T,3> xyz() const { return *this; }
243 
244  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
245  Vector<T, 3> zxy() const { return Vector<T, 3>(base_type::z, base_type::x, base_type::y); }
246 
247  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
248  Vector<T, 3> yzx() const { return Vector<T, 3>(base_type::y, base_type::z, base_type::x); }
249 
250  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
251  Vector<T, 2> xy() const { return Vector<T,2>(base_type::x, base_type::y); }
252 
253  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
254  Vector<T, 2> yx() const { return Vector<T, 2>(base_type::y, base_type::x); }
255 
256  //CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
257  //operator base_type() const { return *(base_type*)this; }
258 };
259 
263 template <typename T>
264 struct Vector<T, 4> : public vector_type<T, 4>::type
265 {
266  typedef typename vector_type<T,4>::type base_type;
267  typedef T value_type;
268 
269  static const uint32 DIMENSION = 4;
270 
271  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
272  Vector<T,4>() {}
273 
274  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
275  Vector<T,4>(const T v)
276  {
277  base_type::x = base_type::y = base_type::z = base_type::w = v;
278  }
279 
280  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
281  Vector<T,4>(const T v0, const T v1, const T v2, const T v3)
282  {
283  base_type::x = v0;
284  base_type::y = v1;
285  base_type::z = v2;
286  base_type::w = v3;
287  }
288 
289  template <typename U>
290  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
291  explicit Vector<T, 4>(const Vector<U, 4> op)
292  {
293  base_type::x = T(op[0]);
294  base_type::y = T(op[1]);
295  base_type::z = T(op[2]);
296  base_type::w = T(op[3]);
297  }
298 
299  template <typename U>
300  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
301  explicit Vector<T, 4>(const Vector<U, 3> op, const T v3)
302  {
303  base_type::x = T(op[0]);
304  base_type::y = T(op[1]);
305  base_type::z = T(op[2]);
306  base_type::w = v3;
307  }
308 
309  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
310  Vector<T, 4>(const base_type v) : base_type(v) {}
311 
312  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
313  uint32 dimension() const { return 4; }
314 
315  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
316  const T& operator[] (const uint32 i) const { return (&this->base_type::x)[i]; }
317 
318  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
319  T& operator[] (const uint32 i) { return (&this->base_type::x)[i]; }
320 
321  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
322  Vector<T, 3> xyz() const { return Vector<T, 3>(base_type::x, base_type::y, base_type::z); }
323 
324  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
325  Vector<T, 3> zxy() const { return Vector<T, 3>(base_type::z, base_type::x, base_type::y); }
326 
327  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
328  Vector<T, 3> yzx() const { return Vector<T, 3>(base_type::y, base_type::z, base_type::x); }
329 
330  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
331  Vector<T, 2> xy() const { return Vector<T, 2>(base_type::x, base_type::y); }
332 
333  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
334  Vector<T, 2> yx() const { return Vector<T, 2>(base_type::y, base_type::x); }
335 
336  //CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
337  //operator base_type() const { return *(base_type*)this; }
338 };
339 
340 template <typename T,uint32 DIM_T> struct vector_traits< Vector<T,DIM_T> > { typedef T value_type; const static uint32 DIM = DIM_T; };
341 
345 template <typename T, uint32 DIM>
346 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
348 
352 template <typename T, uint32 DIM>
353 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
354 Vector<T,DIM> operator+ (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
355 
359 template <typename T, uint32 DIM>
360 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
362 
366 template <typename T, uint32 DIM>
367 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
368 Vector<T,DIM> operator- (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
369 
373 template <typename T, uint32 DIM>
374 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
376 
380 template <typename T, uint32 DIM>
381 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
382 Vector<T,DIM> operator* (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
383 
387 template <typename T, uint32 DIM>
388 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
390 
394 template <typename T, uint32 DIM>
395 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
396 Vector<T, DIM> operator* (const T op1, const Vector<T, DIM>& op2);
397 
401 template <typename T, uint32 DIM>
402 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
403 Vector<T, DIM> operator* (const Vector<T, DIM>& op1, const T op2);
404 
408 template <typename T, uint32 DIM>
409 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
410 Vector<T, DIM>& operator*= (Vector<T, DIM>& op1, const T op2);
411 
415 template <typename T, uint32 DIM>
416 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
417 Vector<T,DIM> operator/ (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
418 
422 template <typename T, uint32 DIM>
423 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
425 
429 template <typename T, uint32 DIM>
430 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
431 Vector<T, DIM> operator/ (const Vector<T, DIM>& op1, const T op2);
432 
436 template <typename T, uint32 DIM>
437 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
438 Vector<T, DIM>& operator/= (Vector<T, DIM>& op1, const T op2);
439 
443 template <typename T, uint32 DIM>
444 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
445 Vector<T,DIM> min(const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
446 
450 template <typename T, uint32 DIM>
451 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
452 Vector<T,DIM> max(const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
453 
457 template <typename T, uint32 DIM>
458 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
459 Vector<T,DIM> min(const Vector<T,DIM>& op1, const T op2);
460 
464 template <typename T, uint32 DIM>
465 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
466 Vector<T,DIM> max(const Vector<T,DIM>& op1, const T op2);
467 
471 template <typename T, uint32 DIM>
472 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
473 Vector<T,DIM> abs(const Vector<T,DIM>& op);
474 
478 template <typename T, uint32 DIM>
479 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
480 T max_comp(const Vector<T, DIM>& op);
481 
485 template <typename T, uint32 DIM>
486 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
487 T min_comp(const Vector<T, DIM>& op);
488 
492 template <typename T, uint32 DIM>
493 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
494 bool any(const Vector<T,DIM>& op);
495 
499 template <typename T, uint32 DIM>
500 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
501 bool all(const Vector<T,DIM>& op);
502 
506 template <typename T, uint32 DIM>
507 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
508 bool operator== (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
509 
513 template <typename T, uint32 DIM>
514 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
515 bool operator!= (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
516 
520 template <typename T, uint32 DIM>
521 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
522 bool operator< (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
523 
527 template <typename T, uint32 DIM>
528 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
529 bool operator> (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
530 
534 template <typename T, uint32 DIM>
535 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
536 bool operator<= (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
537 
541 template <typename T, uint32 DIM>
542 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
543 bool operator>= (const Vector<T,DIM>& op1, const Vector<T,DIM>& op2);
544 
548 template <typename T, uint32 DIM>
549 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
550 T dot(const Vector<T, DIM>& op1, const Vector<T, DIM>& op2);
551 
555 template <typename T, uint32 DIM>
556 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
557 T length(const Vector<T, DIM>& op);
558 
562 template <typename T, uint32 DIM>
563 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
565 
569 template <typename T>
570 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
571 Vector<T, 3u> cross(const Vector<T, 3u>& op1, const Vector<T, 3u>& op2);
572 
579 template <typename T>
580 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
582 
589 template <typename T>
590 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
591 Vector<T, 3> refract(const Vector<T, 3> I, const Vector<T, 3> N, const float eta);
592 
599 template <typename T>
600 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
601 Vector<T, 3> refraction_normal(const Vector<T, 3> I, const Vector<T, 3> T, const float eta);
602 
606 template <typename T>
607 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
609 
613 template <typename T>
614 CUGAR_HOST_DEVICE
616 
620 template <typename T>
621 CUGAR_HOST_DEVICE
622 void orthonormal_basis(
623  const Vector<T, 3> normal,
624  Vector<T, 3>& tangent,
625  Vector<T, 3>& bitangent);
626 
630 template <typename T>
631 CUGAR_HOST_DEVICE
632 uint32 pack_vector(const Vector<T, 2> v, const uint32 n_bits_comp);
633 
637 template <typename T>
638 CUGAR_HOST_DEVICE
639 Vector<T, 2> unpack_vector(const uint32 u, const uint32 n_bits_comp);
640 
644 template <typename T, uint32 DIM>
645 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
646 Vector<T, DIM> mod(const Vector<T, DIM>& op, const T m);
647 
651 template <typename T, uint32 DIM>
652 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
654 
658 template <typename T, uint32 DIM>
659 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
660 bool is_finite(const Vector<T, DIM>& op);
661 
665 template <typename T, uint32 DIM>
666 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
667 T L1_norm(const Vector<T, DIM>& op);
668 
672 template <typename T, uint32 DIM>
673 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
674 T L2_norm(const Vector<T, DIM>& op);
675 
679 template <typename T, uint32 DIM>
680 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
681 T L_inf_norm(const Vector<T, DIM>& op);
682 
686 template <typename T, uint32 DIM, uint32 p>
687 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
688 T L_norm(const Vector<T, DIM>& op);
689 
693 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
694 float L1_norm(const float op);
695 
699 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
700 double L1_norm(const double op);
701 
705 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
706 float L2_norm(const float op);
707 
711 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
712 double L2_norm(const double op);
713 
717 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
718 float L_inf_norm(const float op);
719 
723 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
724 double L_inf_norm(const double op);
725 
729 template <uint32 p>
730 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
731 float L_norm(const float op);
732 
736 template <uint32 p>
737 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
738 double L_norm(const double op);
739 
743 template <typename T, uint32 DIM>
744 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
745 T average(const Vector<T, DIM>& op);
746 
750 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
751 float average(const float op);
752 
756 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
757 double average(const double op);
758 
762 template <typename T, uint32 DIM>
763 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
764 Vector<T, DIM> lerp(const Vector<T, DIM>& op1, const Vector<T, DIM>& op2, const T u);
765 
769 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
770 float lerp(const float op1, const float op2, const float u);
771 
775 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
776 double lerp(const double op1, const double op2, const double u);
777 
778 typedef Vector<float, 2> Vector2f;
779 typedef Vector<float, 3> Vector3f;
780 typedef Vector<float, 4> Vector4f;
784 typedef Vector<int, 2> Vector2i;
785 typedef Vector<int, 3> Vector3i;
786 typedef Vector<int, 4> Vector4i;
790 
793 
794 } // namespace cugar
795 
796 #include <cugar/linalg/vector_inl.h>
797 
798 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
799  // suppress exception specification warnings
800 #pragma warning(pop)
801 #endif
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > refract(const Vector< T, 3 > I, const Vector< T, 3 > N, const float eta)
Definition: vector_inl.h:368
CUGAR_HOST_DEVICE void orthonormal_basis(const Vector< T, 3 > normal, Vector< T, 3 > &tangent, Vector< T, 3 > &bitangent)
Definition: vector_inl.h:423
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T max_comp(const Vector< T, DIM > &op)
Definition: tensor_inl.h:425
CUGAR_HOST_DEVICE Vector< T, 3 > orthogonal(const Vector< T, 3 > v)
Definition: tensor_inl.h:362
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator-(const Vector< T, DIM > &op)
Definition: tensor_inl.h:45
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator-=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:85
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator+=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:66
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T min_comp(const Vector< T, DIM > &op)
Definition: tensor_inl.h:436
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator/=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:152
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:594
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator>(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:286
Definition: vector.h:130
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator!=(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:252
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > min(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:180
Definition: numbers.h:463
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator==(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:241
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > refraction_normal(const Vector< T, 3 > I, const Vector< T, 3 > T, const float eta)
Definition: vector_inl.h:379
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T length(const Vector< T, DIM > &op)
Definition: tensor_inl.h:326
CUGAR_HOST_DEVICE Vector< T, 2 > unpack_vector(const uint32 u, const uint32 n_bits_comp)
Definition: tensor_inl.h:404
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3u > cross(const Vector< T, 3u > &op1, const Vector< T, 3u > &op2)
Definition: tensor_inl.h:341
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T dot(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:309
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator*(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:94
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator/(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:142
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool all(const Vector< T, DIM > &op)
Definition: tensor_inl.h:230
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool is_finite(const Vector< T, DIM > &op)
Definition: tensor_inl.h:458
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > faceforward(const Vector< T, 3 > N, const Vector< T, 3 > I)
Definition: tensor_inl.h:356
Definition: numbers.h:368
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > mod(const Vector< T, DIM > &op, const T m)
Definition: tensor_inl.h:414
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator+(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:56
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator*=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:104
Definition: vector.h:54
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator>=(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:298
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > lerp(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2, const T u)
Definition: vector_inl.h:723
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool any(const Vector< T, DIM > &op)
Definition: tensor_inl.h:220
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L1_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:560
Definition: vector.h:264
Definition: vector.h:187
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T average(const Vector< T, DIM > &op)
Definition: vector_inl.h:692
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > abs(const Vector< T, DIM > &op)
Definition: vector_inl.h:221
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > sqrt(const Vector< T, DIM > &op)
Definition: vector_inl.h:487
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > normalize(const Vector< T, DIM > &op)
Definition: tensor_inl.h:333
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > reflect(const Vector< T, 3 > I, const Vector< T, 3 > N)
Definition: tensor_inl.h:350
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > max(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:190
CUGAR_HOST_DEVICE uint32 pack_vector(const Vector< T, 2 > v, const uint32 n_bits_comp)
Definition: tensor_inl.h:394
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L_inf_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:584
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L2_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:574
Definition: vector.h:95