Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: ui/gfx/matrix3_f.h

Issue 12096069: New Matrix3F class added in gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remaining nits. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/gfx/matrix3_f.cc » ('j') | ui/gfx/matrix3_f.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 static Matrix3F Zeros();
19 static Matrix3F Ones();
20 static Matrix3F Identity();
21 static Matrix3F FromOuterProduct(const Vector3dF& a, const Vector3dF& bt);
22
23 bool IsEqual(const Matrix3F& rhs) const;
24
25 // Element-wise comparison with given precision.
26 bool IsNear(const Matrix3F& rhs, float precision) const;
27
28 float get(int i, int j) const {
29 return data_[MatrixToArrayCoords(i, j)];
30 }
31
32 void set(int i, int j, float v) {
33 data_[MatrixToArrayCoords(i, j)] = v;
34 }
35
36 void set(float m00, float m01, float m02,
37 float m10, float m11, float m12,
38 float m20, float m21, float m22) {
39 data_[0] = m00;
40 data_[1] = m01;
41 data_[2] = m02;
42 data_[3] = m10;
43 data_[4] = m11;
44 data_[5] = m12;
45 data_[6] = m20;
46 data_[7] = m21;
47 data_[8] = m22;
48 }
49
50 Vector3dF get_column(int i) const {
51 return Vector3dF(
52 data_[MatrixToArrayCoords(0, i)],
53 data_[MatrixToArrayCoords(1, i)],
54 data_[MatrixToArrayCoords(2, i)]);
55 }
56
57 void set_column(int i, const Vector3dF& c) {
58 data_[MatrixToArrayCoords(0, i)] = c.x();
59 data_[MatrixToArrayCoords(1, i)] = c.y();
60 data_[MatrixToArrayCoords(2, i)] = c.z();
61 }
62
63 // Returns an inverse of this if the matrix is non-singular, zero (== Zero())
64 // otherwise.
65 Matrix3F Inverse() const;
66
67 // Value of the determinant of the matrix.
68 float Determinant() const;
69
70 // Trace (sum of diagonal elements) of the matrix.
71 float Trace() const {
72 return data_[MatrixToArrayCoords(0, 0)] +
73 data_[MatrixToArrayCoords(1, 1)] +
74 data_[MatrixToArrayCoords(2, 2)];
75 }
76
77 // Compute eigenvalues and (optionally) normalized eigenvectors of
78 // a positive defnite matrix *this. Eigenvectors are computed only if
79 // non-null |eigenvectors| matrix is passed. If it is NULL, the routine
80 // will not attempt to compute eigenvectors but will still return eigenvalues
81 // if they can be computed.
82 // If eigenvalues cannot be computed (the matrix does not meet constraints)
83 // the 0-vector is returned. Note that to retrieve eigenvalues, the matrix
84 // only needs to be symmetric while eigenvectors require it to be
85 // positive-definite. Passing a non-positive definite matrix will result in
86 // NaNs in vectors which cannot be computed.
87 // Eigenvectors are placed as column in |eigenvectors| in order corresponding
88 // to eigenvalues.
89 Vector3dF SolveEigenproblem(Matrix3F* eigenvectors) const;
90
91 private:
92 float data_[9];
sky 2013/02/01 00:25:30 fields after functions.
motek. 2013/02/01 15:19:35 Done.
93
94 Matrix3F(); // Uninitialized default.
sky 2013/02/01 00:25:30 Seems painful not to have this and let it return t
motek. 2013/02/01 15:19:35 I don't think making the constructor set identity
95
96 static int MatrixToArrayCoords(int i, int j) {
97 DCHECK(i >= 0 && i < 3);
98 DCHECK(j >= 0 && j < 3);
99 return i * 3 + j;
100 }
101 };
102
103 inline bool operator==(const Matrix3F& lhs, const Matrix3F& rhs) {
104 return lhs.IsEqual(rhs);
105 }
106
107 } // namespace gfx
108
109 #endif // UI_GFX_MATRIX3_F_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/matrix3_f.cc » ('j') | ui/gfx/matrix3_f.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698