From c57c44a139174ce1021e3b9671e6cd1c5fa3513b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 4 May 2023 10:25:25 +0200 Subject: [PATCH 1/7] Improve formatting --- crates/fj-kernel/src/validate/shell.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/fj-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index c20622333..91915bc3e 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -235,6 +235,7 @@ mod tests { Ok(()) } + #[test] fn shell_not_watertight() -> anyhow::Result<()> { let mut services = Services::new(); From b5ec5738f39711a60c7669f0dd46408dc5e38c10 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 4 May 2023 12:01:42 +0200 Subject: [PATCH 2/7] Track insertion status of `Tetrahedron` --- crates/fj-kernel/src/operations/build/shell.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index c18b6bc06..d41f47f9f 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -2,7 +2,9 @@ use fj_math::Point; use crate::{ objects::{Face, Shell}, - operations::{Insert, IsInsertedYes, JoinCycle, UpdateFace}, + operations::{ + Insert, IsInserted, IsInsertedNo, IsInsertedYes, JoinCycle, UpdateFace, + }, services::Services, }; @@ -83,9 +85,9 @@ impl BuildShell for Shell {} /// `d`, in the order in which they are passed. /// /// Returned by [`BuildShell::tetrahedron`]. -pub struct Tetrahedron { +pub struct Tetrahedron { /// The shell that forms the tetrahedron - pub shell: Shell, + pub shell: I::T, /// The face formed by the points `a`, `b`, and `c`. pub abc: Polygon<3, IsInsertedYes>, From bd9ae22aeadafb2ec8659570bebd8f4659d9366b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 4 May 2023 12:03:43 +0200 Subject: [PATCH 3/7] Implement `Insert` for `Tetrahedron` --- crates/fj-kernel/src/operations/insert.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/operations/insert.rs b/crates/fj-kernel/src/operations/insert.rs index 6cf0eebc4..8c71d9a74 100644 --- a/crates/fj-kernel/src/operations/insert.rs +++ b/crates/fj-kernel/src/operations/insert.rs @@ -7,7 +7,7 @@ use crate::{ storage::Handle, }; -use super::Polygon; +use super::{Polygon, Tetrahedron}; /// Insert an object into its respective store /// @@ -91,3 +91,17 @@ impl Insert for Polygon { } } } + +impl Insert for Tetrahedron { + type Inserted = Tetrahedron; + + fn insert(self, services: &mut Services) -> Self::Inserted { + Tetrahedron { + shell: self.shell.insert(services), + abc: self.abc, + bad: self.bad, + dac: self.dac, + cbd: self.cbd, + } + } +} From eaaa89793bdd018483b3da389815570fc8aef3ee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 4 May 2023 12:11:01 +0200 Subject: [PATCH 4/7] Rename `Tetrahedron` to prepare for new struct --- crates/fj-kernel/src/operations/build/mod.rs | 2 +- crates/fj-kernel/src/operations/build/shell.rs | 6 +++--- crates/fj-kernel/src/operations/insert.rs | 8 ++++---- crates/fj-kernel/src/operations/mod.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/mod.rs b/crates/fj-kernel/src/operations/build/mod.rs index 7f2e1a85a..65c3dfe69 100644 --- a/crates/fj-kernel/src/operations/build/mod.rs +++ b/crates/fj-kernel/src/operations/build/mod.rs @@ -8,6 +8,6 @@ pub use self::{ cycle::BuildCycle, edge::BuildHalfEdge, face::{BuildFace, Polygon}, - shell::{BuildShell, Tetrahedron}, + shell::{BuildShell, TetrahedronShell}, surface::BuildSurface, }; diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index d41f47f9f..41ed095af 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -33,7 +33,7 @@ pub trait BuildShell { fn tetrahedron( points: [impl Into>; 4], services: &mut Services, - ) -> Tetrahedron { + ) -> TetrahedronShell { let [a, b, c, d] = points.map(Into::into); let abc = Face::triangle([a, b, c], services); @@ -66,7 +66,7 @@ pub trait BuildShell { let [abc, bad, dac, cbd] = triangles; - Tetrahedron { + TetrahedronShell { shell, abc, bad, @@ -85,7 +85,7 @@ impl BuildShell for Shell {} /// `d`, in the order in which they are passed. /// /// Returned by [`BuildShell::tetrahedron`]. -pub struct Tetrahedron { +pub struct TetrahedronShell { /// The shell that forms the tetrahedron pub shell: I::T, diff --git a/crates/fj-kernel/src/operations/insert.rs b/crates/fj-kernel/src/operations/insert.rs index 8c71d9a74..66b6a1b42 100644 --- a/crates/fj-kernel/src/operations/insert.rs +++ b/crates/fj-kernel/src/operations/insert.rs @@ -7,7 +7,7 @@ use crate::{ storage::Handle, }; -use super::{Polygon, Tetrahedron}; +use super::{Polygon, TetrahedronShell}; /// Insert an object into its respective store /// @@ -92,11 +92,11 @@ impl Insert for Polygon { } } -impl Insert for Tetrahedron { - type Inserted = Tetrahedron; +impl Insert for TetrahedronShell { + type Inserted = TetrahedronShell; fn insert(self, services: &mut Services) -> Self::Inserted { - Tetrahedron { + TetrahedronShell { shell: self.shell.insert(services), abc: self.abc, bad: self.bad, diff --git a/crates/fj-kernel/src/operations/mod.rs b/crates/fj-kernel/src/operations/mod.rs index de4ebc596..9573ac2d8 100644 --- a/crates/fj-kernel/src/operations/mod.rs +++ b/crates/fj-kernel/src/operations/mod.rs @@ -8,7 +8,7 @@ mod update; pub use self::{ build::{ BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSurface, - Polygon, Tetrahedron, + Polygon, TetrahedronShell, }, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, join::JoinCycle, From 63bc10415e9112a0297b284dc39755f4cf8b7f86 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Mar 2023 14:11:35 +0100 Subject: [PATCH 5/7] Add `BuildSolid` --- crates/fj-kernel/src/operations/build/mod.rs | 2 ++ crates/fj-kernel/src/operations/build/solid.rs | 11 +++++++++++ crates/fj-kernel/src/operations/mod.rs | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 crates/fj-kernel/src/operations/build/solid.rs diff --git a/crates/fj-kernel/src/operations/build/mod.rs b/crates/fj-kernel/src/operations/build/mod.rs index 65c3dfe69..48761b8f6 100644 --- a/crates/fj-kernel/src/operations/build/mod.rs +++ b/crates/fj-kernel/src/operations/build/mod.rs @@ -2,6 +2,7 @@ mod cycle; mod edge; mod face; mod shell; +mod solid; mod surface; pub use self::{ @@ -9,5 +10,6 @@ pub use self::{ edge::BuildHalfEdge, face::{BuildFace, Polygon}, shell::{BuildShell, TetrahedronShell}, + solid::BuildSolid, surface::BuildSurface, }; diff --git a/crates/fj-kernel/src/operations/build/solid.rs b/crates/fj-kernel/src/operations/build/solid.rs new file mode 100644 index 000000000..ac0eb7ca1 --- /dev/null +++ b/crates/fj-kernel/src/operations/build/solid.rs @@ -0,0 +1,11 @@ +use crate::objects::Solid; + +/// Build a [`Solid`] +pub trait BuildSolid { + /// Build an empty solid + fn empty() -> Solid { + Solid::new([]) + } +} + +impl BuildSolid for Solid {} diff --git a/crates/fj-kernel/src/operations/mod.rs b/crates/fj-kernel/src/operations/mod.rs index 9573ac2d8..5c65569c4 100644 --- a/crates/fj-kernel/src/operations/mod.rs +++ b/crates/fj-kernel/src/operations/mod.rs @@ -7,8 +7,8 @@ mod update; pub use self::{ build::{ - BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSurface, - Polygon, TetrahedronShell, + BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSolid, + BuildSurface, Polygon, TetrahedronShell, }, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, join::JoinCycle, From 01ba108aa2cdcbcb64a7bdce0dbe6617177cf563 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Mar 2023 14:15:33 +0100 Subject: [PATCH 6/7] Add `UpdateSolid` --- crates/fj-kernel/src/operations/mod.rs | 4 +++- crates/fj-kernel/src/operations/update/mod.rs | 3 ++- crates/fj-kernel/src/operations/update/solid.rs | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 crates/fj-kernel/src/operations/update/solid.rs diff --git a/crates/fj-kernel/src/operations/mod.rs b/crates/fj-kernel/src/operations/mod.rs index 5c65569c4..1f5913e9a 100644 --- a/crates/fj-kernel/src/operations/mod.rs +++ b/crates/fj-kernel/src/operations/mod.rs @@ -12,5 +12,7 @@ pub use self::{ }, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, join::JoinCycle, - update::{UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateShell}, + update::{ + UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateShell, UpdateSolid, + }, }; diff --git a/crates/fj-kernel/src/operations/update/mod.rs b/crates/fj-kernel/src/operations/update/mod.rs index 73f5d0874..431b97368 100644 --- a/crates/fj-kernel/src/operations/update/mod.rs +++ b/crates/fj-kernel/src/operations/update/mod.rs @@ -2,8 +2,9 @@ mod cycle; mod edge; mod face; mod shell; +mod solid; pub use self::{ cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace, - shell::UpdateShell, + shell::UpdateShell, solid::UpdateSolid, }; diff --git a/crates/fj-kernel/src/operations/update/solid.rs b/crates/fj-kernel/src/operations/update/solid.rs new file mode 100644 index 000000000..9c0e340f7 --- /dev/null +++ b/crates/fj-kernel/src/operations/update/solid.rs @@ -0,0 +1,17 @@ +use crate::{ + objects::{Shell, Solid}, + storage::Handle, +}; + +/// Update a [`Solid`] +pub trait UpdateSolid { + /// Add a shell to the solid + fn add_shell(&self, shell: Handle) -> Solid; +} + +impl UpdateSolid for Solid { + fn add_shell(&self, shell: Handle) -> Solid { + let shells = self.shells().cloned().chain([shell]); + Solid::new(shells) + } +} From 697083be4fa3e2042a3e5b07321a10e005dbfd59 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 4 May 2023 12:18:50 +0200 Subject: [PATCH 7/7] Add `BuildSolid::tetrahedron` --- crates/fj-kernel/src/operations/build/mod.rs | 2 +- .../fj-kernel/src/operations/build/solid.rs | 35 ++++++++++++++++++- crates/fj-kernel/src/operations/mod.rs | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/mod.rs b/crates/fj-kernel/src/operations/build/mod.rs index 48761b8f6..fe6010c3b 100644 --- a/crates/fj-kernel/src/operations/build/mod.rs +++ b/crates/fj-kernel/src/operations/build/mod.rs @@ -10,6 +10,6 @@ pub use self::{ edge::BuildHalfEdge, face::{BuildFace, Polygon}, shell::{BuildShell, TetrahedronShell}, - solid::BuildSolid, + solid::{BuildSolid, Tetrahedron}, surface::BuildSurface, }; diff --git a/crates/fj-kernel/src/operations/build/solid.rs b/crates/fj-kernel/src/operations/build/solid.rs index ac0eb7ca1..080405ee5 100644 --- a/crates/fj-kernel/src/operations/build/solid.rs +++ b/crates/fj-kernel/src/operations/build/solid.rs @@ -1,4 +1,13 @@ -use crate::objects::Solid; +use fj_math::Point; + +use crate::{ + objects::{Shell, Solid}, + operations::{ + build::shell::BuildShell, Insert, IsInsertedYes, TetrahedronShell, + UpdateSolid, + }, + services::Services, +}; /// Build a [`Solid`] pub trait BuildSolid { @@ -6,6 +15,30 @@ pub trait BuildSolid { fn empty() -> Solid { Solid::new([]) } + + /// Build a tetrahedron from the provided points + /// + /// See [`BuildShell::tetrahedron`] for more information. + fn tetrahedron( + points: [impl Into>; 4], + services: &mut Services, + ) -> Tetrahedron { + let shell = Shell::tetrahedron(points, services).insert(services); + let solid = Solid::empty().add_shell(shell.shell.clone()); + + Tetrahedron { solid, shell } + } } impl BuildSolid for Solid {} + +/// A tetrahedron +/// +/// Returned by [`BuildSolid::tetrahedron`]. +pub struct Tetrahedron { + /// The solid that forms the tetrahedron + pub solid: Solid, + + /// The shell of the tetrahedron + pub shell: TetrahedronShell, +} diff --git a/crates/fj-kernel/src/operations/mod.rs b/crates/fj-kernel/src/operations/mod.rs index 1f5913e9a..313bdeaae 100644 --- a/crates/fj-kernel/src/operations/mod.rs +++ b/crates/fj-kernel/src/operations/mod.rs @@ -8,7 +8,7 @@ mod update; pub use self::{ build::{ BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSolid, - BuildSurface, Polygon, TetrahedronShell, + BuildSurface, Polygon, Tetrahedron, TetrahedronShell, }, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, join::JoinCycle,