SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEUtils
SEUtils
Mat22.h
Go to the documentation of this file.
1
/*
2
* Mat22.h
3
*
4
* Created on: Jul 25, 2019
5
* Author: mschefer
6
*/
7
8
#ifndef _SEUTILS_MAT22_H_
9
#define _SEUTILS_MAT22_H_
10
11
#include <tuple>
12
#include <assert.h>
13
14
namespace
SExtractor
{
15
16
class
Mat22;
17
Mat22
operator*
(
const
Mat22& a,
const
Mat22& b);
18
19
class
Mat22
{
20
public
:
21
22
Mat22
() :
m_mat
{ 1.0, 0.0, 0.0, 1.0 } {
23
}
24
25
Mat22
(
double
m1,
double
m2,
double
m3,
double
m4) :
m_mat
{ m1, m2, m3, m4 } {
26
}
27
28
explicit
Mat22
(
std::tuple<double, double, double, double>
tuple) :
m_mat
{
29
std
::get<0>(tuple),
30
std
::get<1>(tuple),
31
std
::get<2>(tuple),
32
std
::get<3>(tuple)} {}
33
34
Mat22
(
const
Mat22
&) =
default
;
35
36
Mat22
&
operator=
(
const
Mat22
& other) {
37
m_mat
[0] = other[0];
38
m_mat
[1] = other[1];
39
m_mat
[2] = other[2];
40
m_mat
[3] = other[3];
41
42
return
*
this
;
43
}
44
45
double
operator[]
(
size_t
i)
const
{
46
return
m_mat
[i];
47
}
48
49
double
&
operator[]
(
size_t
i) {
50
return
m_mat
[i];
51
}
52
53
Mat22
&
operator*=
(
const
Mat22
& other) {
54
*
this
= *
this
* other;
55
return
*
this
;
56
}
57
58
Mat22
GetInverse
()
const
{
59
Mat22
out;
60
61
double
inv_det = 1. / (
m_mat
[0] *
m_mat
[3] -
m_mat
[2] *
m_mat
[1]);
62
out[0] =
m_mat
[3] * inv_det; out[1] = -
m_mat
[1] * inv_det;
63
out[2] = -
m_mat
[2] * inv_det; out[3] =
m_mat
[0] * inv_det;
64
65
assert(
m_mat
[0] * out[0] +
m_mat
[1] * out[2] >= 1 - 1e-8);
66
assert(
m_mat
[0] * out[1] +
m_mat
[1] * out[3] <= 1e-8);
67
assert(
m_mat
[2] * out[0] +
m_mat
[3] * out[2] <= 1e-8);
68
assert(
m_mat
[2] * out[1] +
m_mat
[3] * out[3] >= 1 - 1e-8);
69
70
return
out;
71
}
72
73
Mat22
GetTranspose
()
const
{
74
Mat22
out {
m_mat
[0],
m_mat
[2],
75
m_mat
[1],
m_mat
[3] };
76
77
return
out;
78
}
79
80
double
m_mat
[4];
81
};
82
83
inline
Mat22
operator*
(
const
Mat22
& a,
const
Mat22
& b) {
84
Mat22
out;
85
86
out[0] = a[0] * b[0] + a[1] * b[2];
87
out[1] = a[0] * b[1] + a[1] * b[3];
88
out[2] = a[2] * b[0] + a[3] * b[2];
89
out[3] = a[2] * b[1] + a[3] * b[3];
90
91
return
out;
92
}
93
94
inline
Mat22
operator*
(
const
Mat22
& a,
double
b) {
95
Mat22
out;
96
97
out[0] = a[0] * b;
98
out[1] = a[1] * b;
99
out[2] = a[2] * b;
100
out[3] = a[3] * b;
101
102
return
out;
103
}
104
105
}
106
107
108
#endif
/* _SEUTILS_MAT22_H_ */
SExtractor::Mat22
Definition
Mat22.h:19
SExtractor::Mat22::Mat22
Mat22()
Definition
Mat22.h:22
SExtractor::Mat22::GetTranspose
Mat22 GetTranspose() const
Definition
Mat22.h:73
SExtractor::Mat22::GetInverse
Mat22 GetInverse() const
Definition
Mat22.h:58
SExtractor::Mat22::Mat22
Mat22(std::tuple< double, double, double, double > tuple)
Definition
Mat22.h:28
SExtractor::Mat22::operator[]
double & operator[](size_t i)
Definition
Mat22.h:49
SExtractor::Mat22::operator*=
Mat22 & operator*=(const Mat22 &other)
Definition
Mat22.h:53
SExtractor::Mat22::m_mat
double m_mat[4]
Definition
Mat22.h:80
SExtractor::Mat22::Mat22
Mat22(const Mat22 &)=default
SExtractor::Mat22::operator=
Mat22 & operator=(const Mat22 &other)
Definition
Mat22.h:36
SExtractor::Mat22::operator[]
double operator[](size_t i) const
Definition
Mat22.h:45
SExtractor::Mat22::Mat22
Mat22(double m1, double m2, double m3, double m4)
Definition
Mat22.h:25
std::function
SExtractor
Definition
MeasurementConfigurationSystem.dox:1
SExtractor::operator*
Mat22 operator*(const Mat22 &a, const Mat22 &b)
Definition
Mat22.h:83
std
STL namespace.
Generated by
1.10.0