Skip to content

Commit

Permalink
fix: skew transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Nov 16, 2024
1 parent 7bb91e6 commit 795919a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/render/src/operations/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,24 @@ const applySingleTransformation = (ctx, transform, origin) => {
}

case 'skew': {
const [xAngle, yAngle] = value;
ctx.skew(xAngle, yAngle, { origin });
const [xAngle = 0, yAngle = 0] = value;
const radx = (xAngle * Math.PI) / 180;
const rady = (yAngle * Math.PI) / 180;
const tanx = Math.tan(radx);
const tany = Math.tan(rady);

let x = 0;
let y = 0;

if (origin != null) {
[x, y] = Array.from(origin);
const x1 = x + tanx * y;
const y1 = y + tany * x;
x -= x1;
y -= y1;
}

ctx.transform(1, tany, tanx, 1, x, y);
break;
}

Expand Down

0 comments on commit 795919a

Please sign in to comment.