From a2715eafabd9e4e6e79a68e284517f1ca5a8fc00 Mon Sep 17 00:00:00 2001 From: lisk77 Date: Sun, 2 Nov 2025 14:50:00 +0100 Subject: [PATCH] chore(math): remove warnings --- crates/comet_math/Cargo.toml | 3 ++- crates/comet_math/src/bezier.rs | 2 +- crates/comet_math/src/matrix.rs | 4 ++++ crates/comet_math/src/noise.rs | 9 ++++++--- crates/comet_math/src/point.rs | 18 ++++-------------- crates/comet_math/src/polynomial.rs | 2 +- crates/comet_math/src/quaternion.rs | 1 + crates/comet_math/src/vector.rs | 24 +++++++++++------------- 8 files changed, 30 insertions(+), 33 deletions(-) diff --git a/crates/comet_math/Cargo.toml b/crates/comet_math/Cargo.toml index af49077..d0aaf64 100644 --- a/crates/comet_math/Cargo.toml +++ b/crates/comet_math/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" comet_log = { path = "../comet_log" } rand = "0.9.0-beta.1" image = { version = "0.24", default_features = false, features = ["png", "jpeg", "hdr"] } -chrono = "0.4.40" \ No newline at end of file +chrono = "0.4.40" +serde = { version = "1.0", features = ["derive"] } diff --git a/crates/comet_math/src/bezier.rs b/crates/comet_math/src/bezier.rs index 89458c6..3c16dfd 100644 --- a/crates/comet_math/src/bezier.rs +++ b/crates/comet_math/src/bezier.rs @@ -1,4 +1,4 @@ -use crate::{InnerSpace, Point}; +use crate::InnerSpace; /// Representation of a Bezier curve of degree n in any (2-4) dimensions. pub struct Bezier { diff --git a/crates/comet_math/src/matrix.rs b/crates/comet_math/src/matrix.rs index 4a9c501..81fb3d6 100644 --- a/crates/comet_math/src/matrix.rs +++ b/crates/comet_math/src/matrix.rs @@ -1,6 +1,7 @@ use crate::vector::{v2, v3, v4}; use std::ops::*; +#[allow(dead_code)] trait LinearTransformation { fn det(&self) -> f32; } @@ -12,6 +13,7 @@ trait LinearTransformation { /// Representation of a 2x2 matrix. #[repr(C)] #[derive(Debug, PartialEq)] +#[allow(non_camel_case_types)] pub struct m2 { x00: f32, x01: f32, @@ -208,6 +210,7 @@ impl Into<[[f32; 2]; 2]> for m2 { /// Representation of a 3x3 matrix. #[repr(C)] #[derive(Debug, PartialEq)] +#[allow(non_camel_case_types)] pub struct m3 { x00: f32, x01: f32, @@ -497,6 +500,7 @@ impl Into<[[f32; 3]; 3]> for m3 { /// Representation of a 4x4 matrix. #[repr(C)] #[derive(Debug, PartialEq)] +#[allow(non_camel_case_types)] pub struct m4 { x00: f32, x01: f32, diff --git a/crates/comet_math/src/noise.rs b/crates/comet_math/src/noise.rs index f6ddbea..62f155d 100644 --- a/crates/comet_math/src/noise.rs +++ b/crates/comet_math/src/noise.rs @@ -323,9 +323,12 @@ impl ValueNoise { let mut f = 0.0; let mut amplitude = 0.5; - f += amplitude * self.noise(uv); - uv = (uv.0 * 2.0, uv.1 * 2.0); - amplitude *= 0.5; + for _ in 0..4 { + f += amplitude * self.noise(uv); + uv = (uv.0 * 2.0, uv.1 * 2.0); + amplitude *= 0.5; + } + f = ((f / max_amplitude) + 1.0) * 0.5; noise.push(f); diff --git a/crates/comet_math/src/point.rs b/crates/comet_math/src/point.rs index 51ef279..edc5cc4 100644 --- a/crates/comet_math/src/point.rs +++ b/crates/comet_math/src/point.rs @@ -7,6 +7,7 @@ pub trait Point { } /// Representation of a 2D point. +#[allow(non_camel_case_types)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct p2 { x: f32, @@ -36,6 +37,7 @@ impl p2 { } /// Representation of a 3D point. +#[allow(non_camel_case_types)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct p3 { x: f32, @@ -81,7 +83,7 @@ impl Point for p2 { Self { x, y } } - fn to_vec(&self) -> v2 { + fn to_vec(&self) -> impl InnerSpace { v2::new(self.x, self.y) } } @@ -93,23 +95,11 @@ impl Point for p3 { Self { x, y, z } } - fn to_vec(&self) -> v3 { + fn to_vec(&self) -> impl InnerSpace { v3::new(self.x, self.y, self.z) } } -impl Into for p2 { - fn into(self) -> v2 { - self.to_vec() - } -} - -impl Into for p3 { - fn into(self) -> v3 { - self.to_vec() - } -} - impl From for p2 { fn from(v: v2) -> Self { Self::from_vec(v) diff --git a/crates/comet_math/src/polynomial.rs b/crates/comet_math/src/polynomial.rs index eaf1f09..2a7ff89 100644 --- a/crates/comet_math/src/polynomial.rs +++ b/crates/comet_math/src/polynomial.rs @@ -118,7 +118,7 @@ impl Div for Polynomial { let divisor = other.coefficients.clone(); while dividend.len() >= divisor.len() { let mut quotient = vec![0.0; dividend.len() - divisor.len() + 1]; - let mut i = dividend.len() - divisor.len(); + let i = dividend.len() - divisor.len(); quotient[i] = dividend.last().unwrap() / divisor.last().unwrap(); for (j, &d) in divisor.iter().enumerate() { dividend[i + j] -= quotient[i] * d; diff --git a/crates/comet_math/src/quaternion.rs b/crates/comet_math/src/quaternion.rs index 1183b9c..4f08550 100644 --- a/crates/comet_math/src/quaternion.rs +++ b/crates/comet_math/src/quaternion.rs @@ -11,6 +11,7 @@ pub struct Quat { impl Quat { /// The zero quaternion. + #[allow(unused)] const ZERO: Self = Self { s: 0.0, v: v3 { diff --git a/crates/comet_math/src/vector.rs b/crates/comet_math/src/vector.rs index 011e788..860a5b0 100644 --- a/crates/comet_math/src/vector.rs +++ b/crates/comet_math/src/vector.rs @@ -1,6 +1,9 @@ -use crate::point::{p2, p3}; -use crate::quaternion::Quat; -use crate::Point; +use crate::{ + point::{p2, p3}, + quaternion::Quat, + Point, +}; +use serde::{Deserialize, Serialize}; use std::ops::*; pub trait InnerSpace: @@ -31,8 +34,7 @@ pub trait InnerSpace: /// Representation of a 2D vector #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[allow(non_camel_case_types)] pub struct v2 { x: f32, @@ -175,8 +177,7 @@ impl Into for [f32; 2] { /// Representation of a 2D integer vector #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[allow(non_camel_case_types)] pub struct v2i { x: i64, @@ -423,8 +424,7 @@ impl Into<[f32; 2]> for v2i { /// Representation of a 3D vector #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[allow(non_camel_case_types)] pub struct v3 { pub x: f32, @@ -620,8 +620,7 @@ impl Into for [f32; 3] { /// Representation of a 3D integer vector #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[allow(non_camel_case_types)] pub struct v3i { pub x: i64, @@ -824,8 +823,7 @@ impl From for v3i { /// Representation of a 4D vector #[repr(C)] -#[derive(Debug, Clone, Copy, PartialEq, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[allow(non_camel_case_types)] pub struct v4 { x: f32,