2 #if !defined( INCLUDED_VECTOR_H )
3 #define INCLUDED_VECTOR_H
7 template <typename Element>
10 Element m_elements[2];
14 BasicVector2( const Element& x_, const Element& y_ ){
22 const Element& x() const {
28 const Element& y() const {
32 const Element& operator[]( std::size_t i ) const {
35 Element& operator[]( std::size_t i ){
42 const Element* data() const {
47 /// \brief A 3-element vector.
48 template<typename Element>
51 Element m_elements[3];
56 template<typename OtherElement>
57 BasicVector3( const BasicVector3<OtherElement>& other ){
58 x() = static_cast<Element>( other.x() );
59 y() = static_cast<Element>( other.y() );
60 z() = static_cast<Element>( other.z() );
62 BasicVector3( const Element& x_, const Element& y_, const Element& z_ ){
71 const Element& x() const {
77 const Element& y() const {
83 const Element& z() const {
87 const Element& operator[]( std::size_t i ) const {
90 Element& operator[]( std::size_t i ){
97 const Element* data() const {
102 /// \brief A 4-element vector.
103 template<typename Element>
106 Element m_elements[4];
111 BasicVector4( Element x_, Element y_, Element z_, Element w_ ){
117 BasicVector4( const BasicVector3<Element>& self, Element w_ ){
125 return m_elements[0];
127 const Element& x() const {
128 return m_elements[0];
131 return m_elements[1];
133 const Element& y() const {
134 return m_elements[1];
137 return m_elements[2];
139 const Element& z() const {
140 return m_elements[2];
143 return m_elements[3];
145 const Element& w() const {
146 return m_elements[3];
149 Element index( std::size_t i ) const {
150 return m_elements[i];
152 Element& index( std::size_t i ){
153 return m_elements[i];
155 Element operator[]( std::size_t i ) const {
156 return m_elements[i];
158 Element& operator[]( std::size_t i ){
159 return m_elements[i];
165 const Element* data() const {
170 template<typename Element>
171 inline BasicVector3<Element> vector3_from_array( const Element* array ){
172 return BasicVector3<Element>( array[0], array[1], array[2] );
175 template<typename Element>
176 inline Element* vector3_to_array( BasicVector3<Element>& self ){
179 template<typename Element>
180 inline const Element* vector3_to_array( const BasicVector3<Element>& self ){
184 template<typename Element>
185 inline Element* vector4_to_array( BasicVector4<Element>& self ){
188 template<typename Element>
189 inline const Element* vector4_to_array( const BasicVector4<Element>& self ){
193 template<typename Element>
194 inline BasicVector3<Element>& vector4_to_vector3( BasicVector4<Element>& self ){
195 return *reinterpret_cast<BasicVector3<Element>*>( vector4_to_array( self ) );
197 template<typename Element>
198 inline const BasicVector3<Element>& vector4_to_vector3( const BasicVector4<Element>& self ){
199 return *reinterpret_cast<const BasicVector3<Element>*>( vector4_to_array( self ) );
202 /// \brief A 2-element vector stored in single-precision floating-point.
203 typedef BasicVector2<float> Vector2;
205 /// \brief A 3-element vector stored in single-precision floating-point.
206 typedef BasicVector3<float> Vector3;
208 /// \brief A 4-element vector stored in single-precision floating-point.
209 typedef BasicVector4<float> Vector4;