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