INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
rt::PointVector< T, N > Struct Template Reference

#include <PointVector.h>

Inheritance diagram for rt::PointVector< T, N >:

Public Types

typedef PointVector< T, N > Self
 
typedef std::array< T, N > Base
 
typedef std::size_t Size
 

Public Member Functions

 PointVector (std::initializer_list< T > L)
 
 PointVector (T val0)
 
 PointVector (T val0, T val1)
 
 PointVector (T val0, T val1, T val2)
 
 PointVector (T val0, T val1, T val2, T val3)
 
 PointVector (const T *vals)
 
 operator T* ()
 
 operator const T * () const
 
void selfDisplay (std::ostream &out) const
 
Selfoperator+= (const Self &other)
 
Selfoperator-= (const Self &other)
 
Selfoperator*= (T val)
 
Selfoperator/= (T val)
 
dot (const Self &other) const
 dot product (produit scalaire).
 
Self cross (const Self &other) const
 cross product (produit vectoriel).
 
Self operator+ (const Self &other) const
 
Self operator- (const Self &other) const
 
norm () const
 

Detailed Description

template<typename T, std::size_t N>
struct rt::PointVector< T, N >

Model a static vector T[N], with some operations.

Definition at line 20 of file PointVector.h.

Member Typedef Documentation

◆ Base

template<typename T , std::size_t N>
typedef std::array<T, N> rt::PointVector< T, N >::Base

Definition at line 22 of file PointVector.h.

◆ Self

template<typename T , std::size_t N>
typedef PointVector<T, N> rt::PointVector< T, N >::Self

Definition at line 21 of file PointVector.h.

◆ Size

template<typename T , std::size_t N>
typedef std::size_t rt::PointVector< T, N >::Size

Definition at line 23 of file PointVector.h.

Constructor & Destructor Documentation

◆ PointVector() [1/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( )
inline

Definition at line 35 of file PointVector.h.

35{}

◆ PointVector() [2/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( std::initializer_list< T >  L)
inline

Definition at line 37 of file PointVector.h.

38 {
39 Size i = 0;
40 for ( auto v : L ) if ( i < N ) (*this)[ i++ ] = v;
41 }

◆ PointVector() [3/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( val0)
inline

Definition at line 42 of file PointVector.h.

43 {
44 assert( 0 < N );
45 (*this)[ 0 ] = val0;
46 }

◆ PointVector() [4/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( val0,
val1 
)
inline

Definition at line 47 of file PointVector.h.

48 {
49 assert( 1 < N );
50 (*this)[ 0 ] = val0;
51 (*this)[ 1 ] = val1;
52 }

◆ PointVector() [5/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( val0,
val1,
val2 
)
inline

Definition at line 53 of file PointVector.h.

54 {
55 assert( 2 < N );
56 (*this)[ 0 ] = val0;
57 (*this)[ 1 ] = val1;
58 (*this)[ 2 ] = val2;
59 }

◆ PointVector() [6/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( val0,
val1,
val2,
val3 
)
inline

Definition at line 60 of file PointVector.h.

61 {
62 assert( 3 < N );
63 (*this)[ 0 ] = val0;
64 (*this)[ 1 ] = val1;
65 (*this)[ 2 ] = val2;
66 (*this)[ 3 ] = val3;
67 }

◆ PointVector() [7/7]

template<typename T , std::size_t N>
rt::PointVector< T, N >::PointVector ( const T *  vals)
inline

Definition at line 68 of file PointVector.h.

69 {
70 for ( Size i = 0; i < N; i++ ) (*this)[ i ] = *vals++;
71 }

Member Function Documentation

◆ cross()

template<typename T , std::size_t N>
Self rt::PointVector< T, N >::cross ( const Self other) const
inline

cross product (produit vectoriel).

Definition at line 113 of file PointVector.h.

114 {
115 assert( N == 3 );
116 return Self( (*this)[1]*other[2] - (*this)[2]*other[1],
117 (*this)[2]*other[0] - (*this)[0]*other[2],
118 (*this)[0]*other[1] - (*this)[1]*other[0] );
119 }

◆ dot()

template<typename T , std::size_t N>
T rt::PointVector< T, N >::dot ( const Self other) const
inline

dot product (produit scalaire).

Definition at line 106 of file PointVector.h.

107 {
108 T result = 0;
109 for ( Size i = 0; i < N; ++i ) result += (*this)[ i ] * other[ i ];
110 return result;
111 }

◆ norm()

template<typename T , std::size_t N>
T rt::PointVector< T, N >::norm ( ) const
inline

Definition at line 135 of file PointVector.h.

136 {
137 return sqrt( dot( *this ) );
138 }
T dot(const Self &other) const
dot product (produit scalaire).

◆ operator const T *()

template<typename T , std::size_t N>
rt::PointVector< T, N >::operator const T * ( ) const
inline

Definition at line 75 of file PointVector.h.

75{ return data(); }

◆ operator T*()

template<typename T , std::size_t N>
rt::PointVector< T, N >::operator T* ( )
inline

Definition at line 73 of file PointVector.h.

73{ return data(); }

◆ operator*=()

template<typename T , std::size_t N>
Self & rt::PointVector< T, N >::operator*= ( val)
inline

Definition at line 94 of file PointVector.h.

95 {
96 for ( Size i = 0; i < N; ++i ) (*this)[ i ] *= val;
97 return *this;
98 }

◆ operator+()

template<typename T , std::size_t N>
Self rt::PointVector< T, N >::operator+ ( const Self other) const
inline

Definition at line 121 of file PointVector.h.

122 {
123 Self result( *this );
124 result += other;
125 return result;
126 }

◆ operator+=()

template<typename T , std::size_t N>
Self & rt::PointVector< T, N >::operator+= ( const Self other)
inline

Definition at line 84 of file PointVector.h.

85 {
86 for ( Size i = 0; i < N; ++i ) (*this)[ i ] += other[ i ];
87 return *this;
88 }

◆ operator-()

template<typename T , std::size_t N>
Self rt::PointVector< T, N >::operator- ( const Self other) const
inline

Definition at line 128 of file PointVector.h.

129 {
130 Self result( *this );
131 result -= other;
132 return result;
133 }

◆ operator-=()

template<typename T , std::size_t N>
Self & rt::PointVector< T, N >::operator-= ( const Self other)
inline

Definition at line 89 of file PointVector.h.

90 {
91 for ( Size i = 0; i < N; ++i ) (*this)[ i ] -= other[ i ];
92 return *this;
93 }

◆ operator/=()

template<typename T , std::size_t N>
Self & rt::PointVector< T, N >::operator/= ( val)
inline

Definition at line 99 of file PointVector.h.

100 {
101 for ( Size i = 0; i < N; ++i ) (*this)[ i ] /= val;
102 return *this;
103 }

◆ selfDisplay()

template<typename T , std::size_t N>
void rt::PointVector< T, N >::selfDisplay ( std::ostream &  out) const
inline

Definition at line 77 of file PointVector.h.

78 {
79 out << "(";
80 for ( Size i = 0; i < N; i++ )
81 out << (*this)[ i ] << ( ( i < N-1 ) ? ',' : ')' );
82 }

The documentation for this struct was generated from the following file: