OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_MATRIX3_F_H_ | |
6 #define UI_GFX_MATRIX3_F_H_ | |
7 | |
8 #include "base/logging.h" | |
9 #include "ui/gfx/vector3d_f.h" | |
10 | |
11 namespace gfx { | |
12 | |
13 class UI_EXPORT Matrix3F { | |
14 public: | |
15 Matrix3F(const Matrix3F& rhs); | |
16 ~Matrix3F(); | |
17 | |
18 bool IsEqual(const Matrix3F& rhs) const; | |
19 | |
20 // Element-wise comparison with given precision. | |
21 bool IsNear(const Matrix3F& rhs, float precision) const; | |
22 | |
23 float get(int i, int j) const { | |
24 return data_[MatrixToArrayCoords(i, j)]; | |
25 } | |
26 | |
27 void set(int i, int j, float v) { | |
28 data_[MatrixToArrayCoords(i, j)] = v; | |
29 } | |
30 | |
31 void set(float m00, float m01, float m02, | |
32 float m10, float m11, float m12, | |
33 float m20, float m21, float m22); | |
34 | |
35 Vector3dF get_column(int i) const { | |
36 return Vector3dF( | |
37 data_[MatrixToArrayCoords(0, i)], | |
38 data_[MatrixToArrayCoords(1, i)], | |
39 data_[MatrixToArrayCoords(2, i)]); | |
40 } | |
41 | |
42 void set_column(int i, const Vector3dF& c) { | |
43 data_[MatrixToArrayCoords(0, i)] = c.x(); | |
44 data_[MatrixToArrayCoords(1, i)] = c.y(); | |
45 data_[MatrixToArrayCoords(2, i)] = c.z(); | |
46 } | |
47 | |
48 // Returns an inverse of this if the matrix is non-singular, zero (== Zero()) | |
49 // otherwise. | |
50 Matrix3F Inverse() const; | |
51 | |
52 // Value of the determinant of the matrix. | |
53 float Determinant() const; | |
54 | |
55 // Trace (sum of diagonal elements) of the matrix. | |
56 float Trace() const { | |
57 return data_[MatrixToArrayCoords(0, 0)] + | |
58 data_[MatrixToArrayCoords(1, 1)] + | |
59 data_[MatrixToArrayCoords(2, 2)]; | |
60 } | |
61 | |
62 // Compute eigenvalues and (optionally) normalized eigenvectors of | |
63 // a positive defnite matrix *this. Eigenvectors are computed only if | |
64 // non-null |eigenvectors| matrix is passed. If it is NULL, the routine | |
65 // will not attempt to compute eigenvectors but will still return eigenvalues | |
66 // if they can be computed. | |
67 // If eigenvalues cannot be computed (the matrix does not meet constraints) | |
68 // the 0-vector is returned. Note that to retrieve eigenvalues, the matrix | |
69 // only needs to be symmetric while eigenvectors require it to be | |
70 // positive-definite. Passing a non-positive definite matrix will result in | |
71 // NaNs in vectors which cannot be computed. | |
72 // Eigenvectors are placed as column in |eigenvectors| in order corresponding | |
73 // to eigenvalues. | |
74 Vector3dF SolveEigenproblem(Matrix3F* eigenvectors) const; | |
75 | |
76 static Matrix3F Zeros(); | |
danakj
2013/02/01 00:02:34
nit: Move these up to the top of the class where t
motek.
2013/02/01 00:14:02
Done.
| |
77 static Matrix3F Ones(); | |
78 static Matrix3F Identity(); | |
79 static Matrix3F FromOuterProduct(const Vector3dF& a, const Vector3dF& bt); | |
80 | |
81 private: | |
82 float data_[9]; | |
83 | |
84 Matrix3F(); // Uninitialized default. | |
85 | |
86 static int MatrixToArrayCoords(int i, int j) { | |
87 DCHECK(i >= 0 && i < 3); | |
88 DCHECK(j >= 0 && j < 3); | |
89 return i * 3 + j; | |
90 } | |
91 }; | |
92 | |
93 inline bool operator==(const Matrix3F& lhs, const Matrix3F& rhs) { | |
94 return lhs.IsEqual(rhs); | |
95 } | |
96 | |
97 } // namespace gfx | |
98 | |
99 #endif // UI_GFX_MATRIX3_F_H_ | |
OLD | NEW |