From c9f7ee495e3b527cdcc03fb87fd887d2fd7409fa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:28:04 +0100 Subject: [PATCH 01/11] Rename `fj::Union` to `fj::Group` --- fj/src/shape_3d.rs | 12 ++++++------ fj/src/syntax.rs | 6 +++--- src/kernel/shapes/union.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index 5c49d92e8..83bb52dc4 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -11,7 +11,7 @@ pub enum Shape3d { Transform(Box), /// The union of two 3-dimensional shapes - Union(Box), + Union(Box), } impl From for Shape { @@ -114,7 +114,7 @@ impl From for Shape3d { /// #[derive(Clone, Debug)] #[repr(C)] -pub struct Union { +pub struct Group { /// The first of the shapes pub a: Shape3d, @@ -122,14 +122,14 @@ pub struct Union { pub b: Shape3d, } -impl From for Shape { - fn from(shape: Union) -> Self { +impl From for Shape { + fn from(shape: Group) -> Self { Self::Shape3d(Shape3d::Union(Box::new(shape))) } } -impl From for Shape3d { - fn from(shape: Union) -> Self { +impl From for Shape3d { + fn from(shape: Group) -> Self { Self::Union(Box::new(shape)) } } diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index b62a693cf..bfc0b05c0 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -71,7 +71,7 @@ where } pub trait Union { - fn union(&self, other: &Other) -> crate::Union + fn union(&self, other: &Other) -> crate::Group where Other: Clone + Into; } @@ -80,13 +80,13 @@ impl Union for T where T: Clone + Into, { - fn union(&self, other: &Other) -> crate::Union + fn union(&self, other: &Other) -> crate::Group where Other: Clone + Into, { let a = self.clone().into(); let b = other.clone().into(); - crate::Union { a, b } + crate::Group { a, b } } } diff --git a/src/kernel/shapes/union.rs b/src/kernel/shapes/union.rs index 0bcdcb2b2..9b2fffe25 100644 --- a/src/kernel/shapes/union.rs +++ b/src/kernel/shapes/union.rs @@ -15,7 +15,7 @@ use crate::{ use super::ToShape; -impl ToShape for fj::Union { +impl ToShape for fj::Group { fn to_shape(&self, tolerance: Scalar, debug_info: &mut DebugInfo) -> Shape { let mut shape = Shape::new(); From dbae52a8116473bdc071ad6399de919f78e542df Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:31:27 +0100 Subject: [PATCH 02/11] Update documentation of `fj::Group` --- fj/src/shape_3d.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index 83bb52dc4..27397d96f 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -98,20 +98,14 @@ impl From for Shape3d { } } -/// The union of two 3-dimensional shapes +/// A group of two 3-dimensional shapes /// -/// # Limitations -/// -/// Support for unions is somewhat limited right now. A union of 2 distinct -/// shapes doesn't really create a new shape, but just an aggregation of the -/// two original shapes. +/// A group is a collection of disjoint shapes. It is not a union, in that the +/// shapes in the group are not allowed to touch or overlap. /// -/// This means, for example, that generating the triangle mesh of the union does -/// not result in a proper triangle mesh, but rather the two, possibly -/// intersecting, triangle meshes of the original shapes. +/// # Limitations /// -/// See issue: -/// +/// Whether the shapes in the group touch or overlap is not currently checked. #[derive(Clone, Debug)] #[repr(C)] pub struct Group { From e632bd55cad54d86e8739289eeaf641fbff25968 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:32:05 +0100 Subject: [PATCH 03/11] Move `fj::Group` within the file This way, the types in the file are alphabetically sorted again, which makes things easier to find. --- fj/src/shape_3d.rs | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index 27397d96f..afdd45dc8 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -20,6 +20,36 @@ impl From for Shape { } } +/// A group of two 3-dimensional shapes +/// +/// A group is a collection of disjoint shapes. It is not a union, in that the +/// shapes in the group are not allowed to touch or overlap. +/// +/// # Limitations +/// +/// Whether the shapes in the group touch or overlap is not currently checked. +#[derive(Clone, Debug)] +#[repr(C)] +pub struct Group { + /// The first of the shapes + pub a: Shape3d, + + /// The second of the shapes + pub b: Shape3d, +} + +impl From for Shape { + fn from(shape: Group) -> Self { + Self::Shape3d(Shape3d::Union(Box::new(shape))) + } +} + +impl From for Shape3d { + fn from(shape: Group) -> Self { + Self::Union(Box::new(shape)) + } +} + /// A transformed 3-dimensional shape /// /// # Limitations @@ -97,33 +127,3 @@ impl From for Shape3d { Self::Sweep(shape) } } - -/// A group of two 3-dimensional shapes -/// -/// A group is a collection of disjoint shapes. It is not a union, in that the -/// shapes in the group are not allowed to touch or overlap. -/// -/// # Limitations -/// -/// Whether the shapes in the group touch or overlap is not currently checked. -#[derive(Clone, Debug)] -#[repr(C)] -pub struct Group { - /// The first of the shapes - pub a: Shape3d, - - /// The second of the shapes - pub b: Shape3d, -} - -impl From for Shape { - fn from(shape: Group) -> Self { - Self::Shape3d(Shape3d::Union(Box::new(shape))) - } -} - -impl From for Shape3d { - fn from(shape: Group) -> Self { - Self::Union(Box::new(shape)) - } -} From 218dfdbae23603786db168c8e8c8710b40e0ab88 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:34:14 +0100 Subject: [PATCH 04/11] Update name of enum variant --- fj/src/shape_3d.rs | 10 +++++----- src/kernel/shapes/mod.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index afdd45dc8..800144ca0 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -4,14 +4,14 @@ use crate::{Shape, Shape2d}; #[derive(Clone, Debug)] #[repr(C)] pub enum Shape3d { + /// The union of two 3-dimensional shapes + Group(Box), + /// A sweep of 2-dimensional shape along the z-axis Sweep(Sweep), /// A transformed 3-dimensional shape Transform(Box), - - /// The union of two 3-dimensional shapes - Union(Box), } impl From for Shape { @@ -40,13 +40,13 @@ pub struct Group { impl From for Shape { fn from(shape: Group) -> Self { - Self::Shape3d(Shape3d::Union(Box::new(shape))) + Self::Shape3d(Shape3d::Group(Box::new(shape))) } } impl From for Shape3d { fn from(shape: Group) -> Self { - Self::Union(Box::new(shape)) + Self::Group(Box::new(shape)) } } diff --git a/src/kernel/shapes/mod.rs b/src/kernel/shapes/mod.rs index b3181a62d..32362eb43 100644 --- a/src/kernel/shapes/mod.rs +++ b/src/kernel/shapes/mod.rs @@ -53,9 +53,9 @@ macro_rules! dispatch { $( fn $method(&self, $($arg_name: $arg_ty,)*) -> $ret { match self { + Self::Group(shape) => shape.$method($($arg_name,)*), Self::Sweep(shape) => shape.$method($($arg_name,)*), Self::Transform(shape) => shape.$method($($arg_name,)*), - Self::Union(shape) => shape.$method($($arg_name,)*), } } )* From f1e23508ae3a408196a51d63b233123969e04d6b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:34:33 +0100 Subject: [PATCH 05/11] Update doc comment --- fj/src/shape_3d.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index 800144ca0..b9274089f 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -4,7 +4,7 @@ use crate::{Shape, Shape2d}; #[derive(Clone, Debug)] #[repr(C)] pub enum Shape3d { - /// The union of two 3-dimensional shapes + /// A group of two 3-dimensional shapes Group(Box), /// A sweep of 2-dimensional shape along the z-axis From 37402d5f4e6666834fa88f840bd67aea95b32a55 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:36:03 +0100 Subject: [PATCH 06/11] Update group syntax --- fj/src/syntax.rs | 4 ++-- models/csg-union-disjoint/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index bfc0b05c0..2a206821e 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -71,7 +71,7 @@ where } pub trait Union { - fn union(&self, other: &Other) -> crate::Group + fn group(&self, other: &Other) -> crate::Group where Other: Clone + Into; } @@ -80,7 +80,7 @@ impl Union for T where T: Clone + Into, { - fn union(&self, other: &Other) -> crate::Group + fn group(&self, other: &Other) -> crate::Group where Other: Clone + Into, { diff --git a/models/csg-union-disjoint/src/lib.rs b/models/csg-union-disjoint/src/lib.rs index bda316c43..44787073d 100644 --- a/models/csg-union-disjoint/src/lib.rs +++ b/models/csg-union-disjoint/src/lib.rs @@ -15,7 +15,7 @@ pub extern "C" fn model(_: &HashMap) -> fj::Shape { let cube_a = fj::Sketch::from_points(vertices).sweep(1.0); let cube_b = cube_a.clone().translate([1.5, 0., 0.5]); - let disjoint_union = cube_a.union(&cube_b); + let disjoint_union = cube_a.group(&cube_b); disjoint_union.into() } From 302b1e3540eb63af0be9f3f933b4904bb0bc5edc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:37:57 +0100 Subject: [PATCH 07/11] Update trait name --- fj/src/lib.rs | 2 +- fj/src/syntax.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fj/src/lib.rs b/fj/src/lib.rs index 680d1926c..44f967bbc 100644 --- a/fj/src/lib.rs +++ b/fj/src/lib.rs @@ -16,7 +16,7 @@ mod syntax; pub mod prelude { pub use crate::syntax::{ - Rotate as _, Sketch as _, Sweep as _, Translate as _, Union as _, + Group as _, Rotate as _, Sketch as _, Sweep as _, Translate as _, }; } diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index 2a206821e..7c809c713 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -70,13 +70,13 @@ where } } -pub trait Union { +pub trait Group { fn group(&self, other: &Other) -> crate::Group where Other: Clone + Into; } -impl Union for T +impl Group for T where T: Clone + Into, { From a2a4f153377b4009aa9e7f1c74d2064fcb199213 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:43:18 +0100 Subject: [PATCH 08/11] Update variable name --- models/csg-union-disjoint/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/csg-union-disjoint/src/lib.rs b/models/csg-union-disjoint/src/lib.rs index 44787073d..1c16bccec 100644 --- a/models/csg-union-disjoint/src/lib.rs +++ b/models/csg-union-disjoint/src/lib.rs @@ -15,7 +15,7 @@ pub extern "C" fn model(_: &HashMap) -> fj::Shape { let cube_a = fj::Sketch::from_points(vertices).sweep(1.0); let cube_b = cube_a.clone().translate([1.5, 0., 0.5]); - let disjoint_union = cube_a.group(&cube_b); + let group = cube_a.group(&cube_b); - disjoint_union.into() + group.into() } From 1f73fa415e72fe113f058633952cd5b7c5a99af6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:45:23 +0100 Subject: [PATCH 09/11] Update name of model --- models/csg-union-disjoint/README.md | 10 ---------- models/{csg-union-disjoint => group}/Cargo.toml | 2 +- models/group/README.md | 10 ++++++++++ .../csg-union-disjoint.png => group/group.png} | Bin models/{csg-union-disjoint => group}/src/lib.rs | 0 5 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 models/csg-union-disjoint/README.md rename models/{csg-union-disjoint => group}/Cargo.toml (78%) create mode 100644 models/group/README.md rename models/{csg-union-disjoint/csg-union-disjoint.png => group/group.png} (100%) rename models/{csg-union-disjoint => group}/src/lib.rs (100%) diff --git a/models/csg-union-disjoint/README.md b/models/csg-union-disjoint/README.md deleted file mode 100644 index 344c75907..000000000 --- a/models/csg-union-disjoint/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Fornjot - Disjoint Union - -A model that demonstrates [constructive solid geometry](https://en.wikipedia.org/wiki/Constructive_solid_geometry) (CSG) functionality, specifically the union of two disjoint bodies. - -To display this model, run the following from the repository root: -``` sh -cargo run -- --model csg-union-disjoint -``` - -![Screenshot of the disjoint union model](csg-union-disjoint.png) diff --git a/models/csg-union-disjoint/Cargo.toml b/models/group/Cargo.toml similarity index 78% rename from models/csg-union-disjoint/Cargo.toml rename to models/group/Cargo.toml index 505071e7b..7910d2980 100644 --- a/models/csg-union-disjoint/Cargo.toml +++ b/models/group/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "csg-union-disjoint" +name = "group" version = "0.1.0" edition = "2021" diff --git a/models/group/README.md b/models/group/README.md new file mode 100644 index 000000000..395f59b5f --- /dev/null +++ b/models/group/README.md @@ -0,0 +1,10 @@ +# Fornjot - Group + +A model that demonstrates groups of two disjoint bodies. + +To display this model, run the following from the repository root: +``` sh +cargo run -- --model group +``` + +![Screenshot of the group model](group.png) diff --git a/models/csg-union-disjoint/csg-union-disjoint.png b/models/group/group.png similarity index 100% rename from models/csg-union-disjoint/csg-union-disjoint.png rename to models/group/group.png diff --git a/models/csg-union-disjoint/src/lib.rs b/models/group/src/lib.rs similarity index 100% rename from models/csg-union-disjoint/src/lib.rs rename to models/group/src/lib.rs From e044d6c00433cf9894557076b479e1c42b07c1e6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:46:05 +0100 Subject: [PATCH 10/11] Remove obsolete comment --- src/kernel/shapes/union.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/kernel/shapes/union.rs b/src/kernel/shapes/union.rs index 9b2fffe25..fe63c48ff 100644 --- a/src/kernel/shapes/union.rs +++ b/src/kernel/shapes/union.rs @@ -22,11 +22,6 @@ impl ToShape for fj::Group { let a = self.a.to_shape(tolerance, debug_info); let b = self.b.to_shape(tolerance, debug_info); - // This doesn't create a true union, as it doesn't eliminate, merge, or - // split faces. - // - // See issue: - // https://github.com/hannobraun/Fornjot/issues/42 copy_shape(a, &mut shape); copy_shape(b, &mut shape); From 45a19f8a0ac2bd56950008009c30c2e62ddd0c56 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:47:31 +0100 Subject: [PATCH 11/11] Update module name --- src/kernel/shapes/{union.rs => group.rs} | 0 src/kernel/shapes/mod.rs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/kernel/shapes/{union.rs => group.rs} (100%) diff --git a/src/kernel/shapes/union.rs b/src/kernel/shapes/group.rs similarity index 100% rename from src/kernel/shapes/union.rs rename to src/kernel/shapes/group.rs diff --git a/src/kernel/shapes/mod.rs b/src/kernel/shapes/mod.rs index 32362eb43..700b07a0c 100644 --- a/src/kernel/shapes/mod.rs +++ b/src/kernel/shapes/mod.rs @@ -1,9 +1,9 @@ pub mod circle; pub mod difference_2d; +pub mod group; pub mod sketch; pub mod sweep; pub mod transform; -pub mod union; use crate::{ debug::DebugInfo,