OpenVDB 13.2.0
Loading...
Searching...
No Matches
VecBase< T, N > Class Template Reference

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]

Detailed Description

template<typename T, int N>
class nanovdb::math::VecBase< T, 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).

Member Typedef Documentation

◆ ValueType

template<typename T, int N>
using ValueType = T

Constructor & Destructor Documentation

◆ VecBase() [1/2]

template<typename T, int N>
VecBase ( )
defaultnoexcept

Default-construct (mVec is left uninitialized for trivially-default-constructible T).

◆ VecBase() [2/2]

template<typename T, int N>
template<typename... Args>
__hostdev__ constexpr VecBase ( Args... args)
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.

Member Function Documentation

◆ addAssign()

template<typename T, int N>
__hostdev__ constexpr VecBase & addAssign ( const VecBase< T, N > & rhs)
inlineconstexprnoexcept

Component-wise add rhs into *this and return *this.

◆ asPointer() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T * asPointer ( ) const
inlineconstexprnoexcept

◆ asPointer() [2/2]

template<typename T, int N>
__hostdev__ constexpr T * asPointer ( )
inlineconstexprnoexcept

raw pointer to the underlying N-element storage

◆ ceilAs()

template<typename T, int N>
template<typename Result>
__hostdev__ constexpr Result ceilAs ( ) const
inlinenodiscardconstexprnoexcept

ceil-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through.

Note
Only the integer-T specialization is usable as a constant expression; the floating-point branch calls math::Ceil, which isn't constexpr until C++23.

◆ div()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived div ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

Return component-wise *this / rhs as a Derived.

◆ divAssign()

template<typename T, int N>
__hostdev__ constexpr VecBase & divAssign ( const VecBase< T, N > & rhs)
inlineconstexprnoexcept

Component-wise divide *this by rhs and return *this.

◆ divideAssignScalar()

template<typename T, int N>
__hostdev__ constexpr VecBase & divideAssignScalar ( T s)
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.

◆ divideBy()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived divideBy ( T s) const
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.

◆ dot()

template<typename T, int N>
template<typename V>
__hostdev__ constexpr T dot ( const V & v) const
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.

◆ equals()

template<typename T, int N>
__hostdev__ constexpr bool equals ( const VecBase< T, N > & rhs) const
inlinenodiscardconstexprnoexcept

Return true iff every component compares equal to rhs.

◆ floorAs()

template<typename T, int N>
template<typename Result>
__hostdev__ constexpr Result floorAs ( ) const
inlinenodiscardconstexprnoexcept

floor-rounded components into the Result type (whose [i] must accept int32_t). For integer T the value is passed through.

Note
Only the integer-T specialization is usable as a constant expression; the floating-point branch calls math::Floor, which isn't constexpr until C++23.

◆ generate() [1/2]

template<typename T, int N>
template<typename Derived, typename F>
__hostdev__ constexpr Derived generate ( F f)
inlinestaticconstexprprotectednoexcept

◆ generate() [2/2]

template<typename T, int N>
template<typename Derived, typename F, int... I>
__hostdev__ constexpr Derived generate ( F f,
std::integer_sequence< int, I... >  )
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.

◆ largestComponent()

template<typename T, int N>
__hostdev__ constexpr T largestComponent ( ) const
inlinenodiscardconstexprnoexcept

return the largest of the N components

◆ length()

template<typename T, int N>
__hostdev__ T length ( ) const
inlinenodiscardnoexcept

L2 length (Euclidean norm). Not constexpr — calls Sqrt.

◆ lengthSqr()

template<typename T, int N>
__hostdev__ constexpr T lengthSqr ( ) const
inlinenodiscardconstexprnoexcept

Squared L2 length (sum of squared components). Constexpr, no sqrt.

◆ mergeMax()

template<typename T, int N>
template<typename V>
__hostdev__ constexpr VecBase & mergeMax ( const V & other)
inlineconstexprnoexcept

Component-wise take the max of *this and other (in place); return *this.

◆ mergeMin()

template<typename T, int N>
template<typename V>
__hostdev__ constexpr VecBase & mergeMin ( const V & other)
inlineconstexprnoexcept

Component-wise take the min of *this and other (in place); return *this.

◆ minus()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived minus ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

Return *this - rhs as a Derived.

◆ mul()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived mul ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

Return component-wise *this * rhs as a Derived (Hadamard product).

◆ mulAssign()

template<typename T, int N>
__hostdev__ constexpr VecBase & mulAssign ( const VecBase< T, N > & rhs)
inlineconstexprnoexcept

Component-wise multiply *this by rhs (Hadamard product) and return *this.

◆ negate()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived negate ( ) const
inlinenodiscardconstexprnoexcept

Return -(*this) as a Derived.

◆ normalized()

template<typename T, int N>
template<typename Derived>
__hostdev__ Derived normalized ( ) const
inlinenodiscardnoexcept

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.

◆ operator[]() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T & operator[] ( int i) const
inlineconstexprnoexcept

Indexed element access. Asserts 0 <= i < N in debug builds.

◆ operator[]() [2/2]

template<typename T, int N>
__hostdev__ constexpr T & operator[] ( int i)
inlineconstexprnoexcept

◆ plus()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived plus ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

Return *this + rhs as a Derived.

◆ roundAs()

template<typename T, int N>
template<typename Result>
__hostdev__ constexpr Result roundAs ( ) const
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.

Note
See floorAs — only the integer-T branch is constexpr-usable.

◆ scale()

template<typename T, int N>
template<typename Derived>
__hostdev__ constexpr Derived scale ( T s) const
inlinenodiscardconstexprnoexcept

Return s * (*this) as a Derived (scalar broadcast).

◆ scaleAssign()

template<typename T, int N>
__hostdev__ constexpr VecBase & scaleAssign ( T s)
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.

◆ smallestComponent()

template<typename T, int N>
__hostdev__ constexpr T smallestComponent ( ) const
inlinenodiscardconstexprnoexcept

return the smallest of the N components

◆ subAssign()

template<typename T, int N>
__hostdev__ constexpr VecBase & subAssign ( const VecBase< T, N > & rhs)
inlineconstexprnoexcept

Component-wise subtract rhs from *this and return *this.

◆ w() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T & w ( ) const
inlineconstexprnoexcept

◆ w() [2/2]

template<typename T, int N>
__hostdev__ constexpr T & w ( )
inlineconstexprnoexcept

◆ x() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T & x ( ) const
inlineconstexprnoexcept

◆ x() [2/2]

template<typename T, int N>
__hostdev__ constexpr T & x ( )
inlineconstexprnoexcept

◆ y() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T & y ( ) const
inlineconstexprnoexcept

◆ y() [2/2]

template<typename T, int N>
__hostdev__ constexpr T & y ( )
inlineconstexprnoexcept

◆ z() [1/2]

template<typename T, int N>
__hostdev__ constexpr const T & z ( ) const
inlineconstexprnoexcept

◆ z() [2/2]

template<typename T, int N>
__hostdev__ constexpr T & z ( )
inlineconstexprnoexcept

Member Data Documentation

◆ mVec

template<typename T, int N>
T mVec[N]
protected

◆ SIZE

template<typename T, int N>
int SIZE = N
staticconstexpr