Skip to content
Snippets Groups Projects
Matrix.h 2.35 KiB
Newer Older
#define _USE_MATH_DEFINES
#include <vector>
#include <cmath>
#include <iostream>
#include <cassert>


class Matrix {
private:
	uint32_t m_cols, m_rows;
	std::vector<double> m_matrix;
public:
	Matrix(uint32_t input_rows = 0, uint32_t input_cols = 0, double value = 0.0) : m_rows{ input_rows }, m_cols{ input_cols } {
		m_matrix.resize(m_rows * m_cols, value);
	Matrix(uint32_t input_rows, uint32_t input_cols, std::vector<double> value) : m_rows{ input_rows }, m_cols{ input_cols } {
		assert(input_cols* input_rows == value.size());
		m_matrix = value;
	}
	Matrix(const Matrix& input_matrix) : m_cols{ input_matrix.m_cols }, m_rows{ input_matrix.m_rows }, m_matrix{input_matrix.m_matrix} {};

	double& at(uint32_t input_rows, uint32_t input_cols) {
		assert(input_rows < m_rows&& input_cols < m_cols);
		return m_matrix.at((input_rows * m_cols) + input_cols);
	}

	double at(uint32_t input_rows, uint32_t input_cols) const {
		assert(input_rows < m_rows&& input_cols < m_cols);
		return m_matrix.at((input_rows * m_cols) + input_cols);
	}

	double& operator() (uint32_t input_rows, uint32_t input_cols);
	friend Matrix operator+(const Matrix& matrix_1, const Matrix& matrix_2);
	friend Matrix operator+(const Matrix& matrix_1, const double in);
	friend Matrix operator+(const double in, const Matrix& matrix_1);

	friend Matrix operator-(const Matrix& matrix_1, const Matrix& matrix_2);
	friend Matrix operator-(const Matrix& matrix_1, const double in);
	friend Matrix operator-(const double in, const Matrix& matrix_1);

	friend Matrix operator*(const Matrix& matrix_1, const Matrix& matrix_2);
	friend Matrix operator*(const Matrix& matrix_1, double in);
	friend Matrix operator*(double in, const Matrix& matrix_1);

	friend Matrix operator/(const Matrix& matrix_1, const double in);
	friend Matrix operator/(const double in, const Matrix& matrix_1);

	static Matrix RotationOX(double α);
	static Matrix RotationOY(double α);
	static Matrix RotationOZ(double α);
	friend std::ostream& operator<<(std::ostream& out, const Matrix& i_matrix);
	friend std::ofstream& operator<<(std::ofstream& out, const Matrix& i_matrix);