++ (flutter/engine#39617)
This commit is contained in:
@@ -404,6 +404,52 @@ TEST_P(EntityTest, CubicCurveTest) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(entity));
|
||||
}
|
||||
|
||||
TEST_P(EntityTest, CanDrawCorrectlyWithRotatedTransformation) {
|
||||
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
|
||||
const char* input_axis[] = {"X", "Y", "Z"};
|
||||
static int rotation_axis_index = 0;
|
||||
static float rotation = 0;
|
||||
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::SliderFloat("Rotation", &rotation, -kPi, kPi);
|
||||
ImGui::Combo("Rotation Axis", &rotation_axis_index, input_axis,
|
||||
sizeof(input_axis) / sizeof(char*));
|
||||
Matrix rotation_matrix;
|
||||
switch (rotation_axis_index) {
|
||||
case 0:
|
||||
rotation_matrix = Matrix::MakeRotationX(Radians(rotation));
|
||||
break;
|
||||
case 1:
|
||||
rotation_matrix = Matrix::MakeRotationY(Radians(rotation));
|
||||
break;
|
||||
case 2:
|
||||
rotation_matrix = Matrix::MakeRotationZ(Radians(rotation));
|
||||
break;
|
||||
default:
|
||||
rotation_matrix = Matrix{};
|
||||
break;
|
||||
}
|
||||
|
||||
if (ImGui::Button("Reset")) {
|
||||
rotation = 0;
|
||||
}
|
||||
ImGui::End();
|
||||
Matrix current_transform =
|
||||
Matrix::MakeScale(GetContentScale())
|
||||
.MakeTranslation(
|
||||
Vector3(Point(pass.GetRenderTargetSize().width / 2.0,
|
||||
pass.GetRenderTargetSize().height / 2.0)));
|
||||
Matrix result_transform = current_transform * rotation_matrix;
|
||||
Path path =
|
||||
PathBuilder{}.AddRect(Rect::MakeXYWH(-300, -400, 600, 800)).TakePath();
|
||||
|
||||
Entity entity;
|
||||
entity.SetTransformation(result_transform);
|
||||
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
|
||||
return entity.Render(context, pass);
|
||||
};
|
||||
ASSERT_TRUE(OpenPlaygroundHere(callback));
|
||||
}
|
||||
|
||||
TEST_P(EntityTest, CubicCurveAndOverlapTest) {
|
||||
// Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06
|
||||
Path path =
|
||||
|
||||
@@ -341,7 +341,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
|
||||
auto expect = Matrix{
|
||||
0.02, 0, 0, 0, //
|
||||
0, -0.01, 0, 0, //
|
||||
0, 0, 1, 0, //
|
||||
0, 0, 0, 0, //
|
||||
-1, 1, 0.5, 1, //
|
||||
};
|
||||
ASSERT_MATRIX_NEAR(m, expect);
|
||||
@@ -352,7 +352,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
|
||||
auto expect = Matrix{
|
||||
0.005, 0, 0, 0, //
|
||||
0, -0.02, 0, 0, //
|
||||
0, 0, 1, 0, //
|
||||
0, 0, 0, 0, //
|
||||
-1, 1, 0.5, 1, //
|
||||
};
|
||||
ASSERT_MATRIX_NEAR(m, expect);
|
||||
|
||||
@@ -443,7 +443,7 @@ struct Matrix {
|
||||
// Per assumptions about NDC documented above.
|
||||
const auto scale =
|
||||
MakeScale({2.0f / static_cast<Scalar>(size.width),
|
||||
-2.0f / static_cast<Scalar>(size.height), 1.0});
|
||||
-2.0f / static_cast<Scalar>(size.height), 0.0});
|
||||
const auto translate = MakeTranslation({-1.0, 1.0, 0.5});
|
||||
return translate * scale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user