diff --git a/Cargo.lock b/Cargo.lock index d2a4ce2f3..38e6b0082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,15 +50,6 @@ version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" -[[package]] -name = "approx" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" -dependencies = [ - "num-traits", -] - [[package]] name = "approx" version = "0.5.1" @@ -478,18 +469,6 @@ dependencies = [ "syn", ] -[[package]] -name = "decorum" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "281759d3c8a14f5c3f0c49363be56810fcd7f910422f97f2db850c2920fde5cf" -dependencies = [ - "approx 0.3.2", - "num-traits", - "serde", - "serde_derive", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -538,10 +517,9 @@ name = "fj-host" version = "0.5.0" dependencies = [ "anyhow", - "approx 0.5.1", + "approx", "bytemuck", "clap", - "decorum", "fj", "futures", "libloading", @@ -758,7 +736,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc32c2334f00ca5ac3695c5009ae35da21da8c62d255b5b96d56e2597a637a38" dependencies = [ "ab_glyph", - "approx 0.5.1", + "approx", "xi-unicode", ] @@ -1113,7 +1091,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb2d0de08694bed883320212c18ee3008576bfe8c306f4c3c4a58b4876998be" dependencies = [ - "approx 0.5.1", + "approx", "matrixmultiply", "nalgebra-macros", "num-complex", @@ -1402,7 +1380,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e96040e0f10b65df992e8367983b7c3ac779046cd6d9a4a7cd1496e8c6b6ef51" dependencies = [ - "approx 0.5.1", + "approx", "arrayvec", "bitflags", "downcast-rs", @@ -1422,7 +1400,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "760c93194acb2bda0c4d0696b0350c143da072c8f8dbe01b38fe1d1aa3a154e0" dependencies = [ - "approx 0.5.1", + "approx", "bitflags", "downcast-rs", "either", @@ -1668,17 +1646,6 @@ version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" -[[package]] -name = "serde_derive" -version = "1.0.136" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "sharded-slab" version = "0.1.4" @@ -1694,7 +1661,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a2609e876d4f77f6ab7ff5254fc39b4f1927ba8e6db3d18be7c32534d3725e" dependencies = [ - "approx 0.5.1", + "approx", "num-complex", "num-traits", "paste", diff --git a/Cargo.toml b/Cargo.toml index 58f61eea7..ad9770f0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ categories = ["mathematics", "rendering"] anyhow = "1.0.53" approx = "0.5.1" bytemuck = "1.7.3" -decorum = "0.3.1" futures = "0.3.21" libloading = "0.7.2" nalgebra = "0.30.0" diff --git a/src/graphics/vertices.rs b/src/graphics/vertices.rs index 9ff42e22a..316b8d37d 100644 --- a/src/graphics/vertices.rs +++ b/src/graphics/vertices.rs @@ -4,7 +4,7 @@ use nalgebra::{vector, Point}; use crate::{ debug::DebugInfo, math::Triangle, - mesh::{HashVector, Index, MeshMaker}, + mesh::{Index, MeshMaker}, }; #[derive(Debug)] @@ -57,12 +57,6 @@ impl From<&Vec> for Vertices { let normal = (b - a).cross(&(c - a)).normalize(); - let a = HashVector::from(&a.to_na()); - let b = HashVector::from(&b.to_na()); - let c = HashVector::from(&c.to_na()); - - let normal = HashVector::from(&normal.to_na()); - mesh.push((a, normal)); mesh.push((b, normal)); mesh.push((c, normal)); diff --git a/src/kernel/approximation.rs b/src/kernel/approximation.rs index 3b4313765..a84b52c03 100644 --- a/src/kernel/approximation.rs +++ b/src/kernel/approximation.rs @@ -1,7 +1,5 @@ use std::{cmp::Ordering, collections::HashSet}; -use decorum::R64; - use crate::math::{Point, Scalar, Segment}; use super::topology::edges::{Cycle, Edge, Edges}; @@ -149,20 +147,18 @@ impl Approximation { // Verify that there are no duplicate points let mut points = HashSet::new(); for &point in &self.points { - let point_r64 = point_to_r64(point); - - if points.contains(&point_r64) { + if points.contains(&point) { duplicate_points.push(point); } - points.insert(point_r64); + points.insert(point); } let mut segments = HashSet::new(); for &segment @ Segment { a, b } in &self.segments { // Verify that there are no duplicate segments - let ab = [point_to_r64(a), point_to_r64(b)]; - let ba = [point_to_r64(b), point_to_r64(a)]; + let ab = [a, b]; + let ba = [b, a]; if segments.contains(&ab) { duplicate_segments.push(segment); } @@ -213,14 +209,6 @@ pub struct ValidationError { pub segments_with_invalid_points: Vec>, } -fn point_to_r64(point: Point<3>) -> [R64; 3] { - [ - point.x().into_f64().into(), - point.y().into_f64().into(), - point.z().into_f64().into(), - ] -} - #[cfg(test)] mod tests { use std::cell::RefCell; diff --git a/src/kernel/topology/faces.rs b/src/kernel/topology/faces.rs index 50b8384fc..4c38e0471 100644 --- a/src/kernel/topology/faces.rs +++ b/src/kernel/topology/faces.rs @@ -1,6 +1,5 @@ use std::collections::BTreeSet; -use decorum::R64; use parry2d_f64::query::{Ray as Ray2, RayCast as _}; use parry3d_f64::query::Ray as Ray3; @@ -193,11 +192,10 @@ impl Face { let edge = Segment::from(edge.map(|point| point.value)); - let intersection = edge.to_parry().cast_local_ray( - &ray, - f64::INFINITY, - true, - ); + let intersection = edge + .to_parry() + .cast_local_ray(&ray, f64::INFINITY, true) + .map(|t| Scalar::from_f64(t)); if let Some(t) = intersection { // Due to slight inaccuracies, we might get @@ -206,9 +204,8 @@ impl Face { let eps = 1_000_000.0; let t = (t * eps).round() / eps; - let t_r64: R64 = t.into(); - if hits.insert(t_r64) { - check.hits.push(t); + if hits.insert(t) { + check.hits.push(t.into_f64()); } } } diff --git a/src/main.rs b/src/main.rs index 654dae2d3..9433d0de4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use crate::{ debug::DebugInfo, graphics::{DrawConfig, Renderer}, kernel::Shape as _, - mesh::{HashVector, MeshMaker}, + mesh::MeshMaker, model::Model, window::Window, }; @@ -97,7 +97,7 @@ fn main() -> anyhow::Result<()> { for triangle in triangles { for vertex in triangle.vertices() { - mesh_maker.push(HashVector::from(&vertex.to_na())); + mesh_maker.push(vertex); } } diff --git a/src/math/point.rs b/src/math/point.rs index bc11fb811..f3c7c258c 100644 --- a/src/math/point.rs +++ b/src/math/point.rs @@ -106,6 +106,18 @@ impl From> for Point { } } +impl From> for [f32; D] { + fn from(point: Point) -> Self { + point.0.map(|scalar| scalar.into_f32()) + } +} + +impl From> for [f64; D] { + fn from(point: Point) -> Self { + point.0.map(|scalar| scalar.into_f64()) + } +} + impl ops::Neg for Point { type Output = Self; diff --git a/src/math/scalar.rs b/src/math/scalar.rs index 8b7b2507d..ed0644078 100644 --- a/src/math/scalar.rs +++ b/src/math/scalar.rs @@ -62,7 +62,12 @@ impl Scalar { Self::from_f64(scalar as f64) } - /// Convert the scalar into a `f64` + /// Convert the scalar into an `f32` + pub fn into_f32(self) -> f32 { + self.0 as f32 + } + + /// Convert the scalar into an `f64` pub fn into_f64(self) -> f64 { self.0 } @@ -87,6 +92,11 @@ impl Scalar { self.0.ceil().into() } + /// Round the scalar + pub fn round(self) -> Self { + self.0.round().into() + } + /// Compute the cosine pub fn cos(self) -> Self { self.0.cos().into() diff --git a/src/math/vector.rs b/src/math/vector.rs index 3893d0296..7c6dbd203 100644 --- a/src/math/vector.rs +++ b/src/math/vector.rs @@ -121,6 +121,12 @@ impl From> for Vector { } } +impl From> for [f32; D] { + fn from(vector: Vector) -> Self { + vector.0.map(|scalar| scalar.into_f32()) + } +} + impl ops::Add for Vector { type Output = Self; diff --git a/src/mesh.rs b/src/mesh.rs index 2e22bfc61..85a7e0b4d 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -1,8 +1,5 @@ use std::{collections::HashMap, hash::Hash}; -use decorum::R64; -use nalgebra::{Point, SVector}; - /// API for creating a mesh pub struct MeshMaker { vertices: Vec, @@ -47,37 +44,5 @@ where } } -/// A point/vector type that can be used as a [`HashMap`] key -#[derive(Clone, Copy, Eq, Hash, PartialEq)] -pub struct HashVector(pub [R64; 3]); - -impl From<&Point> for HashVector { - fn from(point: &Point) -> Self { - Self([R64::from(point.x), R64::from(point.y), R64::from(point.z)]) - } -} - -impl From<&SVector> for HashVector { - fn from(vector: &SVector) -> Self { - Self([ - R64::from(vector.x), - R64::from(vector.y), - R64::from(vector.z), - ]) - } -} - -impl From for [f32; 3] { - fn from(hash_vector: HashVector) -> Self { - hash_vector.0.map(|coord| coord.into_inner() as f32) - } -} - -impl From for [f64; 3] { - fn from(hash_vector: HashVector) -> Self { - hash_vector.0.map(|coord| coord.into_inner()) - } -} - /// An index that refers to a vertex in a mesh pub type Index = u32;