Skip to content

Commit

Permalink
switch par-type uint8_t -> std::size_t for Vector, Matrix and LUDecom…
Browse files Browse the repository at this point in the history
…position
  • Loading branch information
TomSaw committed Nov 16, 2021
1 parent 0bcb728 commit 2f525e4
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 296 deletions.
4 changes: 2 additions & 2 deletions src/modm/math/geometry/quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
namespace modm
{
// forward declaration
template<class T, uint8_t N>
template<class T, std::size_t N>
class Vector;

template<class T, uint8_t ROWS, uint8_t COLUMNS>
template<class T, std::size_t ROWS, std::size_t COLUMNS>
class Matrix;

/**
Expand Down
16 changes: 8 additions & 8 deletions src/modm/math/geometry/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace modm
{
// forward declaration
template<typename T, uint8_t, uint8_t>
template<typename T, std::size_t, std::size_t>
class Matrix;

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace modm
* \ingroup modm_math_geometry
* \author Niklas Hauser
*/
template<typename T, uint8_t N>
template<typename T, std::size_t N>
class Vector
{
public:
Expand All @@ -71,8 +71,8 @@ namespace modm
bool operator > (const Vector &rhs) const;
bool operator >= (const Vector &rhs) const;

const T& operator [] (uint8_t index) const;
T& operator [] (uint8_t index);
const T& operator [] (std::size_t index) const;
T& operator [] (std::size_t index);

T* ptr();
const T* ptr() const;
Expand Down Expand Up @@ -104,21 +104,21 @@ namespace modm
asTransposedMatrix() const;

public:
static inline uint8_t
static inline std::size_t
getSize();

T coords[N];
};

template< typename T, uint8_t N >
template< typename T, std::size_t N >
struct detail::MakeSigned< Vector<T, N> >
{ using type = Vector< SignedType<T>, N >; };

template< typename T, uint8_t N >
template< typename T, std::size_t N >
struct detail::MakeUnsigned< Vector<T, N> >
{ using type = Vector< UnsignedType<T>, N >; };

template< typename T, uint8_t N >
template< typename T, std::size_t N >
struct detail::WideType< Vector<T, N> >
{ using type = Vector< WideType<T>, N >; };
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace modm
bool operator > (const Vector &rhs) const;
bool operator >= (const Vector &rhs) const;

const T& operator [] (uint8_t index) const;
T& operator [] (uint8_t index);
const T& operator [] (std::size_t index) const;
T& operator [] (std::size_t index);
T* ptr();
const T* ptr() const;

Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector1_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ modm::Vector<T, 1>::operator >= (const modm::Vector<T, 1> &rhs) const
// ----------------------------------------------------------------------------
template<typename T>
const T&
modm::Vector<T, 1>::operator [] (uint8_t index) const
modm::Vector<T, 1>::operator [] (std::size_t index) const
{
return reinterpret_cast<const T*>(this)[index];
}

template<typename T>
T&
modm::Vector<T, 1>::operator [] (uint8_t index)
modm::Vector<T, 1>::operator [] (std::size_t index)
{
return reinterpret_cast<T*>(this)[index];
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ namespace modm
bool operator > (const Vector &rhs) const;
bool operator >= (const Vector &rhs) const;

const T& operator [] (uint8_t index) const;
T& operator [] (uint8_t index);
const T& operator [] (std::size_t index) const;
T& operator [] (std::size_t index);

T* ptr();
const T* ptr() const;
Expand Down
22 changes: 6 additions & 16 deletions src/modm/math/geometry/vector2_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,16 @@ modm::Vector<T, 2>::ccw(const Vector& a, const Vector& b,
WideType d1 = dx1 * dy2;
WideType d2 = dy1 * dx2;

if (d1 > d2) {
if (d1 > d2)
return 1;
}
else if (d1 < d2) {
else if (d1 < d2)
return -1;
}
else
{
if ((dx1 * dx2 < 0) || (dy1 * dy2 < 0)) {
if ((dx1 * dx2 < 0) || (dy1 * dy2 < 0))
return -1;
}
else
{
if ((dx1 * dx1 + dy1 * dy1) >= (dx2 * dx2 + dy2 * dy2)) {
return 0;
}
else {
return 1;
}
}
return ((dx1 * dx1 + dy1 * dy1) >= (dx2 * dx2 + dy2 * dy2)) ? 0 : 1;
}
}

Expand Down Expand Up @@ -340,15 +330,15 @@ modm::Vector<T, 2>::operator >= (const modm::Vector<T, 2> &rhs) const
// ----------------------------------------------------------------------------
template<typename T>
const T&
modm::Vector<T, 2>::operator [] (uint8_t index) const
modm::Vector<T, 2>::operator [] (std::size_t index) const
{
return reinterpret_cast<const T*>(this)[index];
}

// ----------------------------------------------------------------------------
template<typename T>
T&
modm::Vector<T, 2>::operator [] (uint8_t index)
modm::Vector<T, 2>::operator [] (std::size_t index)
{
return reinterpret_cast<T*>(this)[index];
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace modm
bool operator > (const Vector &rhs) const;
bool operator >= (const Vector &rhs) const;

const T& operator [] (uint8_t index) const;
T& operator [] (uint8_t index);
const T& operator [] (std::size_t index) const;
T& operator [] (std::size_t index);
T* ptr();
const T* ptr() const;

Expand Down
6 changes: 3 additions & 3 deletions src/modm/math/geometry/vector3_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ template<typename T>
void
modm::Vector<T, 3>::setZ(const T& value)
{
this->z = value;
this->z = value;
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -198,15 +198,15 @@ modm::Vector<T, 3>::operator >= (const Vector &rhs) const
// ----------------------------------------------------------------------------
template<typename T>
const T&
modm::Vector<T, 3>::operator [] (uint8_t index) const
modm::Vector<T, 3>::operator [] (std::size_t index) const
{
return reinterpret_cast<const T*>(this)[index];
}

// ----------------------------------------------------------------------------
template<typename T>
T&
modm::Vector<T, 3>::operator [] (uint8_t index)
modm::Vector<T, 3>::operator [] (std::size_t index)
{
return reinterpret_cast<T*>(this)[index];
}
Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ namespace modm
bool operator > (const Vector &rhs) const;
bool operator >= (const Vector &rhs) const;

const T& operator [] (uint8_t index) const;
T& operator [] (uint8_t index);
const T& operator [] (std::size_t index) const;
T& operator [] (std::size_t index);
T* ptr();
const T* ptr() const;

Expand Down
4 changes: 2 additions & 2 deletions src/modm/math/geometry/vector4_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ modm::Vector<T, 4>::operator >= (const modm::Vector<T, 4> &rhs) const

template<typename T>
const T&
modm::Vector<T, 4>::operator [] (uint8_t index) const
modm::Vector<T, 4>::operator [] (std::size_t index) const
{
return reinterpret_cast<const T*>(this)[index];
}

// ----------------------------------------------------------------------------
template<typename T>
T&
modm::Vector<T, 4>::operator [] (uint8_t index)
modm::Vector<T, 4>::operator [] (std::size_t index)
{
return reinterpret_cast<T*>(this)[index];
}
Expand Down
Loading

0 comments on commit 2f525e4

Please sign in to comment.