Jelajahi Sumber

core: use exchange()

Daniele Bartolini 3 tahun lalu
induk
melakukan
ba5363f9e9
2 mengubah file dengan 9 tambahan dan 40 penghapusan
  1. 3 14
      src/core/math/matrix3x3.inl
  2. 6 26
      src/core/math/matrix4x4.inl

+ 3 - 14
src/core/math/matrix3x3.inl

@@ -117,20 +117,9 @@ inline Matrix3x3 operator*(Matrix3x3 a, const Matrix3x3& b)
 /// Transposes the matrix @a m and returns the result.
 inline Matrix3x3& transpose(Matrix3x3& m)
 {
-	f32 tmp;
-
-	tmp = m.x.y;
-	m.x.y = m.y.x;
-	m.y.x = tmp;
-
-	tmp = m.x.z;
-	m.x.z = m.z.x;
-	m.z.x = tmp;
-
-	tmp = m.y.z;
-	m.y.z = m.z.y;
-	m.z.y = tmp;
-
+	exchange(m.x.y, m.y.x);
+	exchange(m.x.z, m.z.x);
+	exchange(m.y.z, m.z.y);
 	return m;
 }
 

+ 6 - 26
src/core/math/matrix4x4.inl

@@ -167,32 +167,12 @@ inline bool operator==(const Matrix4x4& a, const Matrix4x4& b)
 /// Transposes the matrix @a m and returns the result.
 inline Matrix4x4& transpose(Matrix4x4& m)
 {
-	f32 tmp;
-
-	tmp = m.x.y;
-	m.x.y = m.y.x;
-	m.y.x = tmp;
-
-	tmp = m.x.z;
-	m.x.z = m.z.x;
-	m.z.x = tmp;
-
-	tmp = m.x.w;
-	m.x.w = m.t.x;
-	m.t.x = tmp;
-
-	tmp = m.y.z;
-	m.y.z = m.z.y;
-	m.z.y = tmp;
-
-	tmp = m.y.w;
-	m.y.w = m.t.y;
-	m.t.y = tmp;
-
-	tmp = m.z.w;
-	m.z.w = m.t.z;
-	m.t.z = tmp;
-
+	exchange(m.x.y, m.y.x);
+	exchange(m.x.z, m.z.x);
+	exchange(m.x.w, m.t.x);
+	exchange(m.y.z, m.z.y);
+	exchange(m.y.w, m.t.y);
+	exchange(m.z.w, m.t.z);
 	return m;
 }