diff options
| author | Max Pernklau | 2020-11-29 21:28:39 +0100 |
|---|---|---|
| committer | GitHub | 2020-11-29 21:28:39 +0100 |
| commit | 4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87 (patch) | |
| tree | 010339f867d90c2c6293ddd16c4151ec220c7b8e /src/tool/polygon_room_tool.rs | |
| parent | 4d3ee44eb4892bd454a1289f7fed308f82ec6a3b (diff) | |
| parent | 90db142588e1b78250dc9b266bae359cf9e22721 (diff) | |
| download | graf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.tar.gz graf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.zip | |
Merge branch 'master' into wall-join
Diffstat (limited to 'src/tool/polygon_room_tool.rs')
| -rw-r--r-- | src/tool/polygon_room_tool.rs | 52 |
1 files changed, 26 insertions, 26 deletions
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, |
