OpenVDB 14.0.0
Loading...
Searching...
No Matches
Vec2< T > Class Template Reference

A simple vector class with two components, similar to openvdb::math::Vec2. More...

#include <nanovdb/math/Math.h>

Public Types

using ValueType = T

Public Member Functions

 Vec2 () noexcept=default
 Default-construct (components are left uninitialized for fundamental T).
__hostdev__ constexpr Vec2 (T x) noexcept
 Broadcast: set both components to x.
__hostdev__ constexpr Vec2 (T x, T y) noexcept
 Component-wise construction.
template<template< class > class Vec2T, class T2>
__hostdev__ constexpr Vec2 (const Vec2T< T2 > &v) noexcept
 Explicit cross-template converting ctor (e.g. from openvdb::Vec2). Convert a foreign vector with a cast, e.g. Vec2<float>(v).
template<typename T2>
__hostdev__ constexpr Vec2 (const Vec2< T2 > &v) noexcept
 Explicit cross-precision conversion within nanovdb (e.g. Vec2d → Vec2f).
__hostdev__ constexpr Vec2 (const Coord2 &ijk) noexcept
 Construct from a 2D integer coordinate.
template<template< class > class Vec2T, class T2>
__hostdev__ constexpr Vec2 & operator= (const Vec2T< T2 > &rhs) noexcept
 Assign from any 2-component vector type (foreign or nanovdb).
__hostdev__ constexpr Vec2 operator- () const noexcept
 Component-wise negation.
__hostdev__ constexpr Vec2 operator+ (const Vec2 &v) const noexcept
 Component-wise sum.
__hostdev__ constexpr Vec2 operator- (const Vec2 &v) const noexcept
 Component-wise difference.
__hostdev__ constexpr Vec2 operator* (const Vec2 &v) const noexcept
 Component-wise (Hadamard) product.
__hostdev__ constexpr Vec2 operator/ (const Vec2 &v) const noexcept
 Component-wise division.
__hostdev__ constexpr Vec2 & operator+= (const Vec2 &v) noexcept
 In-place component-wise addition.
__hostdev__ constexpr Vec2 & operator-= (const Vec2 &v) noexcept
 In-place component-wise subtraction.
__hostdev__ constexpr Vec2 operator+ (const Coord2 &ijk) const noexcept
 Add an integer Coord2 to this vector (component-wise).
__hostdev__ constexpr Vec2 operator- (const Coord2 &ijk) const noexcept
 Subtract an integer Coord2 from this vector (component-wise).
__hostdev__ constexpr Vec2 & operator+= (const Coord2 &ijk) noexcept
 In-place component-wise addition of an integer Coord2.
__hostdev__ constexpr Vec2 & operator-= (const Coord2 &ijk) noexcept
 In-place component-wise subtraction of an integer Coord2.
__hostdev__ constexpr Vec2 operator* (const T &s) const noexcept
 Component-wise multiply by scalar s.
__hostdev__ constexpr Vec2 operator/ (const T &s) const noexcept
 Component-wise divide by scalar s (integer-safe).
__hostdev__ constexpr Vec2 & operator*= (const T &s) noexcept
 In-place component-wise multiply by scalar s.
__hostdev__ constexpr Vec2 & operator/= (const T &s) noexcept
 In-place component-wise divide by scalar s.
__hostdev__ Vec2 & normalize () noexcept
 Normalize in place (divide by length()). Not constexpr — calls std::sqrt.
__hostdev__ Vec2 normalized () const noexcept
 Return a normalized (unit-length) copy; const counterpart of normalize().
__hostdev__ constexpr bool operator== (const Vec2 &rhs) const noexcept
 Component-wise equality.
__hostdev__ constexpr bool operator!= (const Vec2 &rhs) const noexcept
 Component-wise inequality.
__hostdev__ constexpr Vec2 & minComponent (const Vec2 &other) noexcept
 Take the component-wise minimum of *this and other in place.
__hostdev__ constexpr Vec2 & maxComponent (const Vec2 &other) noexcept
 Take the component-wise maximum of *this and other in place.
__hostdev__ constexpr ValueType min () const noexcept
 Return the smallest vector component.
__hostdev__ constexpr ValueType max () const noexcept
 Return the largest vector component.
__hostdev__ constexpr Coord2 floor () const noexcept
 Round each component down (toward negative infinity)
__hostdev__ constexpr Coord2 ceil () const noexcept
 Round each component up (toward positive infinity)
__hostdev__ constexpr Coord2 round () const noexcept
 Round each component to its closest integer value.
__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
__hostdev__ constexpr Derived plus (const Derived &rhs) const noexcept
 Return *this + rhs as a Derived.
__hostdev__ constexpr Derived minus (const Derived &rhs) const noexcept
 Return *this - rhs as a Derived.
__hostdev__ constexpr Derived mul (const Derived &rhs) const noexcept
 Return component-wise *this * rhs as a Derived (Hadamard product).
__hostdev__ constexpr Derived div (const Derived &rhs) const noexcept
 Return component-wise *this / rhs as a Derived.
__hostdev__ constexpr Derived negate () const noexcept
 Return -(*this) as a Derived.
__hostdev__ constexpr Derived scale (T s) const noexcept
 Return s * (*this) as a Derived (scalar broadcast).
__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.
__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.
__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
__hostdev__ constexpr VecBase & mergeMin (const V &other) noexcept
 Component-wise take the min of *this and other (in place); return *this.
__hostdev__ constexpr VecBase & mergeMax (const V &other) noexcept
 Component-wise take the max of *this and other (in place); return *this.
__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.
__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.
__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 = 2
static constexpr int SIZE

Static Protected Member Functions

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.
static __hostdev__ constexpr Derived generate (F f) noexcept

Protected Attributes

T mVec [N]

Friends

template<typename T1>
__hostdev__ friend constexpr Vec2 operator* (T1 scalar, const Vec2 &vec) noexcept
 Scalar-on-the-left multiplication (hidden friend).
template<typename T1>
__hostdev__ friend constexpr Vec2 operator/ (T1 scalar, const Vec2 &vec) noexcept
 Scalar-on-the-left division (hidden friend).

Detailed Description

template<typename T>
class nanovdb::math::Vec2< T >

A simple vector class with two components, similar to openvdb::math::Vec2.

Naturally aligned (alignof(T)), like all Vec/Mat classes. Raising the alignment would change the layout of every struct and buffer that holds one; use Vec2Aligned for over-aligned arrays.

Member Typedef Documentation

◆ ValueType

template<typename T>
using ValueType = T

Constructor & Destructor Documentation

◆ Vec2() [1/6]

template<typename T>
Vec2 ( )
defaultnoexcept

Default-construct (components are left uninitialized for fundamental T).

◆ Vec2() [2/6]

template<typename T>
__hostdev__ constexpr Vec2 ( T x)
inlineexplicitconstexprnoexcept

Broadcast: set both components to x.

◆ Vec2() [3/6]

template<typename T>
__hostdev__ constexpr Vec2 ( T x,
T y )
inlineconstexprnoexcept

Component-wise construction.

◆ Vec2() [4/6]

template<typename T>
template<template< class > class Vec2T, class T2>
__hostdev__ constexpr Vec2 ( const Vec2T< T2 > & v)
inlineexplicitconstexprnoexcept

Explicit cross-template converting ctor (e.g. from openvdb::Vec2). Convert a foreign vector with a cast, e.g. Vec2<float>(v).

◆ Vec2() [5/6]

template<typename T>
template<typename T2>
__hostdev__ constexpr Vec2 ( const Vec2< T2 > & v)
inlineexplicitconstexprnoexcept

Explicit cross-precision conversion within nanovdb (e.g. Vec2d → Vec2f).

◆ Vec2() [6/6]

template<typename T>
__hostdev__ constexpr Vec2 ( const Coord2 & ijk)
inlineexplicitconstexprnoexcept

Construct from a 2D integer coordinate.

Member Function Documentation

◆ addAssign()

__hostdev__ constexpr VecBase & addAssign ( const VecBase< T, 2 > & rhs)
inlineconstexprnoexceptinherited

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

◆ asPointer() [1/2]

__hostdev__ constexpr const T * asPointer ( ) const
inlineconstexprnoexceptinherited

◆ asPointer() [2/2]

__hostdev__ constexpr T * asPointer ( )
inlineconstexprnoexceptinherited

raw pointer to the underlying N-element storage

◆ ceil()

template<typename T>
__hostdev__ constexpr Coord2 ceil ( ) const
inlinenodiscardconstexprnoexcept

Round each component up (toward positive infinity)

Returns
integer Coord2
Note
Only constexpr for integer T (ceilAs uses non-constexpr math::Ceil for floating point).

◆ ceilAs()

__hostdev__ constexpr Result ceilAs ( ) const
inlinenodiscardconstexprnoexceptinherited

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()

__hostdev__ constexpr Derived div ( const Derived & rhs) const
inlinenodiscardconstexprnoexceptinherited

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

◆ divAssign()

__hostdev__ constexpr VecBase & divAssign ( const VecBase< T, 2 > & rhs)
inlineconstexprnoexceptinherited

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

◆ divideAssignScalar()

__hostdev__ constexpr VecBase & divideAssignScalar ( T s)
inlineconstexprnoexceptinherited

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()

__hostdev__ constexpr Derived divideBy ( T s) const
inlinenodiscardconstexprnoexceptinherited

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()

__hostdev__ constexpr T dot ( const V & v) const
inlinenodiscardconstexprnoexceptinherited

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()

__hostdev__ constexpr bool equals ( const VecBase< T, 2 > & rhs) const
inlinenodiscardconstexprnoexceptinherited

Return true iff every component compares equal to rhs.

◆ floor()

template<typename T>
__hostdev__ constexpr Coord2 floor ( ) const
inlinenodiscardconstexprnoexcept

Round each component down (toward negative infinity)

Returns
integer Coord2
Note
Only constexpr for integer T (floorAs uses non-constexpr math::Floor for floating point).

◆ floorAs()

__hostdev__ constexpr Result floorAs ( ) const
inlinenodiscardconstexprnoexceptinherited

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]

__hostdev__ constexpr Derived generate ( F f)
inlinestaticconstexprprotectednoexceptinherited

◆ generate() [2/2]

__hostdev__ constexpr Derived generate ( F f,
std::integer_sequence< int, I... >  )
inlinestaticconstexprprotectednoexceptinherited

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()

__hostdev__ constexpr T largestComponent ( ) const
inlinenodiscardconstexprnoexceptinherited

return the largest of the N components

◆ length()

__hostdev__ T length ( ) const
inlinenodiscardnoexceptinherited

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

◆ lengthSqr()

__hostdev__ constexpr T lengthSqr ( ) const
inlinenodiscardconstexprnoexceptinherited

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

◆ max()

template<typename T>
__hostdev__ constexpr ValueType max ( ) const
inlinenodiscardconstexprnoexcept

Return the largest vector component.

◆ maxComponent()

template<typename T>
__hostdev__ constexpr Vec2 & maxComponent ( const Vec2< T > & other)
inlineconstexprnoexcept

Take the component-wise maximum of *this and other in place.

◆ mergeMax()

__hostdev__ constexpr VecBase & mergeMax ( const V & other)
inlineconstexprnoexceptinherited

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

◆ mergeMin()

__hostdev__ constexpr VecBase & mergeMin ( const V & other)
inlineconstexprnoexceptinherited

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

◆ min()

template<typename T>
__hostdev__ constexpr ValueType min ( ) const
inlinenodiscardconstexprnoexcept

Return the smallest vector component.

◆ minComponent()

template<typename T>
__hostdev__ constexpr Vec2 & minComponent ( const Vec2< T > & other)
inlineconstexprnoexcept

Take the component-wise minimum of *this and other in place.

◆ minus()

__hostdev__ constexpr Derived minus ( const Derived & rhs) const
inlinenodiscardconstexprnoexceptinherited

Return *this - rhs as a Derived.

◆ mul()

__hostdev__ constexpr Derived mul ( const Derived & rhs) const
inlinenodiscardconstexprnoexceptinherited

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

◆ mulAssign()

__hostdev__ constexpr VecBase & mulAssign ( const VecBase< T, 2 > & rhs)
inlineconstexprnoexceptinherited

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

◆ negate()

__hostdev__ constexpr Derived negate ( ) const
inlinenodiscardconstexprnoexceptinherited

Return -(*this) as a Derived.

◆ normalize()

template<typename T>
__hostdev__ Vec2 & normalize ( )
inlinenoexcept

Normalize in place (divide by length()). Not constexpr — calls std::sqrt.

◆ normalized()

template<typename T>
__hostdev__ Vec2 normalized ( ) const
inlinenodiscardnoexcept

Return a normalized (unit-length) copy; const counterpart of normalize().

◆ operator!=()

template<typename T>
__hostdev__ constexpr bool operator!= ( const Vec2< T > & rhs) const
inlinenodiscardconstexprnoexcept

Component-wise inequality.

◆ operator*() [1/2]

template<typename T>
__hostdev__ constexpr Vec2 operator* ( const T & s) const
inlinenodiscardconstexprnoexcept

Component-wise multiply by scalar s.

◆ operator*() [2/2]

template<typename T>
__hostdev__ constexpr Vec2 operator* ( const Vec2< T > & v) const
inlinenodiscardconstexprnoexcept

Component-wise (Hadamard) product.

◆ operator*=()

template<typename T>
__hostdev__ constexpr Vec2 & operator*= ( const T & s)
inlineconstexprnoexcept

In-place component-wise multiply by scalar s.

◆ operator+() [1/2]

template<typename T>
__hostdev__ constexpr Vec2 operator+ ( const Coord2 & ijk) const
inlinenodiscardconstexprnoexcept

Add an integer Coord2 to this vector (component-wise).

◆ operator+() [2/2]

template<typename T>
__hostdev__ constexpr Vec2 operator+ ( const Vec2< T > & v) const
inlinenodiscardconstexprnoexcept

Component-wise sum.

◆ operator+=() [1/2]

template<typename T>
__hostdev__ constexpr Vec2 & operator+= ( const Coord2 & ijk)
inlineconstexprnoexcept

In-place component-wise addition of an integer Coord2.

◆ operator+=() [2/2]

template<typename T>
__hostdev__ constexpr Vec2 & operator+= ( const Vec2< T > & v)
inlineconstexprnoexcept

In-place component-wise addition.

◆ operator-() [1/3]

template<typename T>
__hostdev__ constexpr Vec2 operator- ( ) const
inlinenodiscardconstexprnoexcept

Component-wise negation.

◆ operator-() [2/3]

template<typename T>
__hostdev__ constexpr Vec2 operator- ( const Coord2 & ijk) const
inlinenodiscardconstexprnoexcept

Subtract an integer Coord2 from this vector (component-wise).

◆ operator-() [3/3]

template<typename T>
__hostdev__ constexpr Vec2 operator- ( const Vec2< T > & v) const
inlinenodiscardconstexprnoexcept

Component-wise difference.

◆ operator-=() [1/2]

template<typename T>
__hostdev__ constexpr Vec2 & operator-= ( const Coord2 & ijk)
inlineconstexprnoexcept

In-place component-wise subtraction of an integer Coord2.

◆ operator-=() [2/2]

template<typename T>
__hostdev__ constexpr Vec2 & operator-= ( const Vec2< T > & v)
inlineconstexprnoexcept

In-place component-wise subtraction.

◆ operator/() [1/2]

template<typename T>
__hostdev__ constexpr Vec2 operator/ ( const T & s) const
inlinenodiscardconstexprnoexcept

Component-wise divide by scalar s (integer-safe).

◆ operator/() [2/2]

template<typename T>
__hostdev__ constexpr Vec2 operator/ ( const Vec2< T > & v) const
inlinenodiscardconstexprnoexcept

Component-wise division.

◆ operator/=()

template<typename T>
__hostdev__ constexpr Vec2 & operator/= ( const T & s)
inlineconstexprnoexcept

In-place component-wise divide by scalar s.

◆ operator=()

template<typename T>
template<template< class > class Vec2T, class T2>
__hostdev__ constexpr Vec2 & operator= ( const Vec2T< T2 > & rhs)
inlineconstexprnoexcept

Assign from any 2-component vector type (foreign or nanovdb).

◆ operator==()

template<typename T>
__hostdev__ constexpr bool operator== ( const Vec2< T > & rhs) const
inlinenodiscardconstexprnoexcept

Component-wise equality.

◆ operator[]() [1/2]

__hostdev__ constexpr const T & operator[] ( int i) const
inlineconstexprnoexceptinherited

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

◆ operator[]() [2/2]

__hostdev__ constexpr T & operator[] ( int i)
inlineconstexprnoexceptinherited

◆ plus()

__hostdev__ constexpr Derived plus ( const Derived & rhs) const
inlinenodiscardconstexprnoexceptinherited

Return *this + rhs as a Derived.

◆ round()

template<typename T>
__hostdev__ constexpr Coord2 round ( ) const
inlinenodiscardconstexprnoexcept

Round each component to its closest integer value.

Returns
integer Coord2
Note
Only constexpr for integer T (roundAs uses non-constexpr math::Round for floating point).

◆ roundAs()

__hostdev__ constexpr Result roundAs ( ) const
inlinenodiscardconstexprnoexceptinherited

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()

__hostdev__ constexpr Derived scale ( T s) const
inlinenodiscardconstexprnoexceptinherited

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

◆ scaleAssign()

__hostdev__ constexpr VecBase & scaleAssign ( T s)
inlineconstexprnoexceptinherited

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()

__hostdev__ constexpr T smallestComponent ( ) const
inlinenodiscardconstexprnoexceptinherited

return the smallest of the N components

◆ subAssign()

__hostdev__ constexpr VecBase & subAssign ( const VecBase< T, 2 > & rhs)
inlineconstexprnoexceptinherited

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

◆ w() [1/2]

__hostdev__ constexpr const T & w ( ) const
inlineconstexprnoexceptinherited

◆ w() [2/2]

__hostdev__ constexpr T & w ( )
inlineconstexprnoexceptinherited

◆ x() [1/2]

__hostdev__ constexpr const T & x ( ) const
inlineconstexprnoexceptinherited

◆ x() [2/2]

__hostdev__ constexpr T & x ( )
inlineconstexprnoexceptinherited

◆ y() [1/2]

__hostdev__ constexpr const T & y ( ) const
inlineconstexprnoexceptinherited

◆ y() [2/2]

__hostdev__ constexpr T & y ( )
inlineconstexprnoexceptinherited

◆ z() [1/2]

__hostdev__ constexpr const T & z ( ) const
inlineconstexprnoexceptinherited

◆ z() [2/2]

__hostdev__ constexpr T & z ( )
inlineconstexprnoexceptinherited

◆ operator*

template<typename T>
template<typename T1>
__hostdev__ friend constexpr Vec2 operator* ( T1 scalar,
const Vec2< T > & vec )
friend

Scalar-on-the-left multiplication (hidden friend).

◆ operator/

template<typename T>
template<typename T1>
__hostdev__ friend constexpr Vec2 operator/ ( T1 scalar,
const Vec2< T > & vec )
friend

Scalar-on-the-left division (hidden friend).

Member Data Documentation

◆ mVec

T mVec[N]
protectedinherited

◆ SIZE

int SIZE
staticconstexprinherited

◆ size

template<typename T>
int size = 2
staticconstexpr