-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.hpp
126 lines (100 loc) · 2.39 KB
/
Cell.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include <iostream>
#include <iomanip>
#include "GridayTypes.hpp"
#include "Vector.hpp"
struct Cell
{
Vector a; // Column 1
Vector b; // Column 2
Vector c; // Column 3
};
//inline Cell inverse(const Cell& cell);
//inline Cell transpose(const Cell& cell);
//inline GReal det(const Cell& cell);
//inline Vector operator * (const Cell& cell, const Vector& v);
//inline Cell operator * (const Cell& cell, const GReal& r);
//inline Cell operator * (const GReal& r, const Cell& cell);
//inline Cell operator * (const Cell& m, const Cell& n);
//std::ostream& operator << (std::ostream& os, const Cell& cell);
//std::istream& operator >> (std::istream& is, Cell& cell);
inline
Vector
operator * (const Cell& cell, const Vector& v)
{
Vector c;
c = v[0] * cell.a + v[1] * cell.b + v[2] * cell.c;
return c;
}
inline
Cell
operator * (const Cell& cell, const GReal& r)
{
Cell c;
c.a = cell.a * r;
c.b = cell.b * r;
c.c = cell.c * r;
return c;
}
inline
Cell
operator * (const GReal& r, const Cell& cell)
{
return cell * r;
}
inline
Cell
operator * (const Cell& m, const Cell& n)
{
return {m * n.a, m * n.b, m * n.c};
}
inline
Cell
transpose(const Cell& cell)
{
return {{cell.a[0], cell.b[0], cell.c[0]},
{cell.a[1], cell.b[1], cell.c[1]},
{cell.a[2], cell.b[2], cell.c[2]}};
}
inline
GReal
det(const Cell& cell)
{
return dot(cell.a, cross(cell.b, cell.c));
}
inline
Cell
inverse(const Cell& cell)
{
Cell inv;
GReal invd = 1.0 / det(cell);
const Vector& a = cell.a;
const Vector& b = cell.b;
const Vector& c = cell.c;
inv.a = cross(b, c) * invd;
inv.b = cross(c, a) * invd;
inv.c = cross(a, b) * invd;
return transpose(inv);
}
inline
std::ostream&
operator << (std::ostream& os, const Cell& cell)
{
os << std::setw(15) << cell.a[0] <<
std::setw(15) << cell.b[0] <<
std::setw(15) << cell.c[0] << std::endl;
os << std::setw(15) << cell.a[1] <<
std::setw(15) << cell.b[1] <<
std::setw(15) << cell.c[1] << std::endl;
os << std::setw(15) << cell.a[2] <<
std::setw(15) << cell.b[2] <<
std::setw(15) << cell.c[2];
return os;
}
inline
std::istream&
operator >> (std::istream& is, Cell& cell)
{
is >> cell.a >> cell.b >> cell.c;
return is;
}