diff options
| author | Arne Dußin | 2020-11-27 22:55:00 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-27 22:55:00 +0100 |
| commit | 4c4b57dc24bc36b3091931c9dcc36f6b1894a017 (patch) | |
| tree | 83f835eb850f249eff2e7694707464c9d4713a69 /src/tool | |
| parent | 99e935b63bb023cfd46c8f3d81074d3faf7ce592 (diff) | |
| download | graf_karto-4c4b57dc24bc36b3091931c9dcc36f6b1894a017.tar.gz graf_karto-4c4b57dc24bc36b3091931c9dcc36f6b1894a017.zip | |
Change to f64 as the preferred floating point number
Diffstat (limited to 'src/tool')
| -rw-r--r-- | src/tool/deletion_tool.rs | 8 | ||||
| -rw-r--r-- | src/tool/icon_tool.rs | 30 | ||||
| -rw-r--r-- | src/tool/polygon_room_tool.rs | 52 | ||||
| -rw-r--r-- | src/tool/room_tool.rs | 8 | ||||
| -rw-r--r-- | src/tool/wall_tool.rs | 16 |
5 files changed, 57 insertions, 57 deletions
diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs index 17dd949..74a8f92 100644 --- a/src/tool/deletion_tool.rs +++ b/src/tool/deletion_tool.rs @@ -10,7 +10,7 @@ use raylib::RaylibHandle; pub struct DeletionTool { keybindings: DeletionToolKeybindings, - deletion_rect: Option<(Vec2<f32>, Vec2<f32>)>, + deletion_rect: Option<(Vec2<f64>, Vec2<f64>)>, } impl DeletionTool { @@ -22,7 +22,7 @@ impl DeletionTool { } /// Delete all map-data that is contained inside the provided rectangular space. - pub fn delete_rect(map_data: &mut MapData, rect: Rect<f32>) { + pub fn delete_rect(map_data: &mut MapData, rect: Rect<f64>) { map_data .rooms_mut() .retain(|&room| !rect.contains_rect(&room)); @@ -50,7 +50,7 @@ impl Tool for DeletionTool { transform: &Transform, mouse_blocked: bool, ) { - let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); + let mouse_pos_m = transform.point_px_to_m(&rl.get_mouse_position().into()); if let Some((_, ref mut pos2)) = &mut self.deletion_rect { *pos2 = mouse_pos_m; } @@ -72,7 +72,7 @@ impl Tool for DeletionTool { fn draw(&self, _map_data: &MapData, rld: &mut RaylibDrawHandle, transform: &Transform) { if let Some((pos1, pos2)) = self.deletion_rect { - let rect_px = transform.rect_m_to_px(Rect::bounding_rect(pos1, pos2)); + let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2)); rld.draw_rectangle_rec( rect_px, Color { diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs index 4b3a1eb..e972c1c 100644 --- a/src/tool/icon_tool.rs +++ b/src/tool/icon_tool.rs @@ -19,9 +19,9 @@ pub const ICON_DIR: &str = "assets/icons"; struct IconFileInfo { /// The position the icon should be anchored in pixels. This is the Vector it will be moved by /// relative to the mouse pointer (to the left and up). - anchor: Vec2<f32>, + anchor: Vec2<f64>, /// The scale of the icon as expressed in image pixels per real meter. - pixels_per_m: f32, + pixels_per_m: f64, } #[derive(Clone, Serialize, Deserialize)] @@ -29,9 +29,9 @@ pub struct IconInfo { /// The id of the icon is the icons position in the currently loaded icon_data vector. pub icon_id: usize, /// The position of the icon on the map, given by the vector in meters. - pub position: Vec2<f32>, + pub position: Vec2<f64>, /// Rotation of the icon texture in degrees. - pub rotation: f32, + pub rotation: f64, } pub struct IconTool { @@ -132,7 +132,7 @@ impl Tool for IconTool { ) { // Update the position of the icon that should be drawn to the current mouse position. let snapped_mouse_pos_m = snap_to_grid( - transform.point_px_to_m(rl.get_mouse_position().into()), + transform.point_px_to_m(&rl.get_mouse_position().into()), SNAP_SIZE, ); self.current_icon.position = snapped_mouse_pos_m; @@ -161,14 +161,14 @@ impl Tool for IconTool { let (texture, info) = &self.icon_data[icon.icon_id]; // Round the position to whole pixels to fix rotation problems. let mut position_px = - transform.point_m_to_px(icon.position - (info.anchor / info.pixels_per_m)); - position_px.x = position_px.x as i32 as f32; - position_px.y = position_px.y as i32 as f32; + transform.point_m_to_px(&(icon.position - (info.anchor / info.pixels_per_m))); + position_px.x = position_px.x.floor(); + position_px.y = position_px.y.floor(); rld.draw_texture_ex( texture, position_px, - icon.rotation, - transform.pixels_per_m() / info.pixels_per_m, + icon.rotation as f32, + (transform.pixels_per_m() / info.pixels_per_m) as f32, Color { r: 255, g: 255, @@ -183,14 +183,14 @@ impl Tool for IconTool { let (texture, info) = &self.icon_data[self.current_icon.icon_id]; // Round the position to whole pixels to fix rotation problems. let mut position_px = transform - .point_m_to_px(self.current_icon.position - (info.anchor / info.pixels_per_m)); - position_px.x = position_px.x as i32 as f32; - position_px.y = position_px.y as i32 as f32; + .point_m_to_px(&(self.current_icon.position - (info.anchor / info.pixels_per_m))); + position_px.x = position_px.x.floor(); + position_px.y = position_px.y.floor(); rld.draw_texture_ex( texture, position_px, - self.current_icon.rotation, - transform.pixels_per_m() / info.pixels_per_m, + self.current_icon.rotation as f32, + (transform.pixels_per_m() / info.pixels_per_m) as f32, Color { r: 120, g: 200, diff --git a/src/tool/polygon_room_tool.rs b/src/tool/polygon_room_tool.rs index 42874e8..8cd2c25 100644 --- a/src/tool/polygon_room_tool.rs +++ b/src/tool/polygon_room_tool.rs @@ -11,8 +11,8 @@ use raylib::ffi::Color; use raylib::RaylibHandle; struct UnfinishedPolygon { - pub corners: Vec<Vec2<f32>>, - pub working_corner: Vec2<f32>, + pub corners: Vec<Vec2<f64>>, + pub working_corner: Vec2<f64>, } pub struct PolygonRoomTool { @@ -23,13 +23,13 @@ pub struct PolygonRoomTool { impl UnfinishedPolygon { // Check the validity of the already completed corners only - pub fn check_validity_completed(&self) -> Result<(), PolygonError<f32>> { + pub fn check_validity_completed(&self) -> Result<(), PolygonError<f64>> { Polygon::check_validity(&self.corners) } // Check the validity of the already completed corners, but with the working corner wedged // between the last and first corner (making it the new last corner). - pub fn check_validity_all(&self) -> Result<(), PolygonError<f32>> { + pub fn check_validity_all(&self) -> Result<(), PolygonError<f64>> { // TODO: Is this possible without changing the mutability of self and without reallocation? let mut corners = self.corners.clone(); corners.push(self.working_corner); @@ -37,7 +37,7 @@ impl UnfinishedPolygon { Polygon::check_validity(&corners) } - pub fn try_into_completed(&mut self) -> Option<Polygon<f32>> { + pub fn try_into_completed(&mut self) -> Option<Polygon<f64>> { match self.check_validity_completed() { Ok(()) => Some(Polygon::new_unchecked(self.corners.drain(..).collect())), Err(e) => { @@ -47,7 +47,7 @@ impl UnfinishedPolygon { } } - pub fn try_into_all(&mut self) -> Option<Polygon<f32>> { + pub fn try_into_all(&mut self) -> Option<Polygon<f64>> { match self.check_validity_all() { Ok(()) => { self.corners.push(self.working_corner); @@ -63,7 +63,7 @@ impl UnfinishedPolygon { } } - pub fn try_push_working(&mut self) -> Result<(), PolygonError<f32>> { + pub fn try_push_working(&mut self) -> Result<(), PolygonError<f64>> { assert!(!self.corners.is_empty()); if self.corners.len() == 1 { @@ -106,7 +106,7 @@ impl Tool for PolygonRoomTool { transform: &Transform, mouse_blocked: bool, ) { - let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); + let mouse_pos_m = transform.point_px_to_m(&rl.get_mouse_position().into()); let snapped_mouse_pos_m = snap_to_grid(mouse_pos_m, SNAP_SIZE); // Update the position of the node that would be placed into the polygon next. @@ -170,11 +170,11 @@ impl Tool for PolygonRoomTool { for polygon in map.polygons() { let triangles = math::triangulate(polygon.clone()); for triangle in triangles { - let triangle: [Vec2<f32>; 3] = triangle.into(); + let triangle: [Vec2<f64>; 3] = triangle.into(); rld.draw_triangle( - transform.point_m_to_px(triangle[0]), - transform.point_m_to_px(triangle[1]), - transform.point_m_to_px(triangle[2]), + transform.point_m_to_px(&triangle[0]), + transform.point_m_to_px(&triangle[1]), + transform.point_m_to_px(&triangle[2]), Color { r: 180, g: 180, @@ -189,9 +189,9 @@ impl Tool for PolygonRoomTool { // The first corner is guaranteed to be set, so we can at least draw a line. if polygon.corners.len() == 1 { rld.draw_line_ex( - transform.point_m_to_px(polygon.corners[0]), - transform.point_m_to_px(polygon.working_corner), - transform.length_m_to_px(0.1), + transform.point_m_to_px(&polygon.corners[0]), + transform.point_m_to_px(&polygon.working_corner), + transform.length_m_to_px(0.1) as f32, Color { r: 150, g: 200, @@ -202,9 +202,9 @@ impl Tool for PolygonRoomTool { } else if polygon.corners.len() == 2 { // We have three valid corners, so we can draw a triangle. rld.draw_triangle( - transform.point_m_to_px(polygon.corners[0]), - transform.point_m_to_px(polygon.corners[1]), - transform.point_m_to_px(polygon.working_corner), + transform.point_m_to_px(&polygon.corners[0]), + transform.point_m_to_px(&polygon.corners[1]), + transform.point_m_to_px(&polygon.working_corner), Color { r: 150, g: 200, @@ -220,11 +220,11 @@ impl Tool for PolygonRoomTool { let polygon = Polygon::new_unchecked(corners); let triangles = math::triangulate(polygon); for triangle in triangles { - let triangle: [Vec2<f32>; 3] = triangle.into(); + let triangle: [Vec2<f64>; 3] = triangle.into(); rld.draw_triangle( - transform.point_m_to_px(triangle[0]), - transform.point_m_to_px(triangle[1]), - transform.point_m_to_px(triangle[2]), + transform.point_m_to_px(&triangle[0]), + transform.point_m_to_px(&triangle[1]), + transform.point_m_to_px(&triangle[2]), Color { r: 150, g: 200, @@ -237,11 +237,11 @@ impl Tool for PolygonRoomTool { let polygon = Polygon::new_unchecked(polygon.corners.clone()); let triangles = math::triangulate(polygon); for triangle in triangles { - let triangle: [Vec2<f32>; 3] = triangle.into(); + let triangle: [Vec2<f64>; 3] = triangle.into(); rld.draw_triangle( - transform.point_m_to_px(triangle[0]), - transform.point_m_to_px(triangle[1]), - transform.point_m_to_px(triangle[2]), + transform.point_m_to_px(&triangle[0]), + transform.point_m_to_px(&triangle[1]), + transform.point_m_to_px(&triangle[2]), Color { r: 150, g: 200, diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index c4a8b8c..6a283e3 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -14,7 +14,7 @@ pub struct RoomTool { keybindings: RoomToolKeybindings, /// The rectangle that is currently being drawn by the user. Once it is finished, it will be /// pushed into the room_rects. - unfinished_rect: Option<(Vec2<f32>, Vec2<f32>)>, + unfinished_rect: Option<(Vec2<f64>, Vec2<f64>)>, dimension_indicator: DimensionIndicator, } @@ -42,7 +42,7 @@ impl Tool for RoomTool { transform: &Transform, mouse_blocked: bool, ) { - let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); + let mouse_pos_m = transform.point_px_to_m(&rl.get_mouse_position().into()); // Update the currently drawn rectangle, if it exists, and also its dimension indicator. if let Some((ref pos1, ref mut pos2)) = &mut self.unfinished_rect { *pos2 = snap_to_grid(mouse_pos_m, SNAP_SIZE); @@ -71,7 +71,7 @@ impl Tool for RoomTool { // Draw all finished rectangles. for &rect in map_data.rooms() { rld.draw_rectangle_rec( - transform.rect_m_to_px(rect), + transform.rect_m_to_px(&rect), Color { r: 180, g: 180, @@ -84,7 +84,7 @@ impl Tool for RoomTool { // Do the same for the unfinished rectangle if let Some((pos1, pos2)) = self.unfinished_rect { rld.draw_rectangle_rec( - transform.rect_m_to_px(Rect::bounding_rect(pos1, pos2)), + transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2)), Color { r: 150, g: 200, diff --git a/src/tool/wall_tool.rs b/src/tool/wall_tool.rs index 2cc5b5d..e6503ba 100644 --- a/src/tool/wall_tool.rs +++ b/src/tool/wall_tool.rs @@ -11,7 +11,7 @@ use raylib::RaylibHandle; pub struct WallTool { keybindings: WallToolKeybindings, - unfinished_wall: Option<(Vec2<f32>, Vec2<f32>)>, + unfinished_wall: Option<(Vec2<f64>, Vec2<f64>)>, } impl WallTool { @@ -35,7 +35,7 @@ impl Tool for WallTool { transform: &Transform, mouse_blocked: bool, ) { - let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); + let mouse_pos_m = transform.point_px_to_m(&rl.get_mouse_position().into()); if let Some((_, ref mut pos2)) = &mut self.unfinished_wall { *pos2 = snap_to_grid(mouse_pos_m, SNAP_SIZE); } @@ -61,12 +61,12 @@ impl Tool for WallTool { fn draw(&self, map_data: &MapData, rld: &mut RaylibDrawHandle, transform: &Transform) { for &(pos1, pos2) in map_data.walls() { - let pos1: Vector2 = transform.point_m_to_px(pos1).into(); - let pos2: Vector2 = transform.point_m_to_px(pos2).into(); + let pos1: Vector2 = transform.point_m_to_px(&pos1).into(); + let pos2: Vector2 = transform.point_m_to_px(&pos2).into(); rld.draw_line_ex( pos1, pos2, - transform.length_m_to_px(0.1), + transform.length_m_to_px(0.1) as f32, Color { r: 200, g: 120, @@ -77,12 +77,12 @@ impl Tool for WallTool { } if let Some((pos1, pos2)) = self.unfinished_wall { - let pos1: Vector2 = transform.point_m_to_px(pos1).into(); - let pos2: Vector2 = transform.point_m_to_px(pos2).into(); + let pos1: Vector2 = transform.point_m_to_px(&pos1).into(); + let pos2: Vector2 = transform.point_m_to_px(&pos2).into(); rld.draw_line_ex( pos1, pos2, - transform.length_m_to_px(0.1), + transform.length_m_to_px(0.1) as f32, Color { r: 150, g: 200, |
