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
127
128
129
130
131
132
|
#ifndef TIBIA_MATRIX_HH_
#define TIBIA_MATRIX_HH_ 1
typedef<typename T>
struct matrix{
// REGULAR FUNCTIONS
// =========================================================================
matrix(int xmin, int xmax, int ymin, int ymax){
int dx = (xmax - xmin) + 1;
int dy = (ymax - ymin) + 1;
if(dx < 1 || dy < 1){
error("matrix: Ungueltige Feldgroesse %d..%d, %d..%d.\n", xmin, xmax, ymin, ymax);
if(dx < 1){
dx = 1;
}
if(dy < 1){
dy = 1;
}
}
this->xmin = xmin;
this->ymin = ymin;
this->dx = dx;
this->dy = dy;
this->entry = new T[dx * dy];
}
matrix(int xmin, int xmax, int ymin, int ymax, T init) : matrix(xmin, xmax, ymin, ymax) {
int count = this->dx * this->dy;
for(int i = 0; i < count; i += 1){
this->entry[i] = init;
}
}
// TODO(fusion): Probably missing some inlined destructor?
T *at(int x, int y){
int xoffset = x - this->xmin;
int yoffset = y - this->ymin;
if(xoffset < 0 || xoffset >= this->dx || yoffset < 0 || yoffset >= this->dy){
error("matrix::operator(): Ungueltiger Index %d/%d.\n", x, y);
return &this->entry[0];
}else{
// TODO(fusion): Are we really storing this in row major order?
return &this->entry[yoffset * this->dx + xoffset];
}
}
// DATA
// =========================================================================
int xmin;
int ymin;
int dx;
int dy;
T *entry;
};
typedef<typename T>
struct matrix3d{
// REGULAR FUNCTIONS
// =========================================================================
matrix3d(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax){
int dx = (xmax - xmin) + 1;
int dy = (ymax - ymin) + 1;
int dz = (zmax - zmin) + 1;
if(dx < 1 || dy < 1 || dz < 1){
error("matrix3d: Ungueltige Feldgroesse %d..%d, %d..%d, %d..%d.\n",
xmin, xmax, ymin, ymax, zmin, zmax);
if(dx < 1){
dx = 1;
}
if(dy < 1){
dy = 1;
}
if(dz < 1){
dz = 1;
}
}
this->xmin = xmin;
this->ymin = ymin;
this->dx = dx;
this->dy = dy;
this->entry = new T[dx * dy];
}
matrix3d(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax, T init)
: matrix(xmin, xmax, ymin, ymax, zmin, zmax) {
int count = this->dx * this->dy * this->dz;
for(int i = 0; i < count; i += 1){
this->entry[i] = init;
}
}
// TODO(fusion): Probably missing some inlined destructor?
T *at(int x, int y, int z){
int xoffset = x - this->xmin;
int yoffset = y - this->ymin;
int zoffset = z - this->zmin;
if(xoffset < 0 || xoffset >= this->dx
|| yoffset < 0 || yoffset >= this->dy
|| zoffset < 0 || zoffset >= this->dz){
error("matrix3d::operator(): Ungueltiger Index %d/%d/%d.\n", x, y, z);
return &this->entry[0];
}else{
// TODO(fusion): Same as `matrix::at` on the XY plane.
return &this->entry[zoffset * this->dx * this->dy
+ yoffset * this->dx
+ xoffset];
}
}
// DATA
// =========================================================================
int xmin;
int ymin;
int zmin;
int dx;
int dy;
int dz;
T *entry;
};
#endif //TIBIA_MATRIX_HH_
|