12#define __MATRIX2_H__ 1
14#include "math/vector_2.h"
21 Mat2(
const Vec2& a,
const Vec2& b);
22 Mat2(
const Mat2& copy);
24 Mat2 Identity()
const;
25 Mat2 Multiply(
const Mat2& other)
const;
26 float Determinant()
const;
28 Vec2 GetLine(
int line)
const;
29 Vec2 GetColum(
int line)
const;
32 Mat2 Transpose()
const;
34 inline Mat2 operator+(
const Mat2& other)
const;
35 inline void operator+=(
const Mat2& other);
36 inline Mat2 operator+(
float value)
const;
37 inline void operator+=(
float value);
38 inline Mat2 operator-(
const Mat2& other)
const;
39 inline void operator-=(
const Mat2& other);
40 inline Mat2 operator-(
float value)
const;
41 inline void operator-=(
float value);
43 inline Mat2 operator*(
float value)
const;
44 inline void operator*=(
float value);
45 inline Mat2 operator/(
float value)
const;
46 inline void operator/=(
float value);
48 bool operator==(
const Mat2& other)
const;
49 bool operator!=(
const Mat2& other)
const;
50 inline void operator=(
const Mat2& other);
55inline Mat2 Mat2::operator+(
const Mat2& other)
const {
57 for (
int i = 0; i < 4; i++) {
58 res.m[i] = m[i] + other.m[i];
63inline void Mat2::operator+=(
const Mat2& other) {
64 for (
int i = 0; i < 4; i++) {
69inline Mat2 Mat2::operator+(
float value)
const {
71 for (
int i = 0; i < 4; i++) {
72 res.m[i] = m[i] + value;
77inline void Mat2::operator+=(
float value) {
78 for (
int i = 0; i < 4; i++) {
83inline Mat2 Mat2::operator-(
const Mat2& other)
const {
85 for (
int i = 0; i < 4; i++) {
86 res.m[i] = m[i] - other.m[i];
91inline void Mat2::operator-=(
const Mat2& other) {
92 for (
int i = 0; i < 4; i++) {
97inline Mat2 Mat2::operator-(
float value)
const {
99 for (
int i = 0; i < 4; i++) {
100 res.m[i] = m[i] - value;
105inline void Mat2::operator-=(
float value) {
106 for (
int i = 0; i < 4; i++) {
111inline Mat2 Mat2::operator*(
float value)
const {
113 for (
int i = 0; i < 4; i++) {
114 res.m[i] = m[i] * value;
119inline void Mat2::operator*=(
float value) {
120 for (
int i = 0; i < 4; i++) {
125inline Mat2 Mat2::operator/(
float value)
const {
127 for (
int i = 0; i < 4; i++) {
128 res.m[i] = m[i] / value;
133inline void Mat2::operator/=(
float value) {
134 for (
int i = 0; i < 4; i++) {
139inline bool Mat2::operator==(
const Mat2& other)
const {
140 for (
int i = 0; i < 4; i++) {
141 if (m[i] != other.m[i])
return false;
146inline bool Mat2::operator!=(
const Mat2& other)
const {
147 for (
int i = 0; i < 4; i++) {
148 if (m[i] != other.m[i])
return true;
153inline void Mat2::operator=(
const Mat2& other) {
154 for (
int i = 0; i < 4; i++) {
159inline Mat2 Mat2::Identity()
const {
return Mat2(Vec2(1, 0), Vec2(0, 1)); }
161inline float Mat2::Determinant()
const {
return m[0] * m[3] - m[1] * m[2]; }
163inline Mat2 Mat2::Inverse()
const {
164 float det = this->Determinant();
165 Mat2 res = this->Adjoint() / det;
169inline Mat2 Mat2::Multiply(
const Mat2& other)
const {
171 for (
int row = 0; row < 2; row++) {
172 for (
int col = 0; col < 2; col++) {
173 res.m[row * 2 + col] = m[row * 2 + 0] * other.m[0 * 2 + col] +
174 m[row * 2 + 1] * other.m[1 * 2 + col] +
175 m[row * 2 + 2] * other.m[2 * 2 + col];
181inline Mat2 Mat2::Adjoint()
const {
182 return Mat2(Vec2(m[3], -m[1]), Vec2(-m[2], m[0]));
185inline Mat2 Mat2::Transpose()
const {
186 return Mat2(Vec2(m[0], m[2]), Vec2(m[1], m[3]));
189inline Vec2 Mat2::GetLine(
int line)
const {
190 return Vec2(m[line * 2 + 0], m[line * 2 + 1]);
193inline Vec2 Mat2::GetColum(
int line)
const {
194 return Vec2(m[line], m[2 + line]);
copperdielf Math Library
Definition: buffer.hpp:5