![]() |
OpenVDB 13.2.0
|
Base class for fixed-size vectors. Provides shared element-wise arithmetic, scalar arithmetic, equality, length/dot reductions, component min/max, and integer-coord rounding. Derived classes provide constructors and any dimension-specific extras (e.g. cross/outer on Vec3). More...
#include <nanovdb/math/Math.h>
Public Types | |
| using | ValueType = T |
Public Member Functions | |
| VecBase () noexcept=default | |
Default-construct (mVec is left uninitialized for trivially-default-constructible T). | |
| __hostdev__ constexpr const T & | operator[] (int i) const noexcept |
| Indexed element access. Asserts 0 <= i < N in debug builds. | |
| __hostdev__ constexpr T & | operator[] (int i) noexcept |
| __hostdev__ constexpr const T & | x () const noexcept |
| __hostdev__ constexpr T & | x () noexcept |
| __hostdev__ constexpr const T & | y () const noexcept |
| __hostdev__ constexpr T & | y () noexcept |
| __hostdev__ constexpr const T & | z () const noexcept |
| __hostdev__ constexpr T & | z () noexcept |
| __hostdev__ constexpr const T & | w () const noexcept |
| __hostdev__ constexpr T & | w () noexcept |
| __hostdev__ constexpr T * | asPointer () noexcept |
| raw pointer to the underlying N-element storage | |
| __hostdev__ constexpr const T * | asPointer () const noexcept |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | plus (const Derived &rhs) const noexcept |
Return *this + rhs as a Derived. | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | minus (const Derived &rhs) const noexcept |
Return *this - rhs as a Derived. | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | mul (const Derived &rhs) const noexcept |
Return component-wise *this * rhs as a Derived (Hadamard product). | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | div (const Derived &rhs) const noexcept |
Return component-wise *this / rhs as a Derived. | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | negate () const noexcept |
Return -(*this) as a Derived. | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | scale (T s) const noexcept |
Return s * (*this) as a Derived (scalar broadcast). | |
| template<typename Derived> | |
| __hostdev__ constexpr Derived | divideBy (T s) const noexcept |
Return (*this) / s element-wise as a Derived. Floating-point T multiplies by the reciprocal 1/s; integer T divides each element, since 1/s would truncate to zero. | |
| template<typename Derived> | |
| __hostdev__ Derived | normalized () const noexcept |
Return a unit-length copy (*this divided by length()) as a Derived. Const, non-mutating counterpart of the derived normalize(). Not constexpr — length() calls Sqrt. | |
| __hostdev__ constexpr VecBase & | addAssign (const VecBase &rhs) noexcept |
Component-wise add rhs into *this and return *this. | |
| __hostdev__ constexpr VecBase & | subAssign (const VecBase &rhs) noexcept |
Component-wise subtract rhs from *this and return *this. | |
| __hostdev__ constexpr VecBase & | mulAssign (const VecBase &rhs) noexcept |
Component-wise multiply *this by rhs (Hadamard product) and return *this. | |
| __hostdev__ constexpr VecBase & | divAssign (const VecBase &rhs) noexcept |
Component-wise divide *this by rhs and return *this. | |
| __hostdev__ constexpr VecBase & | scaleAssign (T s) noexcept |
Multiply every component by scalar s in place; return *this. s is taken by value so v *= v[0] scales every component by the original value. | |
| __hostdev__ constexpr VecBase & | divideAssignScalar (T s) noexcept |
Divide every component by scalar s in place; return *this. Uses the same floating-point reciprocal / integer per-element split as divideBy. s is taken by value so v /= v[0] is safe. | |
| __hostdev__ constexpr bool | equals (const VecBase &rhs) const noexcept |
Return true iff every component compares equal to rhs. | |
| template<typename V> | |
| __hostdev__ constexpr T | dot (const V &v) const noexcept |
dot product. V must have operator[] valid for 0..N-1. Sums in the promoted type of the element products and converts to T once on return, so e.g. Vec3i::dot(Vec3d) does not truncate partial sums. | |
| __hostdev__ constexpr T | lengthSqr () const noexcept |
| Squared L2 length (sum of squared components). Constexpr, no sqrt. | |
| __hostdev__ T | length () const noexcept |
L2 length (Euclidean norm). Not constexpr — calls Sqrt. | |
| __hostdev__ constexpr T | smallestComponent () const noexcept |
| return the smallest of the N components | |
| __hostdev__ constexpr T | largestComponent () const noexcept |
| return the largest of the N components | |
| template<typename V> | |
| __hostdev__ constexpr VecBase & | mergeMin (const V &other) noexcept |
Component-wise take the min of *this and other (in place); return *this. | |
| template<typename V> | |
| __hostdev__ constexpr VecBase & | mergeMax (const V &other) noexcept |
Component-wise take the max of *this and other (in place); return *this. | |
| template<typename Result> | |
| __hostdev__ constexpr Result | floorAs () const noexcept |
floor-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through. | |
| template<typename Result> | |
| __hostdev__ constexpr Result | ceilAs () const noexcept |
ceil-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through. | |
| template<typename Result> | |
| __hostdev__ constexpr Result | roundAs () const noexcept |
nearest-integer rounding for floating T via the scalar math::Round (halfway cases toward +inf, exact for every input), so float and double agree; pass-through for integer T. | |
Static Public Attributes | |
| static constexpr int | SIZE = N |
Protected Member Functions | |
| template<typename... Args> | |
| __hostdev__ constexpr | VecBase (Args... args) noexcept |
Variadic component-init ctor — used only by derived ctors (Vec2(T x, T y) : Base(x, y) {}). The member-init list directly initializes mVec, avoiding the default-construct-then-assign that a body-assignment ctor would impose on a non-fundamental T. | |
Static Protected Member Functions | |
| template<typename Derived, typename F, int... I> | |
| static __hostdev__ constexpr Derived | generate (F f, std::integer_sequence< int, I... >) noexcept |
Return a Derived whose component i is f(i), built through its N-component constructor. This is constexpr-valid in C++17 without first value-initializing a result and overwriting it. | |
| template<typename Derived, typename F> | |
| static __hostdev__ constexpr Derived | generate (F f) noexcept |
Protected Attributes | |
| T | mVec [N] |
Base class for fixed-size vectors. Provides shared element-wise arithmetic, scalar arithmetic, equality, length/dot reductions, component min/max, and integer-coord rounding. Derived classes provide constructors and any dimension-specific extras (e.g. cross/outer on Vec3).
| using ValueType = T |
|
defaultnoexcept |
Default-construct (mVec is left uninitialized for trivially-default-constructible T).
|
inlineexplicitconstexprprotectednoexcept |
Variadic component-init ctor — used only by derived ctors (Vec2(T x, T y) : Base(x, y) {}). The member-init list directly initializes mVec, avoiding the default-construct-then-assign that a body-assignment ctor would impose on a non-fundamental T.
|
inlineconstexprnoexcept |
Component-wise add rhs into *this and return *this.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
raw pointer to the underlying N-element storage
|
inlinenodiscardconstexprnoexcept |
ceil-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through.
T specialization is usable as a constant expression; the floating-point branch calls math::Ceil, which isn't constexpr until C++23.
|
inlinenodiscardconstexprnoexcept |
Return component-wise *this / rhs as a Derived.
|
inlineconstexprnoexcept |
Component-wise divide *this by rhs and return *this.
|
inlineconstexprnoexcept |
Divide every component by scalar s in place; return *this. Uses the same floating-point reciprocal / integer per-element split as divideBy. s is taken by value so v /= v[0] is safe.
|
inlinenodiscardconstexprnoexcept |
Return (*this) / s element-wise as a Derived. Floating-point T multiplies by the reciprocal 1/s; integer T divides each element, since 1/s would truncate to zero.
|
inlinenodiscardconstexprnoexcept |
dot product. V must have operator[] valid for 0..N-1. Sums in the promoted type of the element products and converts to T once on return, so e.g. Vec3i::dot(Vec3d) does not truncate partial sums.
|
inlinenodiscardconstexprnoexcept |
Return true iff every component compares equal to rhs.
|
inlinenodiscardconstexprnoexcept |
floor-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through.
T specialization is usable as a constant expression; the floating-point branch calls math::Floor, which isn't constexpr until C++23.
|
inlinestaticconstexprprotectednoexcept |
|
inlinestaticconstexprprotectednoexcept |
Return a Derived whose component i is f(i), built through its N-component constructor. This is constexpr-valid in C++17 without first value-initializing a result and overwriting it.
|
inlinenodiscardconstexprnoexcept |
return the largest of the N components
|
inlinenodiscardnoexcept |
L2 length (Euclidean norm). Not constexpr — calls Sqrt.
|
inlinenodiscardconstexprnoexcept |
Squared L2 length (sum of squared components). Constexpr, no sqrt.
|
inlineconstexprnoexcept |
Component-wise take the max of *this and other (in place); return *this.
|
inlineconstexprnoexcept |
Component-wise take the min of *this and other (in place); return *this.
|
inlinenodiscardconstexprnoexcept |
Return *this - rhs as a Derived.
|
inlinenodiscardconstexprnoexcept |
Return component-wise *this * rhs as a Derived (Hadamard product).
|
inlineconstexprnoexcept |
Component-wise multiply *this by rhs (Hadamard product) and return *this.
|
inlinenodiscardconstexprnoexcept |
Return -(*this) as a Derived.
|
inlinenodiscardnoexcept |
|
inlineconstexprnoexcept |
Indexed element access. Asserts 0 <= i < N in debug builds.
|
inlineconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Return *this + rhs as a Derived.
|
inlinenodiscardconstexprnoexcept |
nearest-integer rounding for floating T via the scalar math::Round (halfway cases toward +inf, exact for every input), so float and double agree; pass-through for integer T.
floorAs — only the integer-T branch is constexpr-usable.
|
inlinenodiscardconstexprnoexcept |
Return s * (*this) as a Derived (scalar broadcast).
|
inlineconstexprnoexcept |
Multiply every component by scalar s in place; return *this. s is taken by value so v *= v[0] scales every component by the original value.
|
inlinenodiscardconstexprnoexcept |
return the smallest of the N components
|
inlineconstexprnoexcept |
Component-wise subtract rhs from *this and return *this.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
protected |
|
staticconstexpr |