expression
Map normalized coordinates into a viewport
Normalized device coordinates (NDC) describe a post-projection coordinate space. In this illustrative viewport, x and y range from -1 to 1, with y up; screen coordinates use a top-left origin and y down. The mapping returns continuous viewport edges, not pixel indices. Clipping and perspective division must occur earlier in a real pipeline; depth conventions vary by graphics API. Expected result (NOT RUN): 600, 150 Common mistake: Forgetting the y-axis convention or treating the right/bottom viewport edge as an in-bounds pixel index. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
screen_x = (ndc_x+1)*width/2; screen_y = (1-ndc_y)*height/2Working Example
Example Snippetrust
fn screen(x: f64, y: f64, width: f64, height: f64) -> [f64; 2] { [(x+1.0)*width/2.0, (1.0-y)*height/2.0]}fn main() { let [x, y] = screen(0.5, 0.5, 800.0, 600.0); println!("{x:.0}, {y:.0}");}