Skip to main content

rust_css_parser/ast/transform/
skew.rs

1//! Port of `src/ast/transform/skew.ts`: `from = from × skew`, angles in radian.
2
3use super::utils::{multiply_in_place, IDENTITY_MATRIX};
4use super::Matrix;
5
6pub fn skew_x(x: f64, from: &mut Matrix) {
7    let mut matrix = IDENTITY_MATRIX;
8    matrix[4] = x.tan();
9    multiply_in_place(from, &matrix);
10}
11
12pub fn skew_y(y: f64, from: &mut Matrix) {
13    let mut matrix = IDENTITY_MATRIX;
14    matrix[1] = y.tan();
15    multiply_in_place(from, &matrix);
16}
17
18/// `y`: ignored if undefined
19pub fn skew(x: f64, y: Option<f64>, from: &mut Matrix) {
20    let mut matrix = IDENTITY_MATRIX;
21    matrix[4] = x.tan();
22    if let Some(y) = y {
23        matrix[1] = y.tan();
24    }
25    multiply_in_place(from, &matrix);
26}