Skip to content

Commit

Permalink
Implement Canvas::Skew.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 723ca3b commit 6d87108
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
12 changes: 12 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,17 @@ TEST_F(AiksTest, CanPerformFullScreenMSAA) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_F(AiksTest, CanPerformSkew) {
Canvas canvas;

Paint red;
red.color = Color::Red();

canvas.Skew(10, 125);
canvas.DrawRect(Rect::MakeXYWH(0, 0, 100, 100), red);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller
4 changes: 4 additions & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ void Canvas::Scale(const Vector3& scale) {
Concat(Matrix::MakeScale(scale));
}

void Canvas::Skew(Scalar sx, Scalar sy) {
Concat(Matrix::MakeSkew(sx, sy));
}

void Canvas::Rotate(Radians radians) {
Concat(Matrix::MakeRotationZ(radians));
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Canvas {

void Scale(const Vector3& scale);

void Skew(Scalar sx, Scalar sy);

void Rotate(Radians radians);

void DrawPath(Path path, Paint paint);
Expand Down
31 changes: 21 additions & 10 deletions impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ struct Matrix {
// clang-format on
}

static constexpr Matrix MakeSkew(Scalar sx, Scalar sy) {
// clang-format off
return Matrix(1.0, sy , 0.0, 0.0,
sx , 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
// clang-format on
}

static Matrix MakeRotation(Scalar radians, const Vector4& r) {
const Vector4 v = r.Normalize();

Expand Down Expand Up @@ -112,8 +121,8 @@ struct Matrix {
}

static Matrix MakeRotationX(Radians r) {
Scalar cosine = cos(r.radians);
Scalar sine = sin(r.radians);
const Scalar cosine = cos(r.radians);
const Scalar sine = sin(r.radians);
// clang-format off
return Matrix(
1.0, 0.0, 0.0, 0.0,
Expand All @@ -125,8 +134,8 @@ struct Matrix {
}

static Matrix MakeRotationY(Radians r) {
Scalar cosine = cos(r.radians);
Scalar sine = sin(r.radians);
const Scalar cosine = cos(r.radians);
const Scalar sine = sin(r.radians);

// clang-format off
return Matrix(
Expand All @@ -139,8 +148,8 @@ struct Matrix {
}

static Matrix MakeRotationZ(Radians r) {
Scalar cosine = cos(r.radians);
Scalar sine = sin(r.radians);
const Scalar cosine = cos(r.radians);
const Scalar sine = sin(r.radians);

// clang-format off
return Matrix (
Expand Down Expand Up @@ -196,12 +205,14 @@ struct Matrix {
}

constexpr Matrix Transpose() const {
// clang-format off
return {
m[0], m[4], m[8], m[12], //
m[1], m[5], m[9], m[13], //
m[2], m[6], m[10], m[14], //
m[3], m[7], m[11], m[15], //
m[0], m[4], m[8], m[12],
m[1], m[5], m[9], m[13],
m[2], m[6], m[10], m[14],
m[3], m[7], m[11], m[15],
};
// clang-format on
}

Matrix Invert() const;
Expand Down
6 changes: 1 addition & 5 deletions impeller/geometry/shear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

namespace impeller {

std::string Shear::ToString() const {
std::stringstream stream;
stream << "{" << xy << ", " << xz << ", " << yz << "}";
return stream.str();
}
//

} // namespace impeller
2 changes: 0 additions & 2 deletions impeller/geometry/shear.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ struct Shear {
}

bool operator!=(const Shear& o) const { return !(*this == o); }

std::string ToString() const;
};

} // namespace impeller
1 change: 0 additions & 1 deletion impeller/geometry/size.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

#include "size.h"
#include <sstream>

namespace impeller {

Expand Down

0 comments on commit 6d87108

Please sign in to comment.