Skip to content

Commit 6d87108

Browse files
chinmaygardednfield
authored andcommitted
Implement Canvas::Skew.
1 parent 723ca3b commit 6d87108

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

impeller/aiks/aiks_unittests.cc

+12
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,17 @@ TEST_F(AiksTest, CanPerformFullScreenMSAA) {
141141
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
142142
}
143143

144+
TEST_F(AiksTest, CanPerformSkew) {
145+
Canvas canvas;
146+
147+
Paint red;
148+
red.color = Color::Red();
149+
150+
canvas.Skew(10, 125);
151+
canvas.DrawRect(Rect::MakeXYWH(0, 0, 100, 100), red);
152+
153+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
154+
}
155+
144156
} // namespace testing
145157
} // namespace impeller

impeller/aiks/canvas.cc

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ void Canvas::Scale(const Vector3& scale) {
6565
Concat(Matrix::MakeScale(scale));
6666
}
6767

68+
void Canvas::Skew(Scalar sx, Scalar sy) {
69+
Concat(Matrix::MakeSkew(sx, sy));
70+
}
71+
6872
void Canvas::Rotate(Radians radians) {
6973
Concat(Matrix::MakeRotationZ(radians));
7074
}

impeller/aiks/canvas.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Canvas {
4747

4848
void Scale(const Vector3& scale);
4949

50+
void Skew(Scalar sx, Scalar sy);
51+
5052
void Rotate(Radians radians);
5153

5254
void DrawPath(Path path, Paint paint);

impeller/geometry/matrix.h

+21-10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ struct Matrix {
8080
// clang-format on
8181
}
8282

83+
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy) {
84+
// clang-format off
85+
return Matrix(1.0, sy , 0.0, 0.0,
86+
sx , 1.0, 0.0, 0.0,
87+
0.0, 0.0, 1.0, 0.0,
88+
0.0, 0.0, 0.0, 1.0);
89+
// clang-format on
90+
}
91+
8392
static Matrix MakeRotation(Scalar radians, const Vector4& r) {
8493
const Vector4 v = r.Normalize();
8594

@@ -112,8 +121,8 @@ struct Matrix {
112121
}
113122

114123
static Matrix MakeRotationX(Radians r) {
115-
Scalar cosine = cos(r.radians);
116-
Scalar sine = sin(r.radians);
124+
const Scalar cosine = cos(r.radians);
125+
const Scalar sine = sin(r.radians);
117126
// clang-format off
118127
return Matrix(
119128
1.0, 0.0, 0.0, 0.0,
@@ -125,8 +134,8 @@ struct Matrix {
125134
}
126135

127136
static Matrix MakeRotationY(Radians r) {
128-
Scalar cosine = cos(r.radians);
129-
Scalar sine = sin(r.radians);
137+
const Scalar cosine = cos(r.radians);
138+
const Scalar sine = sin(r.radians);
130139

131140
// clang-format off
132141
return Matrix(
@@ -139,8 +148,8 @@ struct Matrix {
139148
}
140149

141150
static Matrix MakeRotationZ(Radians r) {
142-
Scalar cosine = cos(r.radians);
143-
Scalar sine = sin(r.radians);
151+
const Scalar cosine = cos(r.radians);
152+
const Scalar sine = sin(r.radians);
144153

145154
// clang-format off
146155
return Matrix (
@@ -196,12 +205,14 @@ struct Matrix {
196205
}
197206

198207
constexpr Matrix Transpose() const {
208+
// clang-format off
199209
return {
200-
m[0], m[4], m[8], m[12], //
201-
m[1], m[5], m[9], m[13], //
202-
m[2], m[6], m[10], m[14], //
203-
m[3], m[7], m[11], m[15], //
210+
m[0], m[4], m[8], m[12],
211+
m[1], m[5], m[9], m[13],
212+
m[2], m[6], m[10], m[14],
213+
m[3], m[7], m[11], m[15],
204214
};
215+
// clang-format on
205216
}
206217

207218
Matrix Invert() const;

impeller/geometry/shear.cc

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
namespace impeller {
99

10-
std::string Shear::ToString() const {
11-
std::stringstream stream;
12-
stream << "{" << xy << ", " << xz << ", " << yz << "}";
13-
return stream.str();
14-
}
10+
//
1511

1612
} // namespace impeller

impeller/geometry/shear.h

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct Shear {
2727
}
2828

2929
bool operator!=(const Shear& o) const { return !(*this == o); }
30-
31-
std::string ToString() const;
3230
};
3331

3432
} // namespace impeller

impeller/geometry/size.cc

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
#include "size.h"
6-
#include <sstream>
76

87
namespace impeller {
98

0 commit comments

Comments
 (0)