Skip to main content

rust_css_parser/ast/transform/
scale.rs

1//! Port of `src/ast/transform/scale.ts`: `from = from × scale`.
2
3use super::utils::{multiply_in_place, IDENTITY_MATRIX};
4use super::Matrix;
5
6fn apply(from: &mut Matrix, x: f64, y: f64, z: f64) {
7    let mut matrix = IDENTITY_MATRIX;
8    matrix[0] = x;
9    matrix[5] = y;
10    matrix[10] = z;
11    multiply_in_place(from, &matrix);
12}
13
14pub fn scale_x(x: f64, from: &mut Matrix) {
15    apply(from, x, 1.0, 1.0);
16}
17
18pub fn scale_y(y: f64, from: &mut Matrix) {
19    apply(from, 1.0, y, 1.0);
20}
21
22pub fn scale_z(z: f64, from: &mut Matrix) {
23    apply(from, 1.0, 1.0, z);
24}
25
26pub fn scale(x: f64, y: f64, from: &mut Matrix) {
27    apply(from, x, y, 1.0);
28}
29
30pub fn scale3d(x: f64, y: f64, z: f64, from: &mut Matrix) {
31    apply(from, x, y, z);
32}