Euphoria
mat2.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "base/vec2.h"
4 #include "base/angle.h"
5 
6 
7 namespace eu
8 {
9  struct mat2f
10  {
11  bool operator==(const mat2f& rhs) = delete;
12 
13  [[nodiscard]] static mat2f from_col_major
14  (
15  float t00, float t01,
16  float t10, float t11
17  );
18 
19  [[nodiscard]] constexpr static mat2f from_row_major
20  (
21  float t00, float t10,
22  float t01, float t11
23  )
24  {
25  return
26  {
27  t00, t01,
28  t10, t11
29  };
30  }
31 
32  [[nodiscard]] constexpr static mat2f from_scalar(float scalar)
33  {
34  const float z = 0;
35  return from_row_major
36  (
37  scalar, z,
38  z, scalar
39  );
40  }
41  [[nodiscard]] static mat2f from_stretch_x(float k);
42  [[nodiscard]] static mat2f from_stretch_y(float k);
43  [[nodiscard]] static mat2f from_rotation(const Angle& a);
44 
45  float* get_data_ptr();
46 
47  [[nodiscard]] float get(int row, int col) const;
48  [[nodiscard]] vec2f get_column(int c) const;
49  [[nodiscard]] vec2f get_row(int r) const;
50 
51  [[nodiscard]] const float* get_data_ptr() const;
52 
53  void operator+=(const mat2f& rhs);
54  void operator-=(const mat2f& rhs);
55 
56  private:
57  float data[4];
58 
59  mat2f() = default;
60 
61  constexpr mat2f
62  (
63  float t00, float t01,
64  float t10, float t11
65  )
66  : data
67  {
68  t00, t01,
69  t10, t11
70  }
71  {
72  }
73  };
74 
76 
77 
78  std::string to_string(const mat2f& m);
79 
80  mat2f operator+(const mat2f& lhs, const mat2f& rhs);
81  mat2f operator-(const mat2f& lhs, const mat2f& rhs);
82  mat2f operator*(const mat2f& lhs, const mat2f& rhs);
83  vec2f operator*(const mat2f& lhs, const vec2f& rhs);
84 }
85 
86 // todo(Gustav): add a multi line format option?
ADD_DEFAULT_FORMATTER(eu::mat2f, std::string, eu::to_string)
Definition: assert.h:90
Angle operator+(const Angle &lhs, const Angle &rhs)
Definition: angle.cc:123
Angle operator-(const Angle &lhs, const Angle &rhs)
Definition: angle.cc:132
std::string to_string(const Aabb &a)
Definition: aabb.cc:110
constexpr mat2f m2_identity
Definition: mat2.h:75
Angle operator*(const Angle &lhs, float rhs)
Definition: angle.cc:149
Definition: mat2.h:10
static mat2f from_stretch_y(float k)
Definition: mat2.cc:30
constexpr static mat2f from_scalar(float scalar)
Definition: mat2.h:32
static mat2f from_stretch_x(float k)
Definition: mat2.cc:19
void operator-=(const mat2f &rhs)
Definition: mat2.cc:63
static mat2f from_rotation(const Angle &a)
Definition: mat2.cc:40
vec2f get_column(int c) const
Definition: mat2.cc:94
vec2f get_row(int r) const
Definition: mat2.cc:101
bool operator==(const mat2f &rhs)=delete
float get(int row, int col) const
Definition: mat2.cc:87
void operator+=(const mat2f &rhs)
Definition: mat2.cc:53
static mat2f from_col_major(float t00, float t01, float t10, float t11)
Definition: mat2.cc:9
constexpr static mat2f from_row_major(float t00, float t10, float t01, float t11)
Definition: mat2.h:20
float * get_data_ptr()
Definition: mat2.cc:80
Definition: vec2.h:33