From 94b9d39bd32ced4435951dc7a61612c3ea826b87 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Tue, 10 Nov 2020 19:14:53 +0100 Subject: Fix some style errors Fixed the last warnings and ran clippy on the project. Fixed where appropriate and taught clippy otherwise. Now runs through clean. --- src/dimension_indicator.rs | 7 ++++--- src/main.rs | 2 ++ src/map_data.rs | 1 + src/math/vec2.rs | 16 ++++++++++++++-- src/tool/icon_tool.rs | 2 +- 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>) -> Self { + pub fn from_corner_points(corner_points: &[Vec2]) -> 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 { pub x: T, pub y: T, @@ -19,7 +19,7 @@ impl Vec2 { Self { x, y } } - pub fn len(&self) -> T + pub fn length(&self) -> T where T: RealField, { @@ -202,6 +202,18 @@ impl + Copy> Div for Vec2 { // By default, the coordinates are first compared by their y-coordinates, then // their x-coordinates +impl PartialOrd for Vec2 +where + T: PartialOrd + Copy + 'static, +{ + fn partial_cmp(&self, other: &Self) -> Option { + match self.y.partial_cmp(&other.y) { + Some(Ordering::Equal) | None => self.x.partial_cmp(&other.x), + y_order => y_order, + } + } +} + impl Ord for Vec2 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() + } +} -- cgit v1.2.3-70-g09d2