Math/Vector[I]: Replace implicit pointer conversion by [] operator overload
This commit is contained in:
parent
3b440254da
commit
b1b9030359
|
|
@ -63,8 +63,8 @@ namespace Nz
|
|||
|
||||
String ToString() const;
|
||||
|
||||
operator T* ();
|
||||
operator const T* () const;
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
const Vector2& operator+() const;
|
||||
Vector2 operator-() const;
|
||||
|
|
|
|||
|
|
@ -450,29 +450,25 @@ namespace Nz
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to pointer to its own data
|
||||
* \return A pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 1 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y depending on index (0, 1)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>::operator T* ()
|
||||
T& Vector2<T>::operator[](std::size_t i)
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 2, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to const pointer to its own data
|
||||
* \return A constant pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 1 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y depending on index (0, 1)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>::operator const T* () const
|
||||
T Vector2<T>::operator[](std::size_t i) const
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 2, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ namespace Nz
|
|||
|
||||
String ToString() const;
|
||||
|
||||
operator T* ();
|
||||
operator const T* () const;
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
const Vector3& operator+() const;
|
||||
Vector3 operator-() const;
|
||||
|
|
|
|||
|
|
@ -583,27 +583,25 @@ namespace Nz
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to pointer to its own data
|
||||
* \return A pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 2 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y, Z depending on index (0, 1, 2)
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>::operator T* ()
|
||||
T& Vector3<T>::operator[](std::size_t i)
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 3, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to const pointer to its own data
|
||||
* \return A constant pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 2 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y, Z depending on index (0, 1, 2)
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>::operator const T* () const
|
||||
T Vector3<T>::operator[](std::size_t i) const
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 3, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ namespace Nz
|
|||
|
||||
String ToString() const;
|
||||
|
||||
operator T* ();
|
||||
operator const T* () const;
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
const Vector4& operator+() const;
|
||||
Vector4 operator-() const;
|
||||
|
|
|
|||
|
|
@ -494,29 +494,25 @@ namespace Nz
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to pointer to its own data
|
||||
* \return A pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 3 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y, Z depending on index (0, 1, 2)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>::operator T* ()
|
||||
T& Vector4<T>::operator[](std::size_t i)
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 4, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts vector to const pointer to its own data
|
||||
* \return A constant pointer to the own data
|
||||
*
|
||||
* \remark Access to index greather than 3 is undefined behavior
|
||||
* \brief Access a vector component by index
|
||||
* \return X, Y, Z depending on index (0, 1, 2)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>::operator const T* () const
|
||||
T Vector4<T>::operator[](std::size_t i) const
|
||||
{
|
||||
return &x;
|
||||
NazaraAssert(i < 4, "index out of range");
|
||||
return *(&x + i);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -166,8 +166,8 @@ namespace Nz
|
|||
|
||||
std::vector<MD2_Vertex> vertices(header.num_vertices);
|
||||
Vector3f scale, translate;
|
||||
stream.Read(scale, sizeof(Vector3f));
|
||||
stream.Read(translate, sizeof(Vector3f));
|
||||
stream.Read(&scale, sizeof(Vector3f));
|
||||
stream.Read(&translate, sizeof(Vector3f));
|
||||
stream.Read(nullptr, 16*sizeof(char)); //< Frame name, unused
|
||||
stream.Read(vertices.data(), header.num_vertices*sizeof(MD2_Vertex));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue