Move MatrixDecomposition into its TU.
This commit is contained in:
@@ -30,7 +30,7 @@ test_fixtures("file_fixtures") {
|
||||
group("fixtures") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
public_deps = [
|
||||
":file_fixtures",
|
||||
":shader_fixtures",
|
||||
]
|
||||
|
||||
@@ -10,6 +10,8 @@ impeller_component("geometry") {
|
||||
"color.h",
|
||||
"matrix.cc",
|
||||
"matrix.h",
|
||||
"matrix_decomposition.cc",
|
||||
"matrix_decomposition.h",
|
||||
"path.cc",
|
||||
"path.h",
|
||||
"path_builder.cc",
|
||||
|
||||
@@ -64,9 +64,9 @@ TEST(GeometryTest, TestDecomposition) {
|
||||
|
||||
auto result = rotated.Decompose();
|
||||
|
||||
ASSERT_TRUE(result.first);
|
||||
ASSERT_TRUE(result.has_value());
|
||||
|
||||
Matrix::Decomposition res = result.second;
|
||||
MatrixDecomposition res = result.value();
|
||||
|
||||
auto quaternion = Quaternion{{0.0, 0.0, 1.0}, M_PI_4};
|
||||
ASSERT_QUATERNION_NEAR(res.rotation, quaternion);
|
||||
@@ -79,9 +79,9 @@ TEST(GeometryTest, TestDecomposition2) {
|
||||
|
||||
auto result = (translated * rotated * scaled).Decompose();
|
||||
|
||||
ASSERT_TRUE(result.first);
|
||||
ASSERT_TRUE(result.has_value());
|
||||
|
||||
Matrix::Decomposition res = result.second;
|
||||
MatrixDecomposition res = result.value();
|
||||
|
||||
auto quaternion = Quaternion{{0.0, 0.0, 1.0}, M_PI_4};
|
||||
|
||||
@@ -104,9 +104,9 @@ TEST(GeometryTest, TestRecomposition) {
|
||||
|
||||
auto result = rotated.Decompose();
|
||||
|
||||
ASSERT_TRUE(result.first);
|
||||
ASSERT_TRUE(result.has_value());
|
||||
|
||||
Matrix::Decomposition res = result.second;
|
||||
MatrixDecomposition res = result.value();
|
||||
|
||||
auto quaternion = Quaternion{{0.0, 0.0, 1.0}, M_PI_4};
|
||||
|
||||
@@ -125,9 +125,9 @@ TEST(GeometryTest, TestRecomposition2) {
|
||||
|
||||
auto result = matrix.Decompose();
|
||||
|
||||
ASSERT_TRUE(result.first);
|
||||
ASSERT_TRUE(result.has_value());
|
||||
|
||||
ASSERT_MATRIX_NEAR(matrix, Matrix{result.second});
|
||||
ASSERT_MATRIX_NEAR(matrix, Matrix{result.value()});
|
||||
}
|
||||
|
||||
TEST(GeometryTest, QuaternionLerp) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Matrix::Matrix(const Decomposition& d) : Matrix() {
|
||||
Matrix::Matrix(const MatrixDecomposition& d) : Matrix() {
|
||||
/*
|
||||
* Apply perspective.
|
||||
*/
|
||||
@@ -197,14 +197,14 @@ Scalar Matrix::GetDeterminant() const {
|
||||
* Adapted for Impeller from Graphics Gems:
|
||||
* http://www.realtimerendering.com/resources/GraphicsGems/gemsii/unmatrix.c
|
||||
*/
|
||||
Matrix::DecompositionResult Matrix::Decompose() const {
|
||||
std::optional<MatrixDecomposition> Matrix::Decompose() const {
|
||||
/*
|
||||
* Normalize the matrix.
|
||||
*/
|
||||
Matrix self = *this;
|
||||
|
||||
if (self.e[3][3] == 0) {
|
||||
return {false, {}};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@@ -225,10 +225,10 @@ Matrix::DecompositionResult Matrix::Decompose() const {
|
||||
perpectiveMatrix.e[3][3] = 1;
|
||||
|
||||
if (perpectiveMatrix.GetDeterminant() == 0.0) {
|
||||
return {false, {}};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Decomposition result;
|
||||
MatrixDecomposition result;
|
||||
|
||||
/*
|
||||
* ==========================================================================
|
||||
@@ -355,10 +355,10 @@ Matrix::DecompositionResult Matrix::Decompose() const {
|
||||
result.rotation.z = -result.rotation.z;
|
||||
}
|
||||
|
||||
return DecompositionResult(true, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t Matrix::Decomposition::GetComponentsMask() const {
|
||||
uint64_t MatrixDecomposition::GetComponentsMask() const {
|
||||
uint64_t mask = 0;
|
||||
|
||||
Quaternion noRotation(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "impeller/geometry/matrix_decomposition.h"
|
||||
#include "impeller/geometry/point.h"
|
||||
#include "impeller/geometry/quaternion.h"
|
||||
#include "impeller/geometry/scalar.h"
|
||||
@@ -35,28 +37,6 @@ struct Matrix {
|
||||
Vector4 vec[4];
|
||||
};
|
||||
|
||||
struct Decomposition {
|
||||
Vector3 translation;
|
||||
Vector3 scale;
|
||||
Shear shear;
|
||||
Vector4 perspective;
|
||||
Quaternion rotation;
|
||||
|
||||
enum class Component {
|
||||
kTranslation = 1 << 0,
|
||||
kScale = 1 << 1,
|
||||
kShear = 1 << 2,
|
||||
kPerspective = 1 << 3,
|
||||
kRotation = 1 << 4,
|
||||
};
|
||||
|
||||
uint64_t GetComponentsMask() const;
|
||||
};
|
||||
|
||||
// TODO(csg): Radar restrictions of C++11 don't exist. Use optionals instead.
|
||||
using DecompositionResult =
|
||||
std::pair<bool /* success */, Decomposition /* result */>;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Construts a default identity matrix.
|
||||
///
|
||||
@@ -79,7 +59,7 @@ struct Matrix {
|
||||
Vector4(m12, m13, m14, m15)} {}
|
||||
// clang-format on
|
||||
|
||||
Matrix(const Decomposition& decomposition);
|
||||
Matrix(const MatrixDecomposition& decomposition);
|
||||
|
||||
static constexpr Matrix MakeTranslation(const Vector3& t) {
|
||||
// clang-format off
|
||||
@@ -243,7 +223,7 @@ struct Matrix {
|
||||
);
|
||||
}
|
||||
|
||||
DecompositionResult Decompose() const;
|
||||
std::optional<MatrixDecomposition> Decompose() const;
|
||||
|
||||
constexpr bool operator==(const Matrix& m) const {
|
||||
// clang-format off
|
||||
|
||||
11
engine/src/flutter/impeller/geometry/matrix_decomposition.cc
Normal file
11
engine/src/flutter/impeller/geometry/matrix_decomposition.cc
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/geometry/matrix_decomposition.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
|
||||
} // namespace impeller
|
||||
33
engine/src/flutter/impeller/geometry/matrix_decomposition.h
Normal file
33
engine/src/flutter/impeller/geometry/matrix_decomposition.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/geometry/quaternion.h"
|
||||
#include "impeller/geometry/scalar.h"
|
||||
#include "impeller/geometry/shear.h"
|
||||
#include "impeller/geometry/vector.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
struct MatrixDecomposition {
|
||||
Vector3 translation;
|
||||
Vector3 scale;
|
||||
Shear shear;
|
||||
Vector4 perspective;
|
||||
Quaternion rotation;
|
||||
|
||||
enum class Component {
|
||||
kTranslation = 1 << 0,
|
||||
kScale = 1 << 1,
|
||||
kShear = 1 << 2,
|
||||
kPerspective = 1 << 3,
|
||||
kRotation = 1 << 4,
|
||||
};
|
||||
|
||||
uint64_t GetComponentsMask() const;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
Reference in New Issue
Block a user