src/basics.h

changeset 1219
8e39b5d7c562
parent 1218
e0b59d183f96
child 1222
34def2630300
--- a/src/basics.h	Thu Jan 04 19:52:24 2018 +0200
+++ b/src/basics.h	Thu Jan 04 20:21:36 2018 +0200
@@ -85,78 +85,51 @@
 
 Q_DECLARE_METATYPE(Vertex)
 
-//
-// A mathematical 3 x 3 matrix
-//
+/*
+ * A mathematical 3 x 3 matrix
+ */
 class Matrix
 {
 public:
-	Matrix() {}
-	Matrix(const std::initializer_list<double>& vals);
-
-	// Constructs a matrix all 9 elements initialized to the same value.
-	Matrix(double fillval);
-
-	// Constructs a matrix with a C-array.
-	// note: @vals is expected to have exactly 9 elements.
-	Matrix(double vals[]);
-
-	// Calculates the matrix's determinant.
-	double			getDeterminant() const;
-
-	// Multiplies this matrix with @other
-	// note: a.mult(b) is not equivalent to b.mult(a)!
-	Matrix			mult(const Matrix& other) const;
-
-	// Prints the matrix to stdout.
-	void			dump() const;
-
-	// Yields a string representation of the matrix.
-	QString			toString() const;
-
-	// Zeroes the matrix out.
-	void			zero();
-
-	// Assigns the matrix values to the values of @other.
-	Matrix&			operator= (const Matrix& other);
+	Matrix();
+	Matrix(std::initializer_list<double> values);
 
-	// Returns a mutable reference to a value by @idx
-	inline double& value(int idx)
-	{
-		return m_vals[idx];
-	}
-
-	// An overload of value() for const matrices.
-	inline const double& value(int idx) const
-	{
-		return m_vals[idx];
-	}
-
-	// An operator overload for mult().
-	inline Matrix operator*(const Matrix& other) const
-	{
-		return mult(other);
-	}
-
-	// An operator overload for value().
-	inline double& operator[](int idx)
-	{
-		return value(idx);
-	}
-
-	// An operator overload for value() const.
-	inline const double& operator[](int idx) const
-	{
-		return value(idx);
-	}
-
-	// Checks whether the two matrices have the same values.
-	bool operator== (const Matrix& other) const;
+	double determinant() const;
+	QString toString() const;
+	void zero();
+	Matrix& operator=(const Matrix& other);
+	Matrix operator*(const Matrix& other) const;
+	double& operator[](int idx);
+	const double& operator[](int idx) const;
+	double& operator()(int row, int column);
+	const double& operator()(int row, int column) const;
+	bool operator==(const Matrix& other) const;
 
 private:
-	double m_vals[9];
+	double coefficients[9];
 };
 
+inline double& Matrix::operator[](int idx)
+{
+	return coefficients[idx];
+}
+
+inline const double& Matrix::operator[](int idx) const
+{
+	return coefficients[idx];
+}
+
+inline double& Matrix::operator()(int row, int column)
+{
+	return coefficients[row * 3 + column];
+}
+
+inline const double& Matrix::operator()(int row, int column) const
+{
+	return coefficients[row * 3 + column];
+}
+
+
 //
 // Defines a bounding box that encompasses a given set of objects.
 // vertex0 is the minimum vertex, vertex1 is the maximum vertex.
@@ -184,8 +157,6 @@
 	Vertex m_vertex1;
 };
 
-extern const Matrix IdentityMatrix;
-
 static const double Pi = 3.14159265358979323846;
 
 

mercurial