From 9d5fc6903e75289a3f8fe3616faa75b9620027c2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 16:15:42 +0100 Subject: [PATCH 1/4] Extract `debug` module into separate crate --- Cargo.lock | 8 ++++++++ Cargo.toml | 2 ++ fj-app/Cargo.toml | 4 ++++ fj-app/src/graphics/vertices.rs | 6 ++---- fj-app/src/kernel/shape/topology.rs | 16 +++++++--------- fj-app/src/kernel/shapes/circle.rs | 12 +++++------- fj-app/src/kernel/shapes/difference_2d.rs | 16 +++++++--------- fj-app/src/kernel/shapes/group.rs | 16 +++++++--------- fj-app/src/kernel/shapes/mod.rs | 3 +-- fj-app/src/kernel/shapes/sketch.rs | 12 +++++------- fj-app/src/kernel/shapes/sweep.rs | 6 ++---- fj-app/src/kernel/shapes/transform.rs | 3 ++- fj-app/src/kernel/topology/faces.rs | 14 +++++--------- fj-app/src/main.rs | 3 +-- fj-debug/Cargo.toml | 14 ++++++++++++++ fj-app/src/debug.rs => fj-debug/src/lib.rs | 0 16 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 fj-debug/Cargo.toml rename fj-app/src/debug.rs => fj-debug/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f5ecb7f28..02bd332ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -631,6 +631,7 @@ dependencies = [ "clap", "figment", "fj", + "fj-debug", "fj-math", "futures", "libloading", @@ -651,6 +652,13 @@ dependencies = [ "winit", ] +[[package]] +name = "fj-debug" +version = "0.5.0" +dependencies = [ + "parry3d-f64", +] + [[package]] name = "fj-math" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index c9e94951a..a672aadfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "2" members = [ "fj", "fj-app", + "fj-debug", "fj-math", "models/cuboid", @@ -14,5 +15,6 @@ members = [ ] default-members = [ "fj-app", + "fj-debug", "fj-math", ] diff --git a/fj-app/Cargo.toml b/fj-app/Cargo.toml index 1f2880d39..fd648d68c 100644 --- a/fj-app/Cargo.toml +++ b/fj-app/Cargo.toml @@ -43,6 +43,10 @@ features = ["env", "toml"] version = "0.5.0" path = "../fj" +[dependencies.fj-debug] +version = "0.5.0" +path = "../fj-debug" + [dependencies.fj-math] version = "0.5.0" path = "../fj-math" diff --git a/fj-app/src/graphics/vertices.rs b/fj-app/src/graphics/vertices.rs index 0afc25b89..d87c8f229 100644 --- a/fj-app/src/graphics/vertices.rs +++ b/fj-app/src/graphics/vertices.rs @@ -1,11 +1,9 @@ use bytemuck::{Pod, Zeroable}; +use fj_debug::DebugInfo; use fj_math::Triangle; use nalgebra::{vector, Point}; -use crate::{ - debug::DebugInfo, - mesh::{Index, MeshMaker}, -}; +use crate::mesh::{Index, MeshMaker}; #[derive(Debug)] pub struct Vertices { diff --git a/fj-app/src/kernel/shape/topology.rs b/fj-app/src/kernel/shape/topology.rs index 147f97a9d..56bef7f09 100644 --- a/fj-app/src/kernel/shape/topology.rs +++ b/fj-app/src/kernel/shape/topology.rs @@ -1,16 +1,14 @@ use std::collections::HashSet; +use fj_debug::DebugInfo; use fj_math::{Point, Scalar, Triangle, Vector}; -use crate::{ - debug::DebugInfo, - kernel::{ - geometry::{Circle, Curve, Line}, - topology::{ - edges::{Cycle, Edge}, - faces::Face, - vertices::Vertex, - }, +use crate::kernel::{ + geometry::{Circle, Curve, Line}, + topology::{ + edges::{Cycle, Edge}, + faces::Face, + vertices::Vertex, }, }; diff --git a/fj-app/src/kernel/shapes/circle.rs b/fj-app/src/kernel/shapes/circle.rs index 5f283a5a7..98e9e8d32 100644 --- a/fj-app/src/kernel/shapes/circle.rs +++ b/fj-app/src/kernel/shapes/circle.rs @@ -1,12 +1,10 @@ +use fj_debug::DebugInfo; use fj_math::{Aabb, Point, Scalar}; -use crate::{ - debug::DebugInfo, - kernel::{ - geometry::Surface, - shape::Shape, - topology::{edges::Cycle, faces::Face}, - }, +use crate::kernel::{ + geometry::Surface, + shape::Shape, + topology::{edges::Cycle, faces::Face}, }; use super::ToShape; diff --git a/fj-app/src/kernel/shapes/difference_2d.rs b/fj-app/src/kernel/shapes/difference_2d.rs index a2ea256f0..b44f7b151 100644 --- a/fj-app/src/kernel/shapes/difference_2d.rs +++ b/fj-app/src/kernel/shapes/difference_2d.rs @@ -1,16 +1,14 @@ use std::collections::HashMap; +use fj_debug::DebugInfo; use fj_math::{Aabb, Scalar}; -use crate::{ - debug::DebugInfo, - kernel::{ - shape::Shape, - topology::{ - edges::{Cycle, Edge}, - faces::Face, - vertices::Vertex, - }, +use crate::kernel::{ + shape::Shape, + topology::{ + edges::{Cycle, Edge}, + faces::Face, + vertices::Vertex, }, }; diff --git a/fj-app/src/kernel/shapes/group.rs b/fj-app/src/kernel/shapes/group.rs index b73b2b73c..2c44b42b4 100644 --- a/fj-app/src/kernel/shapes/group.rs +++ b/fj-app/src/kernel/shapes/group.rs @@ -1,16 +1,14 @@ use std::collections::HashMap; +use fj_debug::DebugInfo; use fj_math::{Aabb, Scalar}; -use crate::{ - debug::DebugInfo, - kernel::{ - shape::Shape, - topology::{ - edges::{Cycle, Edge}, - faces::Face, - vertices::Vertex, - }, +use crate::kernel::{ + shape::Shape, + topology::{ + edges::{Cycle, Edge}, + faces::Face, + vertices::Vertex, }, }; diff --git a/fj-app/src/kernel/shapes/mod.rs b/fj-app/src/kernel/shapes/mod.rs index 737993891..e7b00773d 100644 --- a/fj-app/src/kernel/shapes/mod.rs +++ b/fj-app/src/kernel/shapes/mod.rs @@ -5,10 +5,9 @@ pub mod sketch; pub mod sweep; pub mod transform; +use fj_debug::DebugInfo; use fj_math::{Aabb, Scalar}; -use crate::debug::DebugInfo; - use super::shape::Shape; /// Implemented by all shapes diff --git a/fj-app/src/kernel/shapes/sketch.rs b/fj-app/src/kernel/shapes/sketch.rs index d6f718f6f..8deb59928 100644 --- a/fj-app/src/kernel/shapes/sketch.rs +++ b/fj-app/src/kernel/shapes/sketch.rs @@ -1,12 +1,10 @@ +use fj_debug::DebugInfo; use fj_math::{Aabb, Point, Scalar}; -use crate::{ - debug::DebugInfo, - kernel::{ - geometry::Surface, - shape::Shape, - topology::{edges::Cycle, faces::Face, vertices::Vertex}, - }, +use crate::kernel::{ + geometry::Surface, + shape::Shape, + topology::{edges::Cycle, faces::Face, vertices::Vertex}, }; use super::ToShape; diff --git a/fj-app/src/kernel/shapes/sweep.rs b/fj-app/src/kernel/shapes/sweep.rs index 0f7f73913..0ddc6d80f 100644 --- a/fj-app/src/kernel/shapes/sweep.rs +++ b/fj-app/src/kernel/shapes/sweep.rs @@ -1,9 +1,7 @@ +use fj_debug::DebugInfo; use fj_math::{Aabb, Scalar, Vector}; -use crate::{ - debug::DebugInfo, - kernel::{algorithms::sweep::sweep_shape, shape::Shape}, -}; +use crate::kernel::{algorithms::sweep::sweep_shape, shape::Shape}; use super::ToShape; diff --git a/fj-app/src/kernel/shapes/transform.rs b/fj-app/src/kernel/shapes/transform.rs index 2b3e8a26e..6a2ffd1f1 100644 --- a/fj-app/src/kernel/shapes/transform.rs +++ b/fj-app/src/kernel/shapes/transform.rs @@ -1,7 +1,8 @@ +use fj_debug::DebugInfo; use fj_math::{Aabb, Scalar, Transform}; use parry3d_f64::math::Isometry; -use crate::{debug::DebugInfo, kernel::shape::Shape}; +use crate::kernel::shape::Shape; use super::ToShape; diff --git a/fj-app/src/kernel/topology/faces.rs b/fj-app/src/kernel/topology/faces.rs index 0bdce626a..a5b805d88 100644 --- a/fj-app/src/kernel/topology/faces.rs +++ b/fj-app/src/kernel/topology/faces.rs @@ -3,19 +3,15 @@ use std::{ hash::{Hash, Hasher}, }; +use fj_debug::{DebugInfo, TriangleEdgeCheck}; use fj_math::{Aabb, Scalar, Segment, Triangle}; use parry2d_f64::query::{Ray as Ray2, RayCast as _}; use parry3d_f64::query::Ray as Ray3; -use crate::{ - debug::{DebugInfo, TriangleEdgeCheck}, - kernel::{ - algorithms::{ - approximation::Approximation, triangulation::triangulate, - }, - geometry::Surface, - shape::Handle, - }, +use crate::kernel::{ + algorithms::{approximation::Approximation, triangulation::triangulate}, + geometry::Surface, + shape::Handle, }; use super::edges::Cycle; diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index 2f8237065..572ff6bce 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -1,7 +1,6 @@ mod args; mod camera; mod config; -mod debug; mod graphics; mod input; mod kernel; @@ -14,6 +13,7 @@ use std::ffi::OsStr; use std::path::PathBuf; use std::{collections::HashMap, sync::mpsc, time::Instant}; +use fj_debug::DebugInfo; use fj_math::Scalar; use futures::executor::block_on; use notify::Watcher as _; @@ -29,7 +29,6 @@ use crate::{ args::Args, camera::Camera, config::Config, - debug::DebugInfo, graphics::{DrawConfig, Renderer}, kernel::shapes::ToShape as _, mesh::MeshMaker, diff --git a/fj-debug/Cargo.toml b/fj-debug/Cargo.toml new file mode 100644 index 000000000..943841991 --- /dev/null +++ b/fj-debug/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "fj-debug" +version = "0.5.0" +edition = "2021" + +description = "The world needs another CAD program." +readme = "../README.md" +repository = "https://github.com/hannobraun/fornjot" +license = "0BSD" +keywords = ["cad", "programmatic", "code-cad"] + + +[dependencies] +parry3d-f64 = "0.8.0" diff --git a/fj-app/src/debug.rs b/fj-debug/src/lib.rs similarity index 100% rename from fj-app/src/debug.rs rename to fj-debug/src/lib.rs From 391582f7d3cffd301e39bba12d9821dc955e537c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 16:17:16 +0100 Subject: [PATCH 2/4] Fix Clippy warning This one only showed up after extracting the module into a separate crate. No idea why; none of the code changed. --- fj-debug/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fj-debug/src/lib.rs b/fj-debug/src/lib.rs index 643cf1d66..2f29919e6 100644 --- a/fj-debug/src/lib.rs +++ b/fj-debug/src/lib.rs @@ -3,6 +3,7 @@ use parry3d_f64::query::Ray; /// Debug info from the CAD kernel that can be visualized /// /// At this point, this is a placeholder that will be filled with life later. +#[derive(Default)] pub struct DebugInfo { /// Rays being used during face triangulation pub triangle_edge_checks: Vec, @@ -10,9 +11,7 @@ pub struct DebugInfo { impl DebugInfo { pub fn new() -> Self { - Self { - triangle_edge_checks: Vec::new(), - } + Self::default() } pub fn clear(&mut self) { From 4cb345eda0888638a11e276202fb87a94de1c985 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 16:24:03 +0100 Subject: [PATCH 3/4] Update documentation of `fj-debug` --- fj-debug/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fj-debug/src/lib.rs b/fj-debug/src/lib.rs index 2f29919e6..a44b71b7c 100644 --- a/fj-debug/src/lib.rs +++ b/fj-debug/src/lib.rs @@ -1,3 +1,10 @@ +//! Debug information definitions for the Fornjot ecosystem +//! +//! This crate contains debug information that is used by other crates within +//! the Fornjot ecosystem. The types in here aren't very useful in themselves, +//! but they define an interface that other crates use to communicate between +//! each other. + use parry3d_f64::query::Ray; /// Debug info from the CAD kernel that can be visualized @@ -10,10 +17,16 @@ pub struct DebugInfo { } impl DebugInfo { + /// Construct an empty instance of `DebugInfo` pub fn new() -> Self { Self::default() } + /// Clear all information within this instance + /// + /// The resulting instance is the same, as if created by [`DebugInfo::new`], + /// but calling `clear` might be more efficient in regard to heap + /// allocations. pub fn clear(&mut self) { self.triangle_edge_checks.clear(); } @@ -21,11 +34,15 @@ impl DebugInfo { /// Record of a check to determine if a triangle edge is within a face pub struct TriangleEdgeCheck { + /// The ray used to perform the check pub ray: Ray, + + /// Where the ray hit any edges of the face pub hits: Vec, } impl TriangleEdgeCheck { + /// Construct a new instance pub fn new(ray: Ray) -> Self { Self { ray, From 04a52a8783bd9176c3153d7f484485fdfe6ea209 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 16:24:15 +0100 Subject: [PATCH 4/4] Deny missing documentation in `fj-debug` --- fj-debug/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fj-debug/src/lib.rs b/fj-debug/src/lib.rs index a44b71b7c..7fee8ce35 100644 --- a/fj-debug/src/lib.rs +++ b/fj-debug/src/lib.rs @@ -5,6 +5,8 @@ //! but they define an interface that other crates use to communicate between //! each other. +#![deny(missing_docs)] + use parry3d_f64::query::Ray; /// Debug info from the CAD kernel that can be visualized