bottomless_pit/
matrix_math.rs

1//! contains several functions that help with doing matrix arithmetic
2use crate::vectors::Vec2;
3
4/// Helper function to normalize 2D points
5pub fn normalize_points<T: std::ops::Div<Output = T>>(point: Vec2<T>, size: Vec2<T>) -> Vec2<T> {
6    let x = point.x / size.x;
7    let y = point.y / size.y;
8    Vec2 { x, y }
9}
10
11/// Helper function that turns pixels into wgsl screen space
12pub fn pixels_to_screenspace(mut point: Vec2<f32>, screen_size: Vec2<u32>) -> Vec2<f32> {
13    let width = screen_size.x as f32;
14    let height = screen_size.y as f32;
15    point.x = (2.0 * point.x / width) - 1.0;
16    point.y = ((2.0 * point.y / height) - 1.0) * -1.0;
17
18    point
19}