From e85fee46ebf87a1e41732994cc956c077d1f33a4 Mon Sep 17 00:00:00 2001 From: bronku Date: Sun, 15 Feb 2026 23:08:21 +0100 Subject: [PATCH] Update main.rs --- src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 94dfd75..3a5d68d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,16 +8,18 @@ struct Vec2 { y: f32, } -fn convert_coordinates(pos: Vec2) -> (i32, i32) { - return ( - ((WINDOW_WIDTH as f32) * ((pos.x + 1.0) / 2.0)) as i32, - ((WINDOW_HEIGHT as f32) * ((pos.y + 1.0) / 2.0)) as i32, - ); +impl Vec2 { + fn to_screen_space(self) -> (i32, i32) { + return ( + ((WINDOW_WIDTH as f32) * ((self.x + 1.0) / 2.0)) as i32, + ((WINDOW_HEIGHT as f32) * ((self.y + 1.0) / 2.0)) as i32, + ); + } } fn draw_point(d: &mut RaylibDrawHandle, pos: Vec2) { const POINT_SIZE: i32 = 3; - let (window_x, window_y) = convert_coordinates(pos); + let (window_x, window_y) = pos.to_screen_space(); d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED); }