Cleanup dans array2d et array3d

This commit is contained in:
Marc-Eric Martel 2021-10-19 14:29:06 -04:00
parent 3782188571
commit db1109fe6e
2 changed files with 20 additions and 35 deletions

View File

@ -4,8 +4,7 @@
#include "define.h" #include "define.h"
template <class T> template <class T>
class Array2d class Array2d {
{
public: public:
Array2d(int x, int y); Array2d(int x, int y);
~Array2d(); ~Array2d();
@ -16,12 +15,11 @@ public:
void Reset(T type); void Reset(T type);
private:
int To1dIndex(int x, int y) const;
private: private:
int m_x, m_y; int m_x, m_y;
T* m_array; T* m_array;
int To1dIndex(int x, int y) const;
}; };
template <class T> template <class T>
@ -38,14 +36,10 @@ Array2d<T>::Array2d(const Array2d<T>& array) : m_x(array.m_x), m_y(array.m_y) {
} }
template <class T> template <class T>
void Array2d<T>::Set(int x, int y, T type) { void Array2d<T>::Set(int x, int y, T type) { m_array[To1dIndex(x, y)] = type; }
m_array[To1dIndex(x, y)] = type;
}
template <class T> template <class T>
T Array2d<T>::Get(int x, int y) const { T Array2d<T>::Get(int x, int y) const { return m_array[To1dIndex(x, y)]; }
return m_array[To1dIndex(x, y)];
}
template <class T> template <class T>
void Array2d<T>::Reset(T type) { void Array2d<T>::Reset(T type) {
@ -54,8 +48,6 @@ void Array2d<T>::Reset(T type) {
} }
template <class T> template <class T>
int Array2d<T>::To1dIndex(int x, int y) const { int Array2d<T>::To1dIndex(int x, int y) const { return x + (y * m_x); }
return x + (y * m_x);
}
#endif // ARRAY2D_H__ #endif // ARRAY2D_H__

View File

@ -4,8 +4,7 @@
#include "define.h" #include "define.h"
template <class T> template <class T>
class Array3d class Array3d {
{
public: public:
Array3d(int x, int y, int z); Array3d(int x, int y, int z);
~Array3d(); ~Array3d();
@ -16,12 +15,11 @@ class Array3d
void Reset(T type); void Reset(T type);
private:
int To1dIndex(int x, int y, int z) const;
private: private:
int m_x, m_y, m_z; int m_x, m_y, m_z;
T* m_array; T* m_array;
int To1dIndex(int x, int y, int z) const;
}; };
template <class T> template <class T>
@ -43,9 +41,7 @@ void Array3d<T>::Set(int x, int y, int z, T type) {
} }
template <class T> template <class T>
T Array3d<T>::Get(int x, int y, int z) const { T Array3d<T>::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; }
return m_array[To1dIndex(x, y, z)];
}
template <class T> template <class T>
void Array3d<T>::Reset(T type) { void Array3d<T>::Reset(T type) {
@ -54,9 +50,6 @@ void Array3d<T>::Reset(T type) {
} }
template <class T> template <class T>
int Array3d<T>::To1dIndex(int x, int y, int z) const { int Array3d<T>::To1dIndex(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); }
return x + (z * m_x) + (y * m_z * m_x);
}
#endif // ARRAY3D_H__ #endif // ARRAY3D_H__