| 127 if (y() != other.y()) return y() < other.y(); |
127 if (y() != other.y()) return y() < other.y(); |
| 128 if (z() != other.z()) return z() < other.z(); |
128 if (z() != other.z()) return z() < other.z(); |
| 129 return false; |
129 return false; |
| 130 } |
130 } |
| 131 |
131 |
| 132 // ============================================================================= |
132 Matrix::Matrix() : |
| 133 // |
133 coefficients {1, 0, 0, 0, 1, 0, 0, 0, 1} {} |
| 134 Matrix::Matrix(double vals[]) |
134 |
| 135 { |
135 Matrix::Matrix(std::initializer_list<double> values) |
| 136 for (int i = 0; i < 9; ++i) |
136 { |
| 137 m_vals[i] = vals[i]; |
137 if (values.size() == 9) |
| 138 } |
138 memcpy(&coefficients[0], values.begin(), sizeof coefficients); |
| 139 |
139 } |
| 140 // ============================================================================= |
140 |
| 141 // |
|
| 142 Matrix::Matrix(double fillval) |
|
| 143 { |
|
| 144 for (int i = 0; i < 9; ++i) |
|
| 145 m_vals[i] = fillval; |
|
| 146 } |
|
| 147 |
|
| 148 // ============================================================================= |
|
| 149 // |
|
| 150 Matrix::Matrix(const std::initializer_list<double>& vals) |
|
| 151 { |
|
| 152 if (vals.size() == 9) |
|
| 153 memcpy(&m_vals[0], vals.begin(), sizeof m_vals); |
|
| 154 } |
|
| 155 |
|
| 156 // ============================================================================= |
|
| 157 // |
|
| 158 void Matrix::dump() const |
|
| 159 { |
|
| 160 for (int i = 0; i < 3; ++i) |
|
| 161 { |
|
| 162 for (int j = 0; j < 3; ++j) |
|
| 163 print("%1\t", m_vals[i * 3 + j]); |
|
| 164 |
|
| 165 print("\n"); |
|
| 166 } |
|
| 167 } |
|
| 168 |
|
| 169 // ============================================================================= |
|
| 170 // |
|
| 171 QString Matrix::toString() const |
141 QString Matrix::toString() const |
| 172 { |
142 { |
| 173 QString val; |
143 QString val; |
| 174 |
144 |
| 175 for (int i = 0; i < 9; ++i) |
145 for (int i = 0; i < countof(coefficients); ++i) |
| 176 { |
146 { |
| 177 if (i > 0) |
147 if (i > 0) |
| 178 val += ' '; |
148 val += ' '; |
| 179 |
149 |
| 180 val += QString::number(m_vals[i]); |
150 val += QString::number(coefficients[i]); |
| 181 } |
151 } |
| 182 |
152 |
| 183 return val; |
153 return val; |
| 184 } |
154 } |
| 185 |
155 |
| 186 // ============================================================================= |
|
| 187 // |
|
| 188 void Matrix::zero() |
156 void Matrix::zero() |
| 189 { |
157 { |
| 190 memset(&m_vals[0], 0, sizeof m_vals); |
158 for (int i = 0; i < countof(coefficients); ++i) |
| 191 } |
159 coefficients[i] = 0; |
| 192 |
160 } |
| 193 // ============================================================================= |
161 |
| 194 // |
162 Matrix Matrix::operator*(const Matrix& other) const |
| 195 Matrix Matrix::mult(const Matrix& other) const |
163 { |
| 196 { |
164 Matrix result; |
| 197 Matrix val; |
165 result.zero(); |
| 198 val.zero(); |
|
| 199 |
166 |
| 200 for (int i = 0; i < 3; ++i) |
167 for (int i = 0; i < 3; ++i) |
| 201 for (int j = 0; j < 3; ++j) |
168 for (int j = 0; j < 3; ++j) |
| 202 for (int k = 0; k < 3; ++k) |
169 for (int k = 0; k < 3; ++k) |
| 203 val[(i * 3) + j] += m_vals[(i * 3) + k] * other[(k * 3) + j]; |
170 result(i, j) += (*this)(i, k) * other(k, j); |
| 204 |
171 |
| 205 return val; |
172 return result; |
| 206 } |
173 } |
| 207 |
174 |
| 208 // ============================================================================= |
175 Matrix& Matrix::operator=(const Matrix& other) |
| 209 // |
176 { |
| 210 Matrix& Matrix::operator= (const Matrix& other) |
177 for (int i = 0; i < countof(coefficients); ++i) |
| 211 { |
178 (*this)[i] = other[i]; |
| 212 memcpy(&m_vals[0], &other.m_vals[0], sizeof m_vals); |
179 return *this; |
| 213 return *this; |
180 } |
| 214 } |
181 |
| 215 |
182 double Matrix::determinant() const |
| 216 // ============================================================================= |
183 { |
| 217 // |
184 return |
| 218 double Matrix::getDeterminant() const |
185 (*this)(0, 0) * (*this)(1, 1) * (*this)(2, 2) + |
| 219 { |
186 (*this)(0, 1) * (*this)(1, 2) * (*this)(2, 0) + |
| 220 return (value(0) * value(4) * value(8)) + |
187 (*this)(0, 2) * (*this)(1, 0) * (*this)(2, 1) - |
| 221 (value(1) * value(5) * value(6)) + |
188 (*this)(0, 2) * (*this)(1, 1) * (*this)(2, 0) - |
| 222 (value(2) * value(3) * value(7)) - |
189 (*this)(0, 1) * (*this)(1, 0) * (*this)(2, 2) - |
| 223 (value(2) * value(4) * value(6)) - |
190 (*this)(0, 0) * (*this)(1, 2) * (*this)(2, 1); |
| 224 (value(1) * value(3) * value(8)) - |
191 } |
| 225 (value(0) * value(5) * value(7)); |
192 |
| 226 } |
|
| 227 |
|
| 228 // ============================================================================= |
|
| 229 // |
|
| 230 bool Matrix::operator== (const Matrix& other) const |
193 bool Matrix::operator== (const Matrix& other) const |
| 231 { |
194 { |
| 232 for (int i = 0; i < 9; ++i) |
195 for (int i = 0; i < countof(coefficients); ++i) |
| 233 { |
196 { |
| 234 if (value(i) != other[i]) |
197 if ((*this)[i] != other[i]) |
| 235 return false; |
198 return false; |
| 236 } |
199 } |
| 237 |
200 |
| 238 return true; |
201 return true; |
| 239 } |
202 } |
| 240 |
203 |
| 241 // ============================================================================= |
|
| 242 // |
|
| 243 LDBoundingBox::LDBoundingBox() |
204 LDBoundingBox::LDBoundingBox() |
| 244 { |
205 { |
| 245 reset(); |
206 reset(); |
| 246 } |
207 } |
| 247 |
208 |