Loading...
Searching...
No Matches
vec4h.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
8// This file is generated by a script. Do not edit directly. Edit the
9// vec.template.h file to make changes.
10
11#ifndef PXR_BASE_GF_VEC4H_H
12#define PXR_BASE_GF_VEC4H_H
13
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/limits.h"
20#include "pxr/base/gf/traits.h"
21#include "pxr/base/gf/math.h"
22#include "pxr/base/gf/half.h"
24#include "pxr/base/tf/hash.h"
25
26#include <cstddef>
27#include <type_traits>
28#include <cmath>
29
30#include <iosfwd>
31
32PXR_NAMESPACE_OPEN_SCOPE
33
34class GfVec2h;
35class GfVec3h;
36
37template <>
38struct GfIsGfVec<class GfVec4h> { static const bool value = true; };
39
49{
50public:
53 static const size_t dimension = 4;
54
66 GfHalf x, y, z, w;
68
71 GfVec4h() = default;
72
74 constexpr explicit GfVec4h(GfHalf value)
75 : x(value), y(value), z(value), w(value)
76 {
77 }
78
80 constexpr GfVec4h(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
81 : x(s0), y(s1), z(s2), w(s3)
82 {
83 }
84
86 template <class Scl>
87 constexpr explicit GfVec4h(Scl const *p)
88 : x(p[0]), y(p[1]), z(p[2]), w(p[3])
89 {
90 }
91
93 explicit GfVec4h(class GfVec4d const &other);
94
96 explicit GfVec4h(class GfVec4f const &other);
97
99 GfVec4h(class GfVec4i const &other);
101 static GfVec4h XAxis() {
102 GfVec4h result(0);
103 result[0] = 1;
104 return result;
105 }
106
108 static GfVec4h YAxis() {
109 GfVec4h result(0);
110 result[1] = 1;
111 return result;
112 }
113
115 static GfVec4h ZAxis() {
116 GfVec4h result(0);
117 result[2] = 1;
118 return result;
119 }
120
122 static GfVec4h WAxis() {
123 GfVec4h result(0);
124 result[3] = 1;
125 return result;
126 }
127
130 static GfVec4h Axis(size_t i) {
131 GfVec4h result(0);
132 if (i < 4)
133 result[i] = 1;
134 return result;
135 }
136
139 x = s0;
140 y = s1;
141 z = s2;
142 w = s3;
143 return *this;
144 }
145
147 GfVec4h &Set(GfHalf const *a) {
148 return Set(a[0], a[1], a[2], a[3]);
149 }
150
156 GfHalf const *data() const { return &x; }
157 GfHalf *data() { return &x; }
158 GfHalf const *GetArray() const { return data(); }
159
161 GfHalf const &operator[](size_t i) const { return data()[i]; }
162 GfHalf &operator[](size_t i) { return data()[i]; }
163
165 friend inline size_t hash_value(GfVec4h const &vec) {
166 return TfHash::Combine(vec.x, vec.y, vec.z, vec.w);
167 }
168
170 bool operator==(GfVec4h const &other) const {
171 return x == other.x &&
172 y == other.y &&
173 z == other.z &&
174 w == other.w;
175 }
176 bool operator!=(GfVec4h const &other) const {
177 return !(*this == other);
178 }
179
180 // TODO Add inequality for other vec types...
182 GF_API
183 bool operator==(class GfVec4d const &other) const;
185 GF_API
186 bool operator==(class GfVec4f const &other) const;
188 GF_API
189 bool operator==(class GfVec4i const &other) const;
190
193 return GfVec4h(-x, -y, -z, -w);
194 }
195
197 GfVec4h &operator+=(GfVec4h const &other) {
198 x += other.x;
199 y += other.y;
200 z += other.z;
201 w += other.w;
202 return *this;
203 }
204 friend GfVec4h operator+(GfVec4h const &l, GfVec4h const &r) {
205 return GfVec4h(l) += r;
206 }
207
209 GfVec4h &operator-=(GfVec4h const &other) {
210 x -= other.x;
211 y -= other.y;
212 z -= other.z;
213 w -= other.w;
214 return *this;
215 }
216 friend GfVec4h operator-(GfVec4h const &l, GfVec4h const &r) {
217 return GfVec4h(l) -= r;
218 }
219
221 GfVec4h &operator*=(double s) {
222 x *= s;
223 y *= s;
224 z *= s;
225 w *= s;
226 return *this;
227 }
228 GfVec4h operator*(double s) const {
229 return GfVec4h(*this) *= s;
230 }
231 friend GfVec4h operator*(double s, GfVec4h const &v) {
232 return v * s;
233 }
234
236 // TODO should divide by the scalar type.
237 GfVec4h &operator/=(double s) {
238 // TODO This should not multiply by 1/s, it should do the division.
239 // Doing the division is more numerically stable when s is close to
240 // zero.
241 return *this *= (1.0 / s);
242 }
243 GfVec4h operator/(double s) const {
244 return *this * (1.0 / s);
245 }
246
248 GfHalf operator*(GfVec4h const &v) const {
249 return x * v.x + y * v.y + z * v.z + w * v.w;
250 }
251
256 GfVec4h GetProjection(GfVec4h const &v) const {
257 return v * (*this * v);
258 }
259
265 GfVec4h GetComplement(GfVec4h const &b) const {
266 return *this - this->GetProjection(b);
267 }
268
271 return *this * *this;
272 }
273
276 return GfSqrt(GetLengthSq());
277 }
278
287 GfHalf Normalize(GfHalf eps = 0.001) {
288 // TODO this seems suspect... suggest dividing by length so long as
289 // length is not zero.
290 GfHalf length = GetLength();
291 *this /= (length > eps) ? length : eps;
292 return length;
293 }
294
295 GfVec4h GetNormalized(GfHalf eps = 0.001) const {
296 GfVec4h normalized(*this);
297 normalized.Normalize(eps);
298 return normalized;
299 }
300
301
317#if defined (doxygen)
318 constexpr GfVec2h xy() const;
319 constexpr GfVec2h xz() const;
320 constexpr GfVec2h xw() const;
321 constexpr GfVec2h yx() const;
322 constexpr GfVec2h yz() const;
323 constexpr GfVec2h yw() const;
324 constexpr GfVec2h zx() const;
325 constexpr GfVec2h zy() const;
326 constexpr GfVec2h zw() const;
327 constexpr GfVec2h wx() const;
328 constexpr GfVec2h wy() const;
329 constexpr GfVec2h wz() const;
330 constexpr GfVec3h xyz() const;
331 constexpr GfVec3h xyw() const;
332 constexpr GfVec3h xzy() const;
333 constexpr GfVec3h xzw() const;
334 constexpr GfVec3h xwy() const;
335 constexpr GfVec3h xwz() const;
336 constexpr GfVec3h yxz() const;
337 constexpr GfVec3h yxw() const;
338 constexpr GfVec3h yzx() const;
339 constexpr GfVec3h yzw() const;
340 constexpr GfVec3h ywx() const;
341 constexpr GfVec3h ywz() const;
342 constexpr GfVec3h zxy() const;
343 constexpr GfVec3h zxw() const;
344 constexpr GfVec3h zyx() const;
345 constexpr GfVec3h zyw() const;
346 constexpr GfVec3h zwx() const;
347 constexpr GfVec3h zwy() const;
348 constexpr GfVec3h wxy() const;
349 constexpr GfVec3h wxz() const;
350 constexpr GfVec3h wyx() const;
351 constexpr GfVec3h wyz() const;
352 constexpr GfVec3h wzx() const;
353 constexpr GfVec3h wzy() const;
354 constexpr GfVec4h xyzw() const;
355 constexpr GfVec4h xywz() const;
356 constexpr GfVec4h xzyw() const;
357 constexpr GfVec4h xzwy() const;
358 constexpr GfVec4h xwyz() const;
359 constexpr GfVec4h xwzy() const;
360 constexpr GfVec4h yxzw() const;
361 constexpr GfVec4h yxwz() const;
362 constexpr GfVec4h yzxw() const;
363 constexpr GfVec4h yzwx() const;
364 constexpr GfVec4h ywxz() const;
365 constexpr GfVec4h ywzx() const;
366 constexpr GfVec4h zxyw() const;
367 constexpr GfVec4h zxwy() const;
368 constexpr GfVec4h zyxw() const;
369 constexpr GfVec4h zywx() const;
370 constexpr GfVec4h zwxy() const;
371 constexpr GfVec4h zwyx() const;
372 constexpr GfVec4h wxyz() const;
373 constexpr GfVec4h wxzy() const;
374 constexpr GfVec4h wyxz() const;
375 constexpr GfVec4h wyzx() const;
376 constexpr GfVec4h wzxy() const;
377 constexpr GfVec4h wzyx() const;
379#else // !doxygen
380 // Note that these are templated on their own return type so that the
381 // declarations cost nothing in compile time & debug info unless they are
382 // actually called in a TU. Naming a different type is an error and
383 // static_assert()ed against.
384 template <class Vec = GfVec2h> constexpr Vec xy() const;
385 template <class Vec = GfVec2h> constexpr Vec xz() const;
386 template <class Vec = GfVec2h> constexpr Vec xw() const;
387 template <class Vec = GfVec2h> constexpr Vec yx() const;
388 template <class Vec = GfVec2h> constexpr Vec yz() const;
389 template <class Vec = GfVec2h> constexpr Vec yw() const;
390 template <class Vec = GfVec2h> constexpr Vec zx() const;
391 template <class Vec = GfVec2h> constexpr Vec zy() const;
392 template <class Vec = GfVec2h> constexpr Vec zw() const;
393 template <class Vec = GfVec2h> constexpr Vec wx() const;
394 template <class Vec = GfVec2h> constexpr Vec wy() const;
395 template <class Vec = GfVec2h> constexpr Vec wz() const;
396 template <class Vec = GfVec3h> constexpr Vec xyz() const;
397 template <class Vec = GfVec3h> constexpr Vec xyw() const;
398 template <class Vec = GfVec3h> constexpr Vec xzy() const;
399 template <class Vec = GfVec3h> constexpr Vec xzw() const;
400 template <class Vec = GfVec3h> constexpr Vec xwy() const;
401 template <class Vec = GfVec3h> constexpr Vec xwz() const;
402 template <class Vec = GfVec3h> constexpr Vec yxz() const;
403 template <class Vec = GfVec3h> constexpr Vec yxw() const;
404 template <class Vec = GfVec3h> constexpr Vec yzx() const;
405 template <class Vec = GfVec3h> constexpr Vec yzw() const;
406 template <class Vec = GfVec3h> constexpr Vec ywx() const;
407 template <class Vec = GfVec3h> constexpr Vec ywz() const;
408 template <class Vec = GfVec3h> constexpr Vec zxy() const;
409 template <class Vec = GfVec3h> constexpr Vec zxw() const;
410 template <class Vec = GfVec3h> constexpr Vec zyx() const;
411 template <class Vec = GfVec3h> constexpr Vec zyw() const;
412 template <class Vec = GfVec3h> constexpr Vec zwx() const;
413 template <class Vec = GfVec3h> constexpr Vec zwy() const;
414 template <class Vec = GfVec3h> constexpr Vec wxy() const;
415 template <class Vec = GfVec3h> constexpr Vec wxz() const;
416 template <class Vec = GfVec3h> constexpr Vec wyx() const;
417 template <class Vec = GfVec3h> constexpr Vec wyz() const;
418 template <class Vec = GfVec3h> constexpr Vec wzx() const;
419 template <class Vec = GfVec3h> constexpr Vec wzy() const;
420 template <class Vec = GfVec4h> constexpr Vec xyzw() const;
421 template <class Vec = GfVec4h> constexpr Vec xywz() const;
422 template <class Vec = GfVec4h> constexpr Vec xzyw() const;
423 template <class Vec = GfVec4h> constexpr Vec xzwy() const;
424 template <class Vec = GfVec4h> constexpr Vec xwyz() const;
425 template <class Vec = GfVec4h> constexpr Vec xwzy() const;
426 template <class Vec = GfVec4h> constexpr Vec yxzw() const;
427 template <class Vec = GfVec4h> constexpr Vec yxwz() const;
428 template <class Vec = GfVec4h> constexpr Vec yzxw() const;
429 template <class Vec = GfVec4h> constexpr Vec yzwx() const;
430 template <class Vec = GfVec4h> constexpr Vec ywxz() const;
431 template <class Vec = GfVec4h> constexpr Vec ywzx() const;
432 template <class Vec = GfVec4h> constexpr Vec zxyw() const;
433 template <class Vec = GfVec4h> constexpr Vec zxwy() const;
434 template <class Vec = GfVec4h> constexpr Vec zyxw() const;
435 template <class Vec = GfVec4h> constexpr Vec zywx() const;
436 template <class Vec = GfVec4h> constexpr Vec zwxy() const;
437 template <class Vec = GfVec4h> constexpr Vec zwyx() const;
438 template <class Vec = GfVec4h> constexpr Vec wxyz() const;
439 template <class Vec = GfVec4h> constexpr Vec wxzy() const;
440 template <class Vec = GfVec4h> constexpr Vec wyxz() const;
441 template <class Vec = GfVec4h> constexpr Vec wyzx() const;
442 template <class Vec = GfVec4h> constexpr Vec wzxy() const;
443 template <class Vec = GfVec4h> constexpr Vec wzyx() const;
444#endif // doxygen
445 };
446
449GF_API std::ostream& operator<<(std::ostream &, GfVec4h const &);
450
451PXR_NAMESPACE_CLOSE_SCOPE
452
453// Other scalar types of the same dimension, for the conversions above.
454#include "pxr/base/gf/vec4d.h"
455#include "pxr/base/gf/vec4f.h"
456#include "pxr/base/gf/vec4i.h"
457// Lower dimensions of the same scalar type, for the swizzles above. Note that
458// lower dimensions never include higher ones, so this introduces no cycle.
459#include "pxr/base/gf/vec2h.h"
460#include "pxr/base/gf/vec3h.h"
461
462PXR_NAMESPACE_OPEN_SCOPE
463
464inline
465GfVec4h::GfVec4h(class GfVec4d const &other)
466{
467 x = other.x;
468 y = other.y;
469 z = other.z;
470 w = other.w;
471}
472inline
473GfVec4h::GfVec4h(class GfVec4f const &other)
474{
475 x = other.x;
476 y = other.y;
477 z = other.z;
478 w = other.w;
479}
480inline
481GfVec4h::GfVec4h(class GfVec4i const &other)
482{
483 x = other.x;
484 y = other.y;
485 z = other.z;
486 w = other.w;
487}
488
489template <class Vec>
490constexpr Vec
491GfVec4h::xy() const
492{
493 static_assert(std::is_same<Vec, GfVec2h>::value);
494 return Vec(x, y);
495}
496
497template <class Vec>
498constexpr Vec
499GfVec4h::xz() const
500{
501 static_assert(std::is_same<Vec, GfVec2h>::value);
502 return Vec(x, z);
503}
504
505template <class Vec>
506constexpr Vec
507GfVec4h::xw() const
508{
509 static_assert(std::is_same<Vec, GfVec2h>::value);
510 return Vec(x, w);
511}
512
513template <class Vec>
514constexpr Vec
515GfVec4h::yx() const
516{
517 static_assert(std::is_same<Vec, GfVec2h>::value);
518 return Vec(y, x);
519}
520
521template <class Vec>
522constexpr Vec
523GfVec4h::yz() const
524{
525 static_assert(std::is_same<Vec, GfVec2h>::value);
526 return Vec(y, z);
527}
528
529template <class Vec>
530constexpr Vec
531GfVec4h::yw() const
532{
533 static_assert(std::is_same<Vec, GfVec2h>::value);
534 return Vec(y, w);
535}
536
537template <class Vec>
538constexpr Vec
539GfVec4h::zx() const
540{
541 static_assert(std::is_same<Vec, GfVec2h>::value);
542 return Vec(z, x);
543}
544
545template <class Vec>
546constexpr Vec
547GfVec4h::zy() const
548{
549 static_assert(std::is_same<Vec, GfVec2h>::value);
550 return Vec(z, y);
551}
552
553template <class Vec>
554constexpr Vec
555GfVec4h::zw() const
556{
557 static_assert(std::is_same<Vec, GfVec2h>::value);
558 return Vec(z, w);
559}
560
561template <class Vec>
562constexpr Vec
563GfVec4h::wx() const
564{
565 static_assert(std::is_same<Vec, GfVec2h>::value);
566 return Vec(w, x);
567}
568
569template <class Vec>
570constexpr Vec
571GfVec4h::wy() const
572{
573 static_assert(std::is_same<Vec, GfVec2h>::value);
574 return Vec(w, y);
575}
576
577template <class Vec>
578constexpr Vec
579GfVec4h::wz() const
580{
581 static_assert(std::is_same<Vec, GfVec2h>::value);
582 return Vec(w, z);
583}
584
585template <class Vec>
586constexpr Vec
587GfVec4h::xyz() const
588{
589 static_assert(std::is_same<Vec, GfVec3h>::value);
590 return Vec(x, y, z);
591}
592
593template <class Vec>
594constexpr Vec
595GfVec4h::xyw() const
596{
597 static_assert(std::is_same<Vec, GfVec3h>::value);
598 return Vec(x, y, w);
599}
600
601template <class Vec>
602constexpr Vec
603GfVec4h::xzy() const
604{
605 static_assert(std::is_same<Vec, GfVec3h>::value);
606 return Vec(x, z, y);
607}
608
609template <class Vec>
610constexpr Vec
611GfVec4h::xzw() const
612{
613 static_assert(std::is_same<Vec, GfVec3h>::value);
614 return Vec(x, z, w);
615}
616
617template <class Vec>
618constexpr Vec
619GfVec4h::xwy() const
620{
621 static_assert(std::is_same<Vec, GfVec3h>::value);
622 return Vec(x, w, y);
623}
624
625template <class Vec>
626constexpr Vec
627GfVec4h::xwz() const
628{
629 static_assert(std::is_same<Vec, GfVec3h>::value);
630 return Vec(x, w, z);
631}
632
633template <class Vec>
634constexpr Vec
635GfVec4h::yxz() const
636{
637 static_assert(std::is_same<Vec, GfVec3h>::value);
638 return Vec(y, x, z);
639}
640
641template <class Vec>
642constexpr Vec
643GfVec4h::yxw() const
644{
645 static_assert(std::is_same<Vec, GfVec3h>::value);
646 return Vec(y, x, w);
647}
648
649template <class Vec>
650constexpr Vec
651GfVec4h::yzx() const
652{
653 static_assert(std::is_same<Vec, GfVec3h>::value);
654 return Vec(y, z, x);
655}
656
657template <class Vec>
658constexpr Vec
659GfVec4h::yzw() const
660{
661 static_assert(std::is_same<Vec, GfVec3h>::value);
662 return Vec(y, z, w);
663}
664
665template <class Vec>
666constexpr Vec
667GfVec4h::ywx() const
668{
669 static_assert(std::is_same<Vec, GfVec3h>::value);
670 return Vec(y, w, x);
671}
672
673template <class Vec>
674constexpr Vec
675GfVec4h::ywz() const
676{
677 static_assert(std::is_same<Vec, GfVec3h>::value);
678 return Vec(y, w, z);
679}
680
681template <class Vec>
682constexpr Vec
683GfVec4h::zxy() const
684{
685 static_assert(std::is_same<Vec, GfVec3h>::value);
686 return Vec(z, x, y);
687}
688
689template <class Vec>
690constexpr Vec
691GfVec4h::zxw() const
692{
693 static_assert(std::is_same<Vec, GfVec3h>::value);
694 return Vec(z, x, w);
695}
696
697template <class Vec>
698constexpr Vec
699GfVec4h::zyx() const
700{
701 static_assert(std::is_same<Vec, GfVec3h>::value);
702 return Vec(z, y, x);
703}
704
705template <class Vec>
706constexpr Vec
707GfVec4h::zyw() const
708{
709 static_assert(std::is_same<Vec, GfVec3h>::value);
710 return Vec(z, y, w);
711}
712
713template <class Vec>
714constexpr Vec
715GfVec4h::zwx() const
716{
717 static_assert(std::is_same<Vec, GfVec3h>::value);
718 return Vec(z, w, x);
719}
720
721template <class Vec>
722constexpr Vec
723GfVec4h::zwy() const
724{
725 static_assert(std::is_same<Vec, GfVec3h>::value);
726 return Vec(z, w, y);
727}
728
729template <class Vec>
730constexpr Vec
731GfVec4h::wxy() const
732{
733 static_assert(std::is_same<Vec, GfVec3h>::value);
734 return Vec(w, x, y);
735}
736
737template <class Vec>
738constexpr Vec
739GfVec4h::wxz() const
740{
741 static_assert(std::is_same<Vec, GfVec3h>::value);
742 return Vec(w, x, z);
743}
744
745template <class Vec>
746constexpr Vec
747GfVec4h::wyx() const
748{
749 static_assert(std::is_same<Vec, GfVec3h>::value);
750 return Vec(w, y, x);
751}
752
753template <class Vec>
754constexpr Vec
755GfVec4h::wyz() const
756{
757 static_assert(std::is_same<Vec, GfVec3h>::value);
758 return Vec(w, y, z);
759}
760
761template <class Vec>
762constexpr Vec
763GfVec4h::wzx() const
764{
765 static_assert(std::is_same<Vec, GfVec3h>::value);
766 return Vec(w, z, x);
767}
768
769template <class Vec>
770constexpr Vec
771GfVec4h::wzy() const
772{
773 static_assert(std::is_same<Vec, GfVec3h>::value);
774 return Vec(w, z, y);
775}
776
777template <class Vec>
778constexpr Vec
779GfVec4h::xyzw() const
780{
781 static_assert(std::is_same<Vec, GfVec4h>::value);
782 return Vec(x, y, z, w);
783}
784
785template <class Vec>
786constexpr Vec
787GfVec4h::xywz() const
788{
789 static_assert(std::is_same<Vec, GfVec4h>::value);
790 return Vec(x, y, w, z);
791}
792
793template <class Vec>
794constexpr Vec
795GfVec4h::xzyw() const
796{
797 static_assert(std::is_same<Vec, GfVec4h>::value);
798 return Vec(x, z, y, w);
799}
800
801template <class Vec>
802constexpr Vec
803GfVec4h::xzwy() const
804{
805 static_assert(std::is_same<Vec, GfVec4h>::value);
806 return Vec(x, z, w, y);
807}
808
809template <class Vec>
810constexpr Vec
811GfVec4h::xwyz() const
812{
813 static_assert(std::is_same<Vec, GfVec4h>::value);
814 return Vec(x, w, y, z);
815}
816
817template <class Vec>
818constexpr Vec
819GfVec4h::xwzy() const
820{
821 static_assert(std::is_same<Vec, GfVec4h>::value);
822 return Vec(x, w, z, y);
823}
824
825template <class Vec>
826constexpr Vec
827GfVec4h::yxzw() const
828{
829 static_assert(std::is_same<Vec, GfVec4h>::value);
830 return Vec(y, x, z, w);
831}
832
833template <class Vec>
834constexpr Vec
835GfVec4h::yxwz() const
836{
837 static_assert(std::is_same<Vec, GfVec4h>::value);
838 return Vec(y, x, w, z);
839}
840
841template <class Vec>
842constexpr Vec
843GfVec4h::yzxw() const
844{
845 static_assert(std::is_same<Vec, GfVec4h>::value);
846 return Vec(y, z, x, w);
847}
848
849template <class Vec>
850constexpr Vec
851GfVec4h::yzwx() const
852{
853 static_assert(std::is_same<Vec, GfVec4h>::value);
854 return Vec(y, z, w, x);
855}
856
857template <class Vec>
858constexpr Vec
859GfVec4h::ywxz() const
860{
861 static_assert(std::is_same<Vec, GfVec4h>::value);
862 return Vec(y, w, x, z);
863}
864
865template <class Vec>
866constexpr Vec
867GfVec4h::ywzx() const
868{
869 static_assert(std::is_same<Vec, GfVec4h>::value);
870 return Vec(y, w, z, x);
871}
872
873template <class Vec>
874constexpr Vec
875GfVec4h::zxyw() const
876{
877 static_assert(std::is_same<Vec, GfVec4h>::value);
878 return Vec(z, x, y, w);
879}
880
881template <class Vec>
882constexpr Vec
883GfVec4h::zxwy() const
884{
885 static_assert(std::is_same<Vec, GfVec4h>::value);
886 return Vec(z, x, w, y);
887}
888
889template <class Vec>
890constexpr Vec
891GfVec4h::zyxw() const
892{
893 static_assert(std::is_same<Vec, GfVec4h>::value);
894 return Vec(z, y, x, w);
895}
896
897template <class Vec>
898constexpr Vec
899GfVec4h::zywx() const
900{
901 static_assert(std::is_same<Vec, GfVec4h>::value);
902 return Vec(z, y, w, x);
903}
904
905template <class Vec>
906constexpr Vec
907GfVec4h::zwxy() const
908{
909 static_assert(std::is_same<Vec, GfVec4h>::value);
910 return Vec(z, w, x, y);
911}
912
913template <class Vec>
914constexpr Vec
915GfVec4h::zwyx() const
916{
917 static_assert(std::is_same<Vec, GfVec4h>::value);
918 return Vec(z, w, y, x);
919}
920
921template <class Vec>
922constexpr Vec
923GfVec4h::wxyz() const
924{
925 static_assert(std::is_same<Vec, GfVec4h>::value);
926 return Vec(w, x, y, z);
927}
928
929template <class Vec>
930constexpr Vec
931GfVec4h::wxzy() const
932{
933 static_assert(std::is_same<Vec, GfVec4h>::value);
934 return Vec(w, x, z, y);
935}
936
937template <class Vec>
938constexpr Vec
939GfVec4h::wyxz() const
940{
941 static_assert(std::is_same<Vec, GfVec4h>::value);
942 return Vec(w, y, x, z);
943}
944
945template <class Vec>
946constexpr Vec
947GfVec4h::wyzx() const
948{
949 static_assert(std::is_same<Vec, GfVec4h>::value);
950 return Vec(w, y, z, x);
951}
952
953template <class Vec>
954constexpr Vec
955GfVec4h::wzxy() const
956{
957 static_assert(std::is_same<Vec, GfVec4h>::value);
958 return Vec(w, z, x, y);
959}
960
961template <class Vec>
962constexpr Vec
963GfVec4h::wzyx() const
964{
965 static_assert(std::is_same<Vec, GfVec4h>::value);
966 return Vec(w, z, y, x);
967}
968
969
971inline GfVec4h
972GfCompMult(GfVec4h const &v1, GfVec4h const &v2) {
973 return GfVec4h(
974 v1.x * v2.x,
975 v1.y * v2.y,
976 v1.z * v2.z,
977 v1.w * v2.w
978 );
979}
980
982inline GfVec4h
983GfCompDiv(GfVec4h const &v1, GfVec4h const &v2) {
984 return GfVec4h(
985 v1.x / v2.x,
986 v1.y / v2.y,
987 v1.z / v2.z,
988 v1.w / v2.w
989 );
990}
991
993inline GfHalf
994GfDot(GfVec4h const &v1, GfVec4h const &v2) {
995 return v1 * v2;
996}
997
998
1000inline GfHalf
1002{
1003 return v.GetLength();
1004}
1005
1009inline GfHalf
1011{
1012 return v->Normalize(eps);
1013}
1014
1018inline GfVec4h
1019GfGetNormalized(GfVec4h const &v, GfHalf eps = 0.001)
1020{
1021 return v.GetNormalized(eps);
1022}
1023
1028inline GfVec4h
1030{
1031 return a.GetProjection(b);
1032}
1033
1038inline GfVec4h
1040{
1041 return a.GetComplement(b);
1042}
1043
1046inline bool
1047GfIsClose(GfVec4h const &v1, GfVec4h const &v2, double tolerance)
1048{
1049 GfVec4h delta = v1 - v2;
1050 return delta.GetLengthSq() <= tolerance * tolerance;
1051}
1052
1053
1054
1055PXR_NAMESPACE_CLOSE_SCOPE
1056
1057#endif // PXR_BASE_GF_VEC4H_H
Low-level utilities for informing users of various internal and external diagnostic conditions.
Basic type for a vector of 2 GfHalf components.
Definition vec2h.h:47
Basic type for a vector of 3 GfHalf components.
Definition vec3h.h:48
Basic type for a vector of 4 double components.
Definition vec4d.h:48
Basic type for a vector of 4 float components.
Definition vec4f.h:48
Basic type for a vector of 4 GfHalf components.
Definition vec4h.h:49
GfVec4h GetComplement(GfVec4h const &b) const
Returns the orthogonal complement of this->GetProjection(b).
Definition vec4h.h:265
static GfVec4h ZAxis()
Create a unit vector along the Z-axis.
Definition vec4h.h:115
GfHalf ScalarType
Scalar element type and dimension.
Definition vec4h.h:52
GfVec4h & operator-=(GfVec4h const &other)
Subtraction.
Definition vec4h.h:209
static GfVec4h YAxis()
Create a unit vector along the Y-axis.
Definition vec4h.h:108
static GfVec4h WAxis()
Create a unit vector along the W-axis.
Definition vec4h.h:122
GfHalf GetLength() const
Length.
Definition vec4h.h:275
GfHalf operator*(GfVec4h const &v) const
See GfDot().
Definition vec4h.h:248
constexpr GfVec4h(Scl const *p)
Construct with pointer to values.
Definition vec4h.h:87
GfVec4h operator-() const
Create a vec with negated elements.
Definition vec4h.h:192
GfVec4h & Set(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Set all elements with passed arguments.
Definition vec4h.h:138
constexpr GfVec4h(GfHalf s0, GfHalf s1, GfHalf s2, GfHalf s3)
Initialize all elements with explicit arguments.
Definition vec4h.h:80
GfHalf Normalize(GfHalf eps=0.001)
Normalizes the vector in place to unit length, returning the length before normalization.
Definition vec4h.h:287
GfVec4h()=default
GfVec4h value-initializes to zero and performs no default initialization, like float or double.
friend size_t hash_value(GfVec4h const &vec)
Hash.
Definition vec4h.h:165
GfVec4h & operator/=(double s)
Division by scalar.
Definition vec4h.h:237
GfHalf GetLengthSq() const
Squared length.
Definition vec4h.h:270
GF_API bool operator==(class GfVec4f const &other) const
Equality comparison.
GfVec4h & Set(GfHalf const *a)
Set all elements with a pointer to data.
Definition vec4h.h:147
GF_API bool operator==(class GfVec4i const &other) const
Equality comparison.
GfHalf const & operator[](size_t i) const
Indexing.
Definition vec4h.h:161
GfHalf const * data() const
Direct data access.
Definition vec4h.h:156
GF_API bool operator==(class GfVec4d const &other) const
Equality comparison.
GfVec4h & operator*=(double s)
Multiplication by scalar.
Definition vec4h.h:221
static GfVec4h XAxis()
Create a unit vector along the X-axis.
Definition vec4h.h:101
GfVec4h GetProjection(GfVec4h const &v) const
Returns the projection of this onto v.
Definition vec4h.h:256
GfVec4h & operator+=(GfVec4h const &other)
Addition.
Definition vec4h.h:197
bool operator==(GfVec4h const &other) const
Equality comparison.
Definition vec4h.h:170
static GfVec4h Axis(size_t i)
Create a unit vector along the i-th axis, zero-based.
Definition vec4h.h:130
constexpr GfVec4h(GfHalf value)
Initialize all elements to a single value.
Definition vec4h.h:74
Basic type for a vector of 4 int components.
Definition vec4i.h:46
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition hash.h:487
Assorted mathematical utility functions.
double GfSqrt(double f)
Return sqrt(f).
Definition math.h:190
GF_API std::ostream & operator<<(std::ostream &, GfVec4h const &)
Output a GfVec4h.
This header serves to simply bring in the half float datatype and provide a hash_value function.
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition half.h:26
Defines useful mathematical limits.
A metafunction with a static const bool member 'value' that is true for GfVec types,...
Definition traits.h:23
GfVec4h GfGetComplement(GfVec4h const &a, GfVec4h const &b)
Returns the orthogonal complement of a.GetProjection(b).
Definition vec4h.h:1039
bool GfIsClose(GfVec4h const &v1, GfVec4h const &v2, double tolerance)
Tests for equality within a given tolerance, returning true if the length of the difference vector is...
Definition vec4h.h:1047
GfHalf GfNormalize(GfVec4h *v, GfHalf eps=0.001)
Normalizes *v in place to unit length, returning the length before normalization.
Definition vec4h.h:1010
GfVec4h GfCompDiv(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition vec4h.h:983
GfHalf GfDot(GfVec4h const &v1, GfVec4h const &v2)
Returns the dot (inner) product of two vectors.
Definition vec4h.h:994
GfVec4h GfGetNormalized(GfVec4h const &v, GfHalf eps=0.001)
Returns a normalized (unit-length) vector with the same direction as v.
Definition vec4h.h:1019
GfVec4h GfCompMult(GfVec4h const &v1, GfVec4h const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition vec4h.h:972
GfVec4h GfGetProjection(GfVec4h const &a, GfVec4h const &b)
Returns the projection of a onto b.
Definition vec4h.h:1029
GfHalf GfGetLength(GfVec4h const &v)
Returns the geometric length of v.
Definition vec4h.h:1001