Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b1b9df

Browse files
bderodnfield
authored andcommitted
Apply Aiks transforms in the canvas space, not world space (#91)
1 parent 1d6dc1e commit 5b1b9df

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ TEST_F(AiksTest, ClipsUseCurrentTransform) {
132132

133133
canvas.Translate(Vector3(300, 300));
134134
for (int i = 0; i < 15; i++) {
135-
canvas.Translate(-Vector3(300, 300));
136135
canvas.Scale(Vector3(0.8, 0.8));
137-
canvas.Translate(Vector3(300, 300));
138136

139137
paint.color = colors[i % colors.size()];
140138
canvas.ClipPath(PathBuilder{}.AddCircle({0, 0}, 300).TakePath());
@@ -202,7 +200,7 @@ TEST_F(AiksTest, CanPerformSkew) {
202200
Paint red;
203201
red.color = Color::Red();
204202

205-
canvas.Skew(10, 125);
203+
canvas.Skew(2, 5);
206204
canvas.DrawRect(Rect::MakeXYWH(0, 0, 100, 100), red);
207205

208206
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
@@ -417,5 +415,43 @@ TEST_F(AiksTest, PaintBlendModeIsRespected) {
417415
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
418416
}
419417

418+
TEST_F(AiksTest, TransformMultipliesCorrectly) {
419+
Canvas canvas;
420+
ASSERT_MATRIX_NEAR(canvas.GetCurrentTransformation(), Matrix());
421+
422+
// clang-format off
423+
canvas.Translate(Vector3(100, 200));
424+
ASSERT_MATRIX_NEAR(
425+
canvas.GetCurrentTransformation(),
426+
Matrix( 1, 0, 0, 0,
427+
0, 1, 0, 0,
428+
0, 0, 1, 0,
429+
100, 200, 0, 1));
430+
431+
canvas.Rotate(Radians(kPiOver2));
432+
ASSERT_MATRIX_NEAR(
433+
canvas.GetCurrentTransformation(),
434+
Matrix( 0, 1, 0, 0,
435+
-1, 0, 0, 0,
436+
0, 0, 1, 0,
437+
100, 200, 0, 1));
438+
439+
canvas.Scale(Vector3(2, 3));
440+
ASSERT_MATRIX_NEAR(
441+
canvas.GetCurrentTransformation(),
442+
Matrix( 0, 2, 0, 0,
443+
-3, 0, 0, 0,
444+
0, 0, 0, 0,
445+
100, 200, 0, 1));
446+
447+
canvas.Translate(Vector3(100, 200));
448+
ASSERT_MATRIX_NEAR(
449+
canvas.GetCurrentTransformation(),
450+
Matrix( 0, 2, 0, 0,
451+
-3, 0, 0, 0,
452+
0, 0, 0, 0,
453+
-500, 400, 0, 1));
454+
}
455+
420456
} // namespace testing
421457
} // namespace impeller

impeller/aiks/canvas.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool Canvas::Restore() {
6161
}
6262

6363
void Canvas::Concat(const Matrix& xformation) {
64-
xformation_stack_.back().xformation = xformation * GetCurrentTransformation();
64+
xformation_stack_.back().xformation = GetCurrentTransformation() * xformation;
6565
}
6666

6767
void Canvas::ResetTransform() {

0 commit comments

Comments
 (0)