diff options
| -rw-r--r-- | src/dimension_indicator.rs | 7 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/map_data.rs | 1 | ||||
| -rw-r--r-- | src/math/vec2.rs | 16 | ||||
| -rw-r--r-- | src/tool/icon_tool.rs | 2 | ||||
| -rw-r--r-- | src/transform.rs | 6 |
6 files changed, 28 insertions, 6 deletions
diff --git a/src/dimension_indicator.rs b/src/dimension_indicator.rs index a08d22c..0ea96d3 100644 --- a/src/dimension_indicator.rs +++ b/src/dimension_indicator.rs @@ -10,13 +10,14 @@ pub struct DimensionIndicator { } impl DimensionIndicator { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self { length_lines: Vec::new(), } } - pub fn from_corner_points(corner_points: &Vec<Vec2<f32>>) -> Self { + pub fn from_corner_points(corner_points: &[Vec2<f32>]) -> Self { let mut this = Self::new(); this.update_dimensions(corner_points); @@ -76,7 +77,7 @@ impl DimensionIndicator { // Start with the direction of the line vector. let dir = *start - *end; // Calculate perpendicular vec and normalise. - dir.rotated_90_clockwise() / dir.len() + dir.rotated_90_clockwise() / dir.length() }; // To not have the line directly in the rect, move start and end outside a bit. @@ -112,7 +113,7 @@ impl DimensionIndicator { */ let text_pos = transform.point_m_to_px((*end + *start) / 2.) + line_normal * 20.; rld.draw_text( - &format!("{}m", &(*end - *start).len()), + &format!("{}m", &(*end - *start).length()), text_pos.x as i32, text_pos.y as i32, 20, diff --git a/src/main.rs b/src/main.rs index e40a40e..8e3bf51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + #[macro_use] extern crate log; diff --git a/src/map_data.rs b/src/map_data.rs index 8d0d926..e1a9c0b 100644 --- a/src/map_data.rs +++ b/src/map_data.rs @@ -18,6 +18,7 @@ pub struct MapData { } impl MapData { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self { rooms: Vec::new(), diff --git a/src/math/vec2.rs b/src/math/vec2.rs index 7834ffc..2b33f7b 100644 --- a/src/math/vec2.rs +++ b/src/math/vec2.rs @@ -8,7 +8,7 @@ use std::convert::{From, Into}; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; use std::{fmt, mem}; -#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq)] pub struct Vec2<T: Scalar + Copy> { pub x: T, pub y: T, @@ -19,7 +19,7 @@ impl<T: Scalar + Copy> Vec2<T> { Self { x, y } } - pub fn len(&self) -> T + pub fn length(&self) -> T where T: RealField, { @@ -202,6 +202,18 @@ impl<T: Scalar + Div<Output = T> + Copy> Div<T> for Vec2<T> { // By default, the coordinates are first compared by their y-coordinates, then // their x-coordinates +impl<T: fmt::Debug> PartialOrd for Vec2<T> +where + T: PartialOrd + Copy + 'static, +{ + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + match self.y.partial_cmp(&other.y) { + Some(Ordering::Equal) | None => self.x.partial_cmp(&other.x), + y_order => y_order, + } + } +} + impl<T: fmt::Debug> Ord for Vec2<T> where T: Ord + Copy + 'static, diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs index 824162f..702c30e 100644 --- a/src/tool/icon_tool.rs +++ b/src/tool/icon_tool.rs @@ -13,7 +13,7 @@ use ron::de::from_reader; use serde::{Deserialize, Serialize}; use std::fs::{self, File}; -pub const ICON_DIR: &'static str = "assets/icons"; +pub const ICON_DIR: &str = "assets/icons"; #[derive(Deserialize)] struct IconFileInfo { diff --git a/src/transform.rs b/src/transform.rs index 2e9ea0b..bd80bc1 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -126,3 +126,9 @@ impl Transform { self.translation_px } } + +impl Default for Transform { + fn default() -> Self { + Self::new() + } +} |
