Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract fj-debug from fj-app #376

Merged
merged 4 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"fj",
"fj-app",
"fj-debug",
"fj-math",

"models/cuboid",
Expand All @@ -14,5 +15,6 @@ members = [
]
default-members = [
"fj-app",
"fj-debug",
"fj-math",
]
4 changes: 4 additions & 0 deletions fj-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 0 additions & 36 deletions fj-app/src/debug.rs

This file was deleted.

6 changes: 2 additions & 4 deletions fj-app/src/graphics/vertices.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions fj-app/src/kernel/shape/topology.rs
Original file line number Diff line number Diff line change
@@ -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,
},
};

Expand Down
12 changes: 5 additions & 7 deletions fj-app/src/kernel/shapes/circle.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 7 additions & 9 deletions fj-app/src/kernel/shapes/difference_2d.rs
Original file line number Diff line number Diff line change
@@ -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,
},
};

Expand Down
16 changes: 7 additions & 9 deletions fj-app/src/kernel/shapes/group.rs
Original file line number Diff line number Diff line change
@@ -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,
},
};

Expand Down
3 changes: 1 addition & 2 deletions fj-app/src/kernel/shapes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions fj-app/src/kernel/shapes/sketch.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 2 additions & 4 deletions fj-app/src/kernel/shapes/sweep.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion fj-app/src/kernel/shapes/transform.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
14 changes: 5 additions & 9 deletions fj-app/src/kernel/topology/faces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions fj-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod args;
mod camera;
mod config;
mod debug;
mod graphics;
mod input;
mod kernel;
Expand All @@ -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 _;
Expand All @@ -29,7 +29,6 @@ use crate::{
args::Args,
camera::Camera,
config::Config,
debug::DebugInfo,
graphics::{DrawConfig, Renderer},
kernel::shapes::ToShape as _,
mesh::MeshMaker,
Expand Down
14 changes: 14 additions & 0 deletions fj-debug/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
54 changes: 54 additions & 0 deletions fj-debug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! 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.

#![deny(missing_docs)]

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<TriangleEdgeCheck>,
}

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();
}
}

/// 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<f64>,
}

impl TriangleEdgeCheck {
/// Construct a new instance
pub fn new(ray: Ray) -> Self {
Self {
ray,
hits: Vec::new(),
}
}
}