neuray API Programmer's Manual

vector.h File Reference

Description

Math vector class template of fixed dimension with arithmetic operators and generic functions. See Math Vector Class.

Code Example

vector.h

‎/***************************************************************************************************
 * Copyright 2024 NVIDIA Corporation. All rights reserved.
 **************************************************************************************************/

#ifndef MI_MATH_VECTOR_H
#define MI_MATH_VECTOR_H

#include <mi/base/types.h>
#include <mi/math/assert.h>
#include <mi/math/function.h>

namespace mi {

namespace math {

enum From_iterator_tag {
    FROM_ITERATOR 
};


// Color and Vector can be converted into each other. To avoid cyclic dependencies among the
// headers, the Color_struct class is already defined here.

//------- POD struct that provides storage for color elements --------

struct Color_struct
{
    Float32 
               r;
    Float32 
               g;
    Float32 
               b;
    Float32 
               a;
};


//------- POD struct that provides storage for vector elements --------

template <typename T, Size DIM>
struct Vector_struct
{
    T elements[DIM]; 
};

template <typename T> struct Vector_struct<T, 1>
{
    T x;  
};

template <typename T> struct Vector_struct<T, 2>
{
    T x;  
    T y;  
};

template <typename T> struct Vector_struct<T, 3>
{
    T x;  
    T y;  
    T z;  
};

template <typename T> struct Vector_struct<T, 4>
{
    T x;  
    T y;  
    T z;  
    T w;  
};


//------ Indirect access to vector storage base ptr to keep Vector_struct a POD --

template <typename T, Size DIM>
inline T* vector_base_ptr( Vector_struct< T, DIM>& vec)
{
    return vec.elements;
}

template <typename T, Size DIM>
inline const T* vector_base_ptr( const Vector_struct< T, DIM>& vec)
{
    return vec.elements;
}

template <typename T>
inline T* vector_base_ptr( Vector_struct< T, 1>& vec)
{
    return &vec.x;
}

template <typename T>
inline const T* vector_base_ptr( const Vector_struct< T, 1>& vec)
{
    return &vec.x;
}

template <typename T>
inline T* vector_base_ptr( Vector_struct< T, 2>& vec)
{
    return &vec.x;
}

template <typename T>
inline const T* vector_base_ptr( const Vector_struct< T, 2>& vec)
{
    return &vec.x;
}

template <typename T>
inline T* vector_base_ptr( Vector_struct< T, 3>& vec)
{
    return &vec.x;
}

template <typename T>
inline const T* vector_base_ptr( const Vector_struct< T, 3>& vec)
{
    return &vec.x;
}

template <typename T>
inline T* vector_base_ptr( Vector_struct< T, 4>& vec)
{
    return &vec.x;
}

template <typename T>
inline const T* vector_base_ptr( const Vector_struct< T, 4>& vec)
{
    return &vec.x;
}

 // end group mi_math_vector_struct


//------ Generic Vector Class -------------------------------------------------

template < class T, Size DIM>
class Vector : public Vector_struct<T, DIM> //-V690 PVS
{
public:
    typedef Vector_struct< T, DIM> 
               Pod_type;      
    typedef Vector_struct< T, DIM> 
               storage_type;  

    typedef T           value_type;             
    typedef Size        
               size_type;              
    typedef Difference  
               difference_type;        
    typedef T *         pointer;                
    typedef const T *   const_pointer;          
    typedef T &         reference;              
    typedef const T &   const_reference;        

    static const Size 
               DIMENSION = DIM;          
    static const Size 
               SIZE      = DIM;          

    static inline Size 
               size()     { return SIZE; }

    static inline Size 
               max_size() { return SIZE; }

    inline T* begin() { return mi::math::vector_base_ptr( *this); }

    inline const T* begin() const { return mi::math::vector_base_ptr( *this); }

    inline T* end() { return begin() + DIM; }

    inline const T* end() const { return begin() + DIM; }

    inline Vector()
    {
#ifndef NDEBUG
        // In debug mode, default-constructed vectors are initialized with signaling NaNs or, if not
        // applicable, with a maximum value to increase the chances of diagnosing incorrect use of
        // an uninitialized vector.
        typedef mi::base::numeric_traits< T> Traits;
        T v = (Traits::has_signaling_NaN) ? Traits::signaling_NaN()
                                          : Traits::max MI_PREVENT_MACRO_EXPAND ();
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = v;
#endif
    }

#if (__cplusplus >= 201103L)
    Vector( const Vector<T,DIM>& vec ) = default;
#endif

    inline Vector( const Vector_struct< T, DIM>& vec )
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = mi::math::vector_base_ptr(vec)[i];
    }

    inline explicit Vector(T v)
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = v;
    }

    template <typename Iterator>
    inline Vector(From_iterator_tag, Iterator p)
    {
        for( Size i(0u); i < DIM; ++i, ++p)
            (*this)[i] = *p;
    }

    template <typename T2>
    inline explicit Vector( T2 const (& array)[DIM])
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = array[i];
    }

    template <typename T2>
    inline explicit Vector( const Vector< T2, DIM>& other)
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = T(other[i]);
    }

    template <typename T2>
    inline explicit Vector( const Vector_struct< T2, DIM>& other)
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = T(mi::math::vector_base_ptr(other)[i]);
    }

    inline Vector(T v1, T v2)
    {
        mi_static_assert(DIM == 2);
        begin()[0] = v1;
        begin()[1] = v2;
    }

    inline Vector(T v1, T v2, T v3)
    {
        mi_static_assert(DIM == 3);
        begin()[0] = v1;
        begin()[1] = v2;
        begin()[2] = v3;
    }

    inline Vector(T v1, const Vector< T, 2>& v2)
    {
        mi_static_assert(DIM == 3);
        begin()[0] = v1;
        begin()[1] = v2.x;
        begin()[2] = v2.y;
    }

    inline Vector(const Vector< T, 2>& v1, T v2)
    {
        mi_static_assert(DIM == 3);
        begin()[0] = v1.x;
        begin()[1] = v1.y;
        begin()[2] = v2;
    }

    inline Vector(T v1, T v2, T v3, T v4)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1;
        begin()[1] = v2;
        begin()[2] = v3;
        begin()[3] = v4;
    }

    inline Vector(T v1, T v2, const Vector< T, 2>& v3)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1;
        begin()[1] = v2;
        begin()[2] = v3.x;
        begin()[3] = v3.y;
    }


    inline Vector(T v1, const Vector< T, 2>& v2, T v3)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1;
        begin()[1] = v2.x;
        begin()[2] = v2.y;
        begin()[3] = v3;
    }

    inline Vector(const Vector< T, 2>& v1, T v2, T v3)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1.x;
        begin()[1] = v1.y;
        begin()[2] = v2;
        begin()[3] = v3;
    }

    inline Vector(const Vector< T, 2>& v1, const Vector< T, 2>& v2)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1.x;
        begin()[1] = v1.y;
        begin()[2] = v2.x;
        begin()[3] = v2.y;
    }

    inline Vector(T v1, const Vector< T, 3>& v2)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1;
        begin()[1] = v2.x;
        begin()[2] = v2.y;
        begin()[3] = v2.z;
    }

    inline Vector(const Vector< T, 3>& v1, T v2)
    {
        mi_static_assert(DIM == 4);
        begin()[0] = v1.x;
        begin()[1] = v1.y;
        begin()[2] = v1.z;
        begin()[3] = v2;
    }

    inline explicit Vector( const Color_struct& color)
    {
        mi_static_assert(DIM == 4);
        this->x = color.r;
        this->y = color.g;
        this->z = color.b;
        this->w = color.a;
    }

#if (__cplusplus >= 201103L)
    Vector& operator=( const Vector& other) = default;
#else
    inline Vector& operator=( const Vector& other)
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = other[i];
        return *this;
    }
#endif

    inline Vector& operator=( T s)
    {
        for( Size i(0u); i < DIM; ++i)
            (*this)[i] = s;
        return *this;
    }
    inline Vector& operator=( const Color_struct& color)
    {
        mi_static_assert(DIM == 4);
        this->x = color.r;
        this->y = color.g;
        this->z = color.b;
        this->w = color.a;
        return *this;
    }

    inline T& operator[](Size i)
    {
        mi_math_assert_msg(i < DIM, "precondition");
        return begin()[i];
    }

    inline const T& operator[](Size i) const
    {
        mi_math_assert_msg(i < DIM, "precondition");
        return begin()[i];
    }

    inline const T& get(Size i) const
    {
        mi_math_assert_msg(i < DIM, "precondition");
        return begin()[i];
    }

    inline void set(Size i, T value)
    {
        mi_math_assert_msg(i < DIM, "precondition");
        begin()[i] = value;
    }



    inline bool normalize()
    {
        const T rec_length = T(1) / length( *this);
        const bool result = isfinite( rec_length); //-V601 PVS
        if( result)
            (*this) *= rec_length;
        return result;
    }


    //------ Free comparison operators ==, !=, <, <=, >, >= for vectors --------

    inline bool operator==( Vector< T, DIM> rhs) const
    {
        return is_equal( *this, rhs);
    }

    inline bool operator!=( Vector< T, DIM> rhs) const
    {
        return is_not_equal( *this, rhs);
    }

    inline bool operator<( Vector<T,DIM> rhs) const
    {
        return lexicographically_less( *this, rhs);
    }

    inline bool operator<=( Vector<T,DIM> rhs) const
    {
        return lexicographically_less_or_equal( *this, rhs);
    }

    inline bool operator>( Vector< T, DIM> rhs) const
    {
        return lexicographically_greater( *this, rhs);
    }

    inline bool operator>=( Vector< T, DIM> rhs) const
    {
        return lexicographically_greater_or_equal( *this, rhs);
    }
};


//------ Free operators +=, -=, *=, /=, +, -, *, and / for vectors -------------

template <typename T, Size DIM>
inline Vector< T, DIM>& operator+=(
    Vector< T, DIM>&       lhs,
    const Vector_struct< T, DIM>& rhs)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(lhs)[i] += vector_base_ptr(rhs)[i];
    return lhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator-=(
    Vector< T, DIM>&       lhs,
    const Vector_struct< T, DIM>& rhs)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(lhs)[i] -= vector_base_ptr(rhs)[i];
    return lhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator*=(
    Vector< T, DIM>&       lhs,
    const Vector_struct< T, DIM>& rhs)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(lhs)[i] *= vector_base_ptr(rhs)[i];
    return lhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator%=(
    Vector< T, DIM>&       lhs,
    const Vector_struct< T, DIM>& rhs)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(lhs)[i] %= vector_base_ptr(rhs)[i];
    return lhs;
}

template <typename T, typename U, Size DIM>
inline Vector< T, DIM>& operator/=(
    Vector< T, DIM>&       lhs,
    const Vector_struct< U, DIM>& rhs)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(lhs)[i] = T(vector_base_ptr(lhs)[i] / vector_base_ptr(rhs)[i]);
    return lhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator+(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> tmp( lhs);
    return tmp += rhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator-(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> tmp( lhs);
    return tmp -= rhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator*(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> tmp( lhs);
    return tmp *= rhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator%(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> tmp( lhs);
    return tmp %= rhs;
}

template <typename T, typename U, Size DIM>
inline Vector< T, DIM> 
               operator/(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< U, DIM>& rhs)
{
    Vector< T, DIM> tmp(lhs);
    return tmp /= rhs;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator-( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> tmp;
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(tmp)[i] = -vector_base_ptr(v)[i];
    return tmp;
}


//------ Resolve ambiguity with hybrid operators -------------
// (Those operators should really be restricted to scalar types but that requires
// modern C++ which some users of this headers don't enable.)

template <typename T, Size DIM>
inline Vector< T, DIM>& operator+=(
    Vector< T, DIM>&       lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs += static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator-=(
    Vector< T, DIM>&       lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs -= static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator*=(
    Vector< T, DIM>&       lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs *= static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator%=(
    Vector< T, DIM>&       lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs %= static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, typename U, Size DIM>
inline Vector< T, DIM>& operator/=(
    Vector< T, DIM>&       lhs,
    const Vector< U, DIM>& rhs)
{
    return lhs /= static_cast<const Vector_struct< U, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator+(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs + static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator-(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs - static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator*(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs * static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator%(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    return lhs % static_cast<const Vector_struct< T, DIM>&>(rhs);
}

template <typename T, typename U, Size DIM>
inline Vector< T, DIM> 
               operator/(
    const Vector< T, DIM>& lhs,
    const Vector< U, DIM>& rhs)
{
    return lhs / static_cast<const Vector_struct< U, DIM>&>(rhs);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               operator-( const Vector< T, DIM>& v)
{
    return -static_cast<const Vector_struct< T, DIM>&>(v);
}


//------ Free operator *=, /=, *, and / definitions for scalars ---------------

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM>& operator*=(
    Vector< T, DIM>& v,
    TT             s)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(v)[i] = T(vector_base_ptr(v)[i] * s);
    return v;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM>& operator%=(
    Vector< T, DIM>& v,
    TT             s)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(v)[i] = T(vector_base_ptr(v)[i] % s);
    return v;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM>& operator/=(
    Vector< T, DIM>&  v,
    TT              s)
{
    for( Size i(0u); i < DIM; ++i)
        vector_base_ptr(v)[i] = T(vector_base_ptr(v)[i] / s);
    return v;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM> 
               operator*(
    const Vector_struct< T, DIM>& v,
    TT                   s)
{
    Vector< T, DIM> tmp( v);
    return tmp *= s;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM> 
               operator*(
    TT                   s,
    const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> tmp(v);
    return tmp *= s;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM> 
               operator%(
    const Vector_struct< T, DIM>& v,
    TT                   s)
{
    Vector< T, DIM> tmp(v);
    return tmp %= s;
}

template <typename T, typename TT, Size DIM>
inline Vector< T, DIM> 
               operator/(
    const Vector_struct< T, DIM>& v,
    TT                   s)
{
    Vector< T, DIM> tmp( v);
    return tmp /= s;
}


//------ Free operator ++, -- for vectors -------------------------------------

template <typename T, Size DIM>
inline Vector< T, DIM>& operator++( Vector< T, DIM>& vec)
{
    general::for_each( vec, functor::Operator_pre_incr());
    return vec;
}

template <typename T, Size DIM>
inline Vector< T, DIM>& operator--( Vector< T, DIM>& vec)
{
    general::for_each( vec, functor::Operator_pre_decr());
    return vec;
}


//------ Free operators !, &&, ||, ^ for bool vectors and bool scalars ---------

template <Size DIM>
inline Vector< bool, DIM> 
               operator&&(
    const Vector< bool, DIM>& lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result, functor::Operator_and_and());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator&&(
    bool                    lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform_left_scalar( lhs, rhs, result, functor::Operator_and_and());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator&&(
    const Vector< bool, DIM>& lhs,
    bool                    rhs)
{
    Vector< bool, DIM> result;
    general::transform_right_scalar( lhs, rhs, result, functor::Operator_and_and());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator||(
    const Vector< bool, DIM>& lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform(lhs, rhs, result, functor::Operator_or_or());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator||(
    bool                    lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform_left_scalar( lhs, rhs, result, functor::Operator_or_or());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator||(
    const Vector< bool, DIM>& lhs,
    bool                     rhs)
{
    Vector< bool, DIM> result;
    general::transform_right_scalar( lhs, rhs, result, functor::Operator_or_or());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator^(
    const Vector< bool, DIM>& lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result, functor::Operator_xor());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator^(
    bool                    lhs,
    const Vector< bool, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform_left_scalar( lhs, rhs, result, functor::Operator_xor());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator^(
    const Vector< bool, DIM>& lhs,
    bool                    rhs)
{
    Vector< bool, DIM> result;
    general::transform_right_scalar( lhs, rhs, result, functor::Operator_xor());
    return result;
}

template <Size DIM>
inline Vector< bool, DIM> 
               operator!(
    const Vector< bool, DIM>& vec)
{
    Vector< bool, DIM> result;
    general::transform( vec, result, functor::Operator_not());
    return result;
}


//------ Elementwise comparison operators returning a bool vector. ------------

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_equal(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_equal_equal());
    return result;
}

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_not_equal(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_not_equal());
    return result;
}

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_less_than(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_less());
    return result;
}

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_less_than_or_equal(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_less_equal());
    return result;
}

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_greater_than(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_greater());
    return result;
}

template <typename T, Size DIM>
inline Vector< bool, DIM> 
               elementwise_is_greater_than_or_equal(
    const Vector< T, DIM>& lhs,
    const Vector< T, DIM>& rhs)
{
    Vector< bool, DIM> result;
    general::transform( lhs, rhs, result,functor::Operator_greater_equal());
    return result;
}


//------ Function Overloads for Vector Algorithms -----------------------------

template <typename T, Size DIM>
inline Vector< T, DIM> 
               abs( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = abs( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               acos( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = acos( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline bool all( const Vector_struct< T, DIM>& v)
{
    for( Size i = 0; i != DIM; ++i)
        if( !all(vector_base_ptr(v)[i]))
            return false;
    return true;
}

template <typename T, Size DIM>
inline bool any( const Vector_struct< T, DIM>& v)
{
    for( Size i = 0; i != DIM; ++i)
        if( any(vector_base_ptr(v)[i]))
           return true;
    return false;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               asin( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = asin( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               atan( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = atan( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               atan2( const Vector_struct< T, DIM>& v,  const Vector_struct< T, DIM>& w)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = atan2( vector_base_ptr(v)[i], vector_base_ptr(w)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               ceil( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = ceil( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               clamp(
    const Vector_struct< T, DIM>&  v,
    const Vector_struct< T, DIM>&  low,
    const Vector_struct< T, DIM>&  high)
{
    Vector< T, DIM> result;
    for( Size i = 0u; i < DIM; ++i)
        result[i] = clamp(
            vector_base_ptr(v)[i], vector_base_ptr(low)[i], vector_base_ptr(high)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               clamp(
    const Vector_struct< T, DIM>& v,
    const Vector_struct< T, DIM>& low,
    T                    high)
{
    Vector< T, DIM> result;
    for( Size i = 0u; i < DIM; ++i)
        result[i] = clamp( vector_base_ptr(v)[i], vector_base_ptr(low)[i], high);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               clamp(
    const Vector_struct< T, DIM>& v,
    T                    low,
    const Vector_struct< T, DIM>& high)
{
    Vector< T, DIM> result;
    for( Size i = 0u; i < DIM; ++i)
        result[i] = clamp( vector_base_ptr(v)[i], low, vector_base_ptr(high)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               clamp(
    const Vector_struct< T, DIM>& v,
    T                    low,
    T                    high)
{
    Vector< T, DIM> result;
    for( Size i = 0u; i < DIM; ++i)
        result[i] = clamp( vector_base_ptr(v)[i], low, high);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               cos( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = cos( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               degrees( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = degrees( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               elementwise_max(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> r;
    for( Size i(0u); i < Vector<T,DIM>::DIMENSION; ++i)
        vector_base_ptr(r)[i] = base::max MI_PREVENT_MACRO_EXPAND (
            vector_base_ptr(lhs)[i], vector_base_ptr(rhs)[i] );
    return r;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               elementwise_min(
    const Vector_struct< T, DIM>& lhs,
    const Vector_struct< T, DIM>& rhs)
{
    Vector< T, DIM> r;
    for( Size i(0u); i < Vector<T,DIM>::DIMENSION; ++i)
        vector_base_ptr(r)[i] = base::min MI_PREVENT_MACRO_EXPAND (
            vector_base_ptr(lhs)[i], vector_base_ptr(rhs)[i] );
    return r;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               exp( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = exp( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               exp2( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = exp2( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               floor( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = floor( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               fmod( const Vector_struct< T, DIM>& a, const Vector_struct< T, DIM>& b)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = fmod( vector_base_ptr(a)[i], vector_base_ptr(b)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               fmod( const Vector_struct< T, DIM>& a, T b)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = fmod( vector_base_ptr(a)[i], b);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               frac( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = frac( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline bool is_approx_equal(
    const Vector_struct< T, DIM>& left,
    const Vector_struct< T, DIM>& right,
    T                    e)
{
    for( Size i = 0u; i < DIM; ++i)
        if( !is_approx_equal( vector_base_ptr(left)[i], vector_base_ptr(right)[i], e))
            return false;
    return true;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               lerp(
    const Vector_struct< T, DIM>& v1,  
    const Vector_struct< T, DIM>& v2,  
    const Vector_struct< T, DIM>& t)   
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = vector_base_ptr(v1)[i] * (T(1)-vector_base_ptr(t)[i])
                  + vector_base_ptr(v2)[i] * vector_base_ptr(t)[i];
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               lerp(
    const Vector_struct< T, DIM>& v1,  
    const Vector_struct< T, DIM>& v2,  
    T          t)             
{
    // equivalent to: return v1 * (T(1)-t) + v2 * t;
    Vector< T, DIM> result;
    T t2 = T(1) - t;
    for( Size i = 0; i != DIM; ++i)
        result[i] = vector_base_ptr(v1)[i] * t2 + vector_base_ptr(v2)[i] * t;
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               log( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = log( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               log2 
               MI_PREVENT_MACRO_EXPAND ( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = log2 
               MI_PREVENT_MACRO_EXPAND ( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               log10( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = log10( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               modf( const Vector_struct< T, DIM>& v, Vector< T, DIM>& i)
{
    Vector< T, DIM> result;
    for( Size j = 0; j != DIM; ++j)
        result[j] = modf( vector_base_ptr(v)[j], vector_base_ptr(i)[j]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               pow( const Vector_struct< T, DIM>& a, const Vector_struct< T, DIM>& b)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = pow( vector_base_ptr(a)[i], vector_base_ptr(b)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               pow( const Vector_struct< T, DIM>& a, T b)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = pow( vector_base_ptr(a)[i], b);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               radians( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = radians( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               round( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = round( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               rsqrt( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = rsqrt( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               saturate( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = saturate( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               sign( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = sign( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               sin( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = sin( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline void sincos( const Vector_struct< T, DIM>& a, Vector< T, DIM>& s, Vector< T, DIM>& c)
{
    for( Size i = 0; i != DIM; ++i)
        sincos( vector_base_ptr(a)[i], vector_base_ptr(s)[i], vector_base_ptr(c)[i]);
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               smoothstep(
    const Vector_struct< T, DIM>& a,
    const Vector_struct< T, DIM>& b,
    const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = smoothstep(
            vector_base_ptr(a)[i], vector_base_ptr(b)[i], vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               smoothstep(
    const Vector_struct< T, DIM>& a,
    const Vector_struct< T, DIM>& b,
    T x)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = smoothstep( vector_base_ptr(a)[i], vector_base_ptr(b)[i], x);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               sqrt( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = sqrt( vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               step( const Vector_struct< T, DIM>& a, const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = step( vector_base_ptr(a)[i], vector_base_ptr(v)[i]);
    return result;
}

template <typename T, Size DIM>
inline Vector< T, DIM> 
               tan( const Vector_struct< T, DIM>& v)
{
    Vector< T, DIM> result;
    for( Size i = 0; i != DIM; ++i)
        result[i] = tan( vector_base_ptr(v)[i]);
    return result;
}


//------ Geometric Vector Algorithms ------------------------------------------

template <typename T>
inline T cross(
    const Vector_struct< T, 2>& lhs,
    const Vector_struct< T, 2>& rhs)
{
    return lhs.x * rhs.y - lhs.y * rhs.x;
}

template <typename T>
inline Vector< T, 3> 
               cross(
    const Vector_struct< T, 3>& lhs,
    const Vector_struct< T, 3>& rhs)
{
    return Vector< T, 3>( lhs.y * rhs.z - lhs.z * rhs.y,
                        lhs.z * rhs.x - lhs.x * rhs.z,
                        lhs.x * rhs.y - lhs.y * rhs.x);
}

template <typename T>
inline void make_basis(
    const Vector< T, 3>& n,  
    Vector< T, 3>*       u,  
    Vector< T, 3>*       v)  
{
#ifdef mi_base_assert_enabled
    const T eps    = 1e-6f;       // smallest resolvable factor
#endif

    mi_math_assert_msg( u != 0, "precondition");
    mi_math_assert_msg( v != 0, "precondition");
    // Sanity check: the normal vector must be unit length.
    mi_math_assert_msg( abs( length(n) - 1.0f) < eps, "precondition");

    // Compute u.
    if( abs(n.x) < abs(n.y)) {
        // u = cross(x, n), x = (1, 0, 0)
        u->x = T(0);
        u->y = -n.z;
        u->z =  n.y;
    } else {
        // u = cross(y, n), y = (0, 1, 0)
        u->x =  n.z;
        u->y = T(0);
        u->z = -n.x;
    }
    u->normalize();

    // Compute v. Since *u and n are orthogonal and unit-length,
    // there is no need to normalize *v.
    *v = cross( *u, n);

    // Sanity check: make sure (u, n, v) is an orthogonal basis.
    mi_math_assert_msg( abs( dot( *u,  n)) < eps, "postcondition");
    mi_math_assert_msg( abs( dot( *u, *v)) < eps, "postcondition");
    mi_math_assert_msg( abs( dot(  n, *v)) < eps, "postcondition");
    // Sanity check: make sure u and v are unit length.
    mi_math_assert_msg( abs( length( *u) - T(1)) < eps, "postcondition");
    mi_math_assert_msg( abs( length( *v) - T(1)) < eps, "postcondition");
}

template <typename T>
inline void make_basis(
    const Vector< T, 3>& n,     
    const Vector< T, 3>& u,     
    const Vector< T, 3>& v,     
    Vector< T, 3>*       t,     
    Vector< T, 3>*       b)     
{
    const T eps    = 1e-6f;       // smallest resolvable factor
    (void)eps;

    mi_math_assert_msg( t != 0, "precondition");
    mi_math_assert_msg( b != 0, "precondition");
    // Sanity check: the normal vector must be unit length.
    mi_math_assert_msg( abs( length( n) - 1.0f) < eps, "precondition");
    // Sanity check: the other vector lengths should be finite and non-zero
    mi_math_assert_msg( length( u) > 0., "precondition");
    mi_math_assert_msg( length( v) > 0., "precondition");
    mi_math_assert_msg( isfinite( length( u)), "precondition");
    mi_math_assert_msg( isfinite( length( v)), "precondition");

    // Compute b
    *b = cross(u,n);
    b->normalize();

    // Compute t. Since *b and n are orthogonal and unit-length,
    // there is no need to normalize *t.
    *t = cross(n,*b);

    // Check that b has the same orientation of v
    if( dot( *b,v) < T(0))
        *b = -*b;

    // Sanity check: make sure *u and t have the same orientation.
    mi_math_assert_msg( dot( u, *t) > T(0), "postcondition");
    // Sanity check: make sure (t, n, b) is an orthogonal basis.
    // We use a scaled epsilon in order to avoid false positives.
    mi_math_assert_msg( abs( dot( *t,  n)) < 20*eps, "postcondition");
    mi_math_assert_msg( abs( dot( *t, *b)) < 20*eps, "postcondition");
    mi_math_assert_msg( abs( dot(  n, *b)) < 20*eps, "postcondition");
    // Sanity check: make sure t and b are unit length.
    mi_math_assert_msg( abs( length( *t) - T(1)) < eps, "postcondition");
    mi_math_assert_msg( abs( length( *b) - T(1)) < eps, "postcondition");
}

template <typename T2, Size DIM2, typename T1, Size DIM1>
inline Vector< T2,  DIM2> 
               convert_vector(
    const Vector< T1,  DIM1>& v,
    const T2& fill = T2(0))
{
    const Size dim_min = base::min MI_PREVENT_MACRO_EXPAND ( DIM1, DIM2 );
    Vector< T2,  DIM2> result;
    for( Size i = 0; i < dim_min; ++i)
        result[i] = T2(v[i]);
    for( Size i = dim_min; i < DIM2; ++i)
        result[i] = fill;
    return result;
}
 // end group mi_math_vector

} // namespace math

} // namespace mi

#endif // MI_MATH_VECTOR_H

Namespaces

namespace 
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
namespace 
Namespace for the Math API. More...

Classes

struct 
Generic storage class template for an RGBA color representation storing four floating points elements. More...
class 
Fixed-size math vector class template with generic operations. More...
struct 
Specialization for dimension 1 to create x member. More...
struct 
Specialization for dimension 2 to create x and y member. More...
struct 
Specialization for dimension 3 to create x, y, and z members. More...
struct 
Specialization for dimension 4 to create x, y, z, and w members. More...
struct 
Generic storage class template for math vector representations storing DIM elements of type T. More...

Enumerations

enum  {FROM_ITERATOR }
Enum used for initializing a vector from an iterator. More...

Functions

template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise absolute values of the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise arc cosine of the vector v. More...
template< typename T, Size>bool   ( const Vector_struct < T , DIM >& v)
Returns true if all of all elements of v returns true. More...
template< typename T, Size>bool   ( const Vector_struct < T , DIM >& v)
Returns true if any of any element of v returns true. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise arc sine of the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise arc tangent of the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, const Vector_struct < T , DIM >& w)
Returns a vector with the elementwise arc tangent of the vector v / w. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise smallest integral value that is not less than the element in vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, const Vector_struct < T , DIM >& low, const Vector_struct < T , DIM >& high)
Returns the vector v elementwise clamped to the range [low, high]. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, const Vector_struct < T , DIM >& low, T high)
Returns the vector v elementwise clamped to the range [low, high]. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, T low, const Vector_struct < T , DIM >& high)
Returns the vector v elementwise clamped to the range [low, high]. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, T low, T high)
Returns the vector v elementwise clamped to the range [low, high]. More...
template< typename T2, Size, typename T1, Size> Vector < T2 , DIM2 >  ( const Vector < T1 , DIM1 >& v, const T2& fill = T2(0))
Converts the vector v of type Vector<T1, DIM1> to a vector of type Vector<T2, DIM2>. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise cosine of the vector v. More...
template< typename T> ( const Vector_struct < T , 2 >& lhs, const Vector_struct < T , 2 >& rhs)
Returns the two-times-two determinant result for the two vectors lhs and rhs. More...
template< typename T> Vector < T , 3 >  ( const Vector_struct < T , 3 >& lhs, const Vector_struct < T , 3 >& rhs)
Returns the three-dimensional cross product result for the two vectors lhs and rhs. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Converts elementwise radians in v to degrees. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise equality comparison. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise greater-than comparison. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise greater-than-or-equal comparison. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise less-than comparison. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise less-than-or-equal comparison. More...
template< typename T, Size> Vector < bool , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Returns the boolean vector result of an elementwise inequality comparison. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Returns elementwise maximum of two vectors. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Returns elementwise minimum of two vectors. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with elementwise e to the power of the element in the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with elementwise 2 to the power of the element in the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise largest integral value that is not greater than the element in vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, const Vector_struct < T , DIM >& b)
Returns elementwise a modulo b, in other words, the remainder of a/b. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, T b)
Returns elementwise a modulo b, in other words, the remainder of a/b. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise positive fractional part of the vector v. More...
template< typename T, Size>bool   ( const Vector_struct < T , DIM >& left, const Vector_struct < T , DIM >& right, T e)
Compares the two given values elementwise for equality within the given epsilon. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v1, const Vector_struct < T , DIM >& v2, const Vector_struct < T , DIM >& t)
Returns the elementwise linear interpolation between v1 and v2, i.e., it returns (1-t) * v1 + t * v2. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v1, const Vector_struct < T , DIM >& v2, T t)
Returns the linear interpolation between v1 and v2, i.e., it returns (1-t) * v1 + t * v2. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise natural logarithm of the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise base 10 logarithm of the vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise base 2 logarithm of the vector v. More...
template< typename T>void  ( const Vector < T , 3 >& n, Vector < T , 3 >* u, Vector < T , 3 >* v)
Computes a basis of 3D space with one given vector. More...
template< typename T>void  ( const Vector < T , 3 >& n, const Vector < T , 3 >& u, const Vector < T , 3 >& v, Vector < T , 3 >* t, Vector < T , 3 >* b)
Computes a basis of 3D space with one given vector, plane, and direction. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, Vector < T , DIM >& i)
Returns the elementwise fractional part of v and stores the elementwise integral part of v in i. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& vec)
Returns the elementwise logical not of a boolean vector. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Computes lhs modulo rhs elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Computes lhs modulo rhs elementwise and returns the new result. More...
template< typename T, typename TT, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, TT s)
Computes v modulo s elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Computes lhs modulo rhs elementwise and returns the modified lhs. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Computes lhs modulo rhs elementwise and returns the modified lhs. More...
template< typename T, typename TT, Size> Vector < T , DIM >&  ( Vector < T , DIM >& v, TT s)
Computes v modulo s elementwise and returns the modified vector v. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical and of two boolean vectors. More...
template< Size> Vector < bool , DIM >  ( bool lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical and of a bool and a boolean vector. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, bool rhs)
Returns the elementwise logical and of a boolean vector and a bool. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Multiplies rhs elementwise with lhs and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Multiplies rhs elementwise with lhs and returns the new result. More...
template< typename T, typename TT, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, TT s)
Multiplies the vector v elementwise with the scalar s and returns the new result. More...
template< typename T, typename TT, Size> Vector < T , DIM >  ( TT s, const Vector_struct < T , DIM >& v)
Multiplies the vector v elementwise with the scalar s and returns the new result. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Multiplies rhs elementwise with lhs and returns the modified lhs. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Multiplies rhs elementwise with lhs and returns the modified lhs. More...
template< typename T, typename TT, Size> Vector < T , DIM >&  ( Vector < T , DIM >& v, TT s)
Multiplies the vector v elementwise with the scalar s and returns the modified vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Adds lhs and rhs elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Adds lhs and rhs elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& vec)
Pre-increments all elements of vec and returns the result. Modifies vec. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Adds rhs elementwise to lhs and returns the modified lhs. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Adds rhs elementwise to lhs and returns the modified lhs. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Subtracts rhs elementwise from lhs and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Negates the vector v elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Subtracts rhs elementwise from lhs and returns the new result. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector < T , DIM >& v)
Negates the vector v elementwise and returns the new result. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& vec)
Pre-decrements all elements of vec and returns the result. Modifies vec. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector_struct < T , DIM >& rhs)
Subtracts rhs elementwise from lhs and returns the modified lhs. More...
template< typename T, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector < T , DIM >& rhs)
Subtracts rhs elementwise from lhs and returns the modified lhs. More...
template< typename T, typename U, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& lhs, const Vector_struct < U , DIM >& rhs)
Divides rhs elementwise by lhs and returns the new result. More...
template< typename T, typename U, Size> Vector < T , DIM >  ( const Vector < T , DIM >& lhs, const Vector < U , DIM >& rhs)
Divides rhs elementwise by lhs and returns the new result. More...
template< typename T, typename TT, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v, TT s)
Divides the vector v elementwise by the scalar s and returns the new result. More...
template< typename T, typename U, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector_struct < U , DIM >& rhs)
Divides lhs elementwise by rhs and returns the modified lhs. More...
template< typename T, typename U, Size> Vector < T , DIM >&  ( Vector < T , DIM >& lhs, const Vector < U , DIM >& rhs)
Divides lhs elementwise by rhs and returns the modified lhs. More...
template< typename T, typename TT, Size> Vector < T , DIM >&  ( Vector < T , DIM >& v, TT s)
Divides the vector v elementwise by the scalar s and returns the modified vector v. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical xor of two boolean vectors. More...
template< Size> Vector < bool , DIM >  ( bool lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical xor of a bool and a boolean vector. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, bool rhs)
Returns the elementwise logical xor of a boolean vector and a bool. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical or of two boolean vectors. More...
template< Size> Vector < bool , DIM >  ( bool lhs, const Vector < bool , DIM >& rhs)
Returns the elementwise logical or of a bool and a boolean vector. More...
template< Size> Vector < bool , DIM >  ( const Vector < bool , DIM >& lhs, bool rhs)
Returns the elementwise logical or of a boolean vector and a bool. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, const Vector_struct < T , DIM >& b)
Returns the vector a elementwise to the power of b. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, T b)
Returns the vector a elementwise to the power of b. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Converts elementwise degrees in v to radians. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elements of vector v rounded to nearest integers. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns the reciprocal of the square root of each element of v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns the vector v clamped elementwise to the range [0,1]. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns the elementwise sign of vector v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise sine of the vector v. More...
template< typename T, Size>void  ( const Vector_struct < T , DIM >& a, Vector < T , DIM >& s, Vector < T , DIM >& c)
Computes elementwise the sine s and cosine c of angles a simultaneously. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, const Vector_struct < T , DIM >& b, const Vector_struct < T , DIM >& v)
Returns 0 if v is less than a and 1 if v is greater than b in an elementwise fashion. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, const Vector_struct < T , DIM >& b, T x)
Returns 0 if x is less than a and 1 if x is greater than b in an elementwise fashion. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns the square root of each element of v. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& a, const Vector_struct < T , DIM >& v)
Returns elementwise 0 if v is less than a and 1 otherwise. More...
template< typename T, Size> Vector < T , DIM >  ( const Vector_struct < T , DIM >& v)
Returns a vector with the elementwise tangent of the vector v. More...
template< typename T, Size>T*  ( Vector_struct < T , DIM >& vec)
Returns the base pointer to the vector data. More...
template< typename T, Size>const T*  ( const Vector_struct < T , DIM >& vec)
Returns the base pointer to the vector data. More...
template< typename T>T*  ( Vector_struct < T , 1 >& vec)
Returns the base pointer to the vector data, specialization for DIM==1. More...
template< typename T>const T*  ( const Vector_struct < T , 1 >& vec)
Returns the base pointer to the vector data, specialization for DIM==1. More...
template< typename T>T*  ( Vector_struct < T , 2 >& vec)
Returns the base pointer to the vector data, specialization for DIM==2. More...
template< typename T>const T*  ( const Vector_struct < T , 2 >& vec)
Returns the base pointer to the vector data, specialization for DIM==2. More...
template< typename T>T*  ( Vector_struct < T , 3 >& vec)
Returns the base pointer to the vector data, specialization for DIM==3. More...
template< typename T>const T*  ( const Vector_struct < T , 3 >& vec)
Returns the base pointer to the vector data, specialization for DIM==3. More...
template< typename T>T*  ( Vector_struct < T , 4 >& vec)
Returns the base pointer to the vector data, specialization for DIM==4. More...
template< typename T>const T*  ( const Vector_struct < T , 4 >& vec)
Returns the base pointer to the vector data, specialization for DIM==4. More...