mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-25 16:45:52 +00:00
Merge pull request #366 from hannobraun/group
Rename `fj::Union` to `fj::Group`
This commit is contained in:
commit
4addd99245
@ -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 _,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,14 +4,14 @@ use crate::{Shape, Shape2d};
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub enum Shape3d {
|
||||
/// A group of two 3-dimensional shapes
|
||||
Group(Box<Group>),
|
||||
|
||||
/// A sweep of 2-dimensional shape along the z-axis
|
||||
Sweep(Sweep),
|
||||
|
||||
/// A transformed 3-dimensional shape
|
||||
Transform(Box<Transform>),
|
||||
|
||||
/// The union of two 3-dimensional shapes
|
||||
Union(Box<Union>),
|
||||
}
|
||||
|
||||
impl From<Shape3d> for Shape {
|
||||
@ -20,6 +20,36 @@ impl From<Shape3d> 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<Group> for Shape {
|
||||
fn from(shape: Group) -> Self {
|
||||
Self::Shape3d(Shape3d::Group(Box::new(shape)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Group> for Shape3d {
|
||||
fn from(shape: Group) -> Self {
|
||||
Self::Group(Box::new(shape))
|
||||
}
|
||||
}
|
||||
|
||||
/// A transformed 3-dimensional shape
|
||||
///
|
||||
/// # Limitations
|
||||
@ -97,39 +127,3 @@ impl From<Sweep> for Shape3d {
|
||||
Self::Sweep(shape)
|
||||
}
|
||||
}
|
||||
|
||||
/// The union 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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// See issue:
|
||||
/// <https://github.com/hannobraun/Fornjot/issues/42>
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Union {
|
||||
/// The first of the shapes
|
||||
pub a: Shape3d,
|
||||
|
||||
/// The second of the shapes
|
||||
pub b: Shape3d,
|
||||
}
|
||||
|
||||
impl From<Union> for Shape {
|
||||
fn from(shape: Union) -> Self {
|
||||
Self::Shape3d(Shape3d::Union(Box::new(shape)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Union> for Shape3d {
|
||||
fn from(shape: Union) -> Self {
|
||||
Self::Union(Box::new(shape))
|
||||
}
|
||||
}
|
||||
|
@ -70,23 +70,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Union {
|
||||
fn union<Other>(&self, other: &Other) -> crate::Union
|
||||
pub trait Group {
|
||||
fn group<Other>(&self, other: &Other) -> crate::Group
|
||||
where
|
||||
Other: Clone + Into<crate::Shape3d>;
|
||||
}
|
||||
|
||||
impl<T> Union for T
|
||||
impl<T> Group for T
|
||||
where
|
||||
T: Clone + Into<crate::Shape3d>,
|
||||
{
|
||||
fn union<Other>(&self, other: &Other) -> crate::Union
|
||||
fn group<Other>(&self, other: &Other) -> crate::Group
|
||||
where
|
||||
Other: Clone + Into<crate::Shape3d>,
|
||||
{
|
||||
let a = self.clone().into();
|
||||
let b = other.clone().into();
|
||||
|
||||
crate::Union { a, b }
|
||||
crate::Group { a, b }
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
```
|
||||
|
||||

|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "csg-union-disjoint"
|
||||
name = "group"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
10
models/group/README.md
Normal file
10
models/group/README.md
Normal file
@ -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
|
||||
```
|
||||
|
||||

|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
@ -15,7 +15,7 @@ pub extern "C" fn model(_: &HashMap<String, String>) -> 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 group = cube_a.group(&cube_b);
|
||||
|
||||
disjoint_union.into()
|
||||
group.into()
|
||||
}
|
@ -15,18 +15,13 @@ 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();
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
@ -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,)*),
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
Loading…
Reference in New Issue
Block a user