Skip to content

Commit

Permalink
fix: transform matrix config
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed Jan 19, 2021
1 parent cb2561a commit 9dcddf2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion __test__/draw.spec.ts
Expand Up @@ -411,7 +411,21 @@ test('rect', async (t) => {
await snapshotImage(t)
})

test.todo('resetTransform')
test('resetTransform', async (t) => {
const { ctx } = t.context
// Skewed rects
ctx.transform(1, 0, 1.7, 1, 0, 0)
ctx.fillStyle = 'gray'
ctx.fillRect(40, 40, 50, 20)
ctx.fillRect(40, 90, 50, 20)

// Non-skewed rects
ctx.resetTransform()
ctx.fillStyle = 'red'
ctx.fillRect(40, 40, 50, 20)
ctx.fillRect(40, 90, 50, 20)
await snapshotImage(t)
})

test('save-restore', async (t) => {
const { ctx } = t.context
Expand Down
Binary file added __test__/snapshots/resetTransform.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/sk.rs
Expand Up @@ -1924,13 +1924,13 @@ impl Transform {
}

#[inline]
/// | A B C |
/// | D E F |
/// | A C E |
/// | B D F |
/// | 0 0 1 |
/// [interface.js](skia/modules/canvaskit/interface.js)
pub fn invert(&self) -> Option<Self> {
let m = [
self.a, self.b, self.c, self.d, self.e, self.f, 0f32, 0f32, 1f32,
self.a, self.c, self.e, self.b, self.d, self.f, 0f32, 0f32, 1f32,
];
// Find the determinant by the sarrus rule. https://en.wikipedia.org/wiki/Rule_of_Sarrus
let det = m[0] * m[4] * m[8] + m[1] * m[5] * m[6] + m[2] * m[3] * m[7]
Expand Down

0 comments on commit 9dcddf2

Please sign in to comment.