OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/matrix3_f.h" | 5 #include "ui/gfx/geometry/matrix3_f.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 Matrix3F Matrix3F::Inverse() const { | 101 Matrix3F Matrix3F::Inverse() const { |
102 Matrix3F inverse = Matrix3F::Zeros(); | 102 Matrix3F inverse = Matrix3F::Zeros(); |
103 double determinant = Determinant3x3(data_); | 103 double determinant = Determinant3x3(data_); |
104 if (std::numeric_limits<float>::epsilon() > std::abs(determinant)) | 104 if (std::numeric_limits<float>::epsilon() > std::abs(determinant)) |
105 return inverse; // Singular matrix. Return Zeros(). | 105 return inverse; // Singular matrix. Return Zeros(). |
106 | 106 |
107 inverse.set( | 107 inverse.set( |
108 (data_[M11] * data_[M22] - data_[M12] * data_[M21]) / determinant, | 108 static_cast<float>((data_[M11] * data_[M22] - data_[M12] * data_[M21]) / |
109 (data_[M02] * data_[M21] - data_[M01] * data_[M22]) / determinant, | 109 determinant), |
110 (data_[M01] * data_[M12] - data_[M02] * data_[M11]) / determinant, | 110 static_cast<float>((data_[M02] * data_[M21] - data_[M01] * data_[M22]) / |
111 (data_[M12] * data_[M20] - data_[M10] * data_[M22]) / determinant, | 111 determinant), |
112 (data_[M00] * data_[M22] - data_[M02] * data_[M20]) / determinant, | 112 static_cast<float>((data_[M01] * data_[M12] - data_[M02] * data_[M11]) / |
113 (data_[M02] * data_[M10] - data_[M00] * data_[M12]) / determinant, | 113 determinant), |
114 (data_[M10] * data_[M21] - data_[M11] * data_[M20]) / determinant, | 114 static_cast<float>((data_[M12] * data_[M20] - data_[M10] * data_[M22]) / |
115 (data_[M01] * data_[M20] - data_[M00] * data_[M21]) / determinant, | 115 determinant), |
116 (data_[M00] * data_[M11] - data_[M01] * data_[M10]) / determinant); | 116 static_cast<float>((data_[M00] * data_[M22] - data_[M02] * data_[M20]) / |
| 117 determinant), |
| 118 static_cast<float>((data_[M02] * data_[M10] - data_[M00] * data_[M12]) / |
| 119 determinant), |
| 120 static_cast<float>((data_[M10] * data_[M21] - data_[M11] * data_[M20]) / |
| 121 determinant), |
| 122 static_cast<float>((data_[M01] * data_[M20] - data_[M00] * data_[M21]) / |
| 123 determinant), |
| 124 static_cast<float>((data_[M00] * data_[M11] - data_[M01] * data_[M10]) / |
| 125 determinant)); |
117 return inverse; | 126 return inverse; |
118 } | 127 } |
119 | 128 |
120 float Matrix3F::Determinant() const { | 129 float Matrix3F::Determinant() const { |
121 return static_cast<float>(Determinant3x3(data_)); | 130 return static_cast<float>(Determinant3x3(data_)); |
122 } | 131 } |
123 | 132 |
124 Vector3dF Matrix3F::SolveEigenproblem(Matrix3F* eigenvectors) const { | 133 Vector3dF Matrix3F::SolveEigenproblem(Matrix3F* eigenvectors) const { |
125 // The matrix must be symmetric. | 134 // The matrix must be symmetric. |
126 const float epsilon = std::numeric_limits<float>::epsilon(); | 135 const float epsilon = std::numeric_limits<float>::epsilon(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // Normalize. | 237 // Normalize. |
229 eigvec.Scale(1.0f / eigvec.Length()); | 238 eigvec.Scale(1.0f / eigvec.Length()); |
230 eigenvectors->set_column(i, eigvec); | 239 eigenvectors->set_column(i, eigvec); |
231 } | 240 } |
232 } | 241 } |
233 | 242 |
234 return Vector3dF(eigenvalues[0], eigenvalues[1], eigenvalues[2]); | 243 return Vector3dF(eigenvalues[0], eigenvalues[1], eigenvalues[2]); |
235 } | 244 } |
236 | 245 |
237 } // namespace gfx | 246 } // namespace gfx |
OLD | NEW |