Просмотр исходного кода

Add toString methods in the math classes

Panagiotis Christopoulos Charitos 5 лет назад
Родитель
Сommit
aedafde27c
6 измененных файлов с 89 добавлено и 0 удалено
  1. 9 0
      src/anki/math/Axisang.h
  2. 1 0
      src/anki/math/Common.h
  3. 9 0
      src/anki/math/Euler.h
  4. 25 0
      src/anki/math/Mat.h
  5. 18 0
      src/anki/math/Transform.h
  6. 27 0
      src/anki/math/Vec.h

+ 9 - 0
src/anki/math/Axisang.h

@@ -183,6 +183,15 @@ public:
 	}
 	}
 	/// @}
 	/// @}
 
 
+	/// @name Other
+	/// @{
+	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
+	void toString(StringAuto& str) const
+	{
+		str.sprintf("%f %f %f | %f", m_axis.x(), m_axis.y(), m_axis.z(), m_ang);
+	}
+	/// @}
+
 private:
 private:
 	/// @name Data
 	/// @name Data
 	/// @{
 	/// @{

+ 1 - 0
src/anki/math/Common.h

@@ -8,3 +8,4 @@
 #include <anki/math/Simd.h>
 #include <anki/math/Simd.h>
 #include <anki/util/Array.h>
 #include <anki/util/Array.h>
 #include <anki/util/Assert.h>
 #include <anki/util/Assert.h>
+#include <anki/util/String.h>

+ 9 - 0
src/anki/math/Euler.h

@@ -150,6 +150,15 @@ public:
 	}
 	}
 	/// @}
 	/// @}
 
 
+	/// @name Other
+	/// @{
+	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
+	void toString(StringAuto& str) const
+	{
+		str.sprintf("%f %f %f", m_vec.m_x, m_vec.m_y, m_vec.m_z);
+	}
+	/// @}
+
 private:
 private:
 	/// @name Data
 	/// @name Data
 	/// @{
 	/// @{

+ 25 - 0
src/anki/math/Mat.h

@@ -1535,6 +1535,31 @@ public:
 	{
 	{
 		return U8(I * J);
 		return U8(I * J);
 	}
 	}
+
+	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
+	void toString(StringAuto& str) const
+	{
+		for(U j = 0; j < J; ++j)
+		{
+			for(U i = 0; i < I; ++i)
+			{
+				CString fmt;
+				if(i == I - 1 && j == J - 1)
+				{
+					fmt = "%f";
+				}
+				else if(i == I - 1)
+				{
+					fmt = "%f\n";
+				}
+				else
+				{
+					fmt = "%f ";
+				}
+				str.append(StringAuto(str.getAllocator()).sprintf(fmt, m_arr2[j][i]));
+			}
+		}
+	}
 	/// @}
 	/// @}
 
 
 protected:
 protected:

+ 18 - 0
src/anki/math/Transform.h

@@ -205,6 +205,24 @@ public:
 		TVec<T, 4> out = TVec<T, 4>(m_rotation * (b * m_scale), T(0)) + m_origin;
 		TVec<T, 4> out = TVec<T, 4>(m_rotation * (b * m_scale), T(0)) + m_origin;
 		return out;
 		return out;
 	}
 	}
+
+	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
+	void toString(StringAuto& str) const
+	{
+		StringAuto b(str.getAllocator());
+		m_origin.toString(b);
+		str.append(b);
+		str.append("\n");
+
+		b.destroy();
+		m_rotation.toString(b);
+		str.append(b);
+		str.append("\n");
+
+		b.destroy();
+		b.sprintf("%f", m_scale);
+		str.append(b);
+	}
 	/// @}
 	/// @}
 
 
 private:
 private:

+ 27 - 0
src/anki/math/Vec.h

@@ -3040,6 +3040,33 @@ public:
 	{
 	{
 		return U8(N);
 		return U8(N);
 	}
 	}
+
+	ANKI_ENABLE_METHOD(std::is_floating_point<T>::value)
+	void toString(StringAuto& str) const
+	{
+		for(U i = 0; i < N; ++i)
+		{
+			str.append(StringAuto(str.getAllocator()).sprintf((i < i - N) ? "%f " : "%f", m_arr[i]));
+		}
+	}
+
+	ANKI_ENABLE_METHOD(std::is_integral<T>::value&& std::is_unsigned<T>::value)
+	void toString(StringAuto& str) const
+	{
+		for(U i = 0; i < N; ++i)
+		{
+			str.append(StringAuto(str.getAllocator()).sprintf((i < i - N) ? "%u " : "%u", m_arr[i]));
+		}
+	}
+
+	ANKI_ENABLE_METHOD(std::is_integral<T>::value&& std::is_signed<T>::value)
+	void toString(StringAuto& str) const
+	{
+		for(U i = 0; i < N; ++i)
+		{
+			str.append(StringAuto(str.getAllocator()).sprintf((i < i - N) ? "%d " : "%d", m_arr[i]));
+		}
+	}
 	/// @}
 	/// @}
 
 
 private:
 private: