Chromium Code Reviews| Index: ui/gfx/matrix3_f.h |
| diff --git a/ui/gfx/matrix3_f.h b/ui/gfx/matrix3_f.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7f3b34474f73bf07f72d327937e95ed8d4065def |
| --- /dev/null |
| +++ b/ui/gfx/matrix3_f.h |
| @@ -0,0 +1,77 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_MATRIX3_F_H_ |
| +#define UI_GFX_MATRIX3_F_H_ |
| + |
| +#include "ui/gfx/vector3d_f.h" |
| + |
| +namespace gfx { |
| + |
| +class UI_EXPORT Matrix3F { |
| + public: |
| + typedef float ScalarType; |
| + typedef Vector3dF VectorType; |
| + |
| + Matrix3F(const Matrix3F& rhs); |
| + ~Matrix3F(); |
| + |
| + bool IsEqual(const Matrix3F& rhs) const; |
| + |
| + // Element-wise comparison with given precision. A convenience method |
| + // primairly intended for unit tests. |
| + bool IsNear(const Matrix3F& rhs, ScalarType precision) const; |
|
danakj
2013/01/31 22:38:30
nit: primarily
If this is just for tests, can you
motek.
2013/01/31 23:29:56
On the second thought: I may actually need it in p
|
| + |
| + ScalarType get(int i, int j) const; |
| + void set(int i, int j, ScalarType v); |
| + void set(ScalarType v); |
| + void set(ScalarType m00, ScalarType m01, ScalarType m02, |
| + ScalarType m10, ScalarType m11, ScalarType m12, |
| + ScalarType m20, ScalarType m21, ScalarType m22); |
| + |
| + VectorType GetColumn(int i) const; |
| + void SetColumn(int i, const VectorType& c); |
| + |
| + // Returns an inverse of this if the matrix is non-singular, zero (== Zero()) |
| + // otherwise. |
| + Matrix3F Inverse() const; |
| + |
| + // Value of the determinant of the matrix. |
| + ScalarType Determinant() const; |
| + |
| + // Trace (sum of diagonal elements) of the matrix. |
| + ScalarType Trace() const; |
| + |
| + // Compute eigenvalues and (optionally) normalized eigenvectors of |
| + // a positive defnite matrix *this. Eigenvectors are computed only if |
| + // non-null |eigenvectors| matrix is passed. If it is NULL, the routine |
| + // will not attempt to compute eigenvectors but will still return eigenvalues |
| + // if they can be computed. |
| + // If eigenvalues cannot be computed (the matrix does not meet constraints) |
| + // the 0-vector is returned. Note that to retrieve eigenvalues, the matrix |
| + // only needs to be symmetric while eigenvectors require it to be |
| + // positive-definite. Passing a non-positive definite matrix will result in |
| + // NaNs in vectors which cannot be computed. |
| + // Eigenvectors are placed as column in |eigenvectors| in order corresponding |
| + // to eigenvalues. |
| + VectorType SolveEigenproblem(Matrix3F* eigenvectors) const; |
| + |
| + static Matrix3F Zeros(); |
| + static Matrix3F Ones(); |
| + static Matrix3F Identity(); |
| + static Matrix3F FromOuterProduct(const VectorType& a, const VectorType& bt); |
| + |
| + private: |
| + ScalarType data_[9]; |
| + |
| + Matrix3F(); // Uninitialized default. |
| +}; |
| + |
| +inline bool operator==(const Matrix3F& lhs, const Matrix3F& rhs) { |
| + return lhs.IsEqual(rhs); |
| +} |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_MATRIX3_F_H_ |