Function to_ndc

Source
pub fn to_ndc(w: f32, h: f32, x: f32, y: f32) -> [f32; 2]
Expand description

Converts top-left-origin physical pixels to wgpu normalized device coordinates.

(0, 0) maps to (-1, 1) and (w, h) maps to (1, -1). Zero dimensions produce IEEE infinities or NaN rather than being clamped.

ยงExamples

use ailloli_ui_render_wgpu::passes::to_ndc;
assert_eq!(to_ndc(100.0, 50.0, 0.0, 0.0), [-1.0, 1.0]);
assert_eq!(to_ndc(100.0, 50.0, 100.0, 50.0), [1.0, -1.0]);