rust_css_parser/ast/transform/perspective.rs
1//! Port of `src/ast/transform/perspective.ts`: `from = from × perspective`.
2
3use super::utils::{multiply_in_place, IDENTITY_MATRIX};
4use super::Matrix;
5
6/// `x`: distance, `None` for `none`
7pub fn perspective(x: Option<f64>, from: &mut Matrix) {
8 let mut matrix = IDENTITY_MATRIX;
9 matrix[11] = match x {
10 None => 0.0,
11 Some(x) if x == 0.0 => f64::NEG_INFINITY,
12 Some(x) => -1.0 / x,
13 };
14 multiply_in_place(from, &matrix);
15}