Skip to content

Commit

Permalink
WIP Add fj::Difference3d
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed May 6, 2022
1 parent c47285e commit 52f995d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/fj-operations/src/difference_3d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use fj_interop::debug::DebugInfo;
use fj_kernel::{algorithms::Tolerance, shape::Shape};
use fj_math::Aabb;

use super::ToShape;

impl ToShape for fj::Difference3d {
fn to_shape(
&self,
_tolerance: Tolerance,
_debug_info: &mut DebugInfo,
) -> Shape {
// TASK: Implement algorithm from "Boundary Representation Modelling
// Techniques", section 6.1.1 (pages 127 ff.).

// TASK: Find interactions between objects by comparing each face in one
// with each face in the other.
// TASK: Check for intersection between the surfaces of each face. This
// might result in a curve where they intersect.
// TASK: Check that curve against the faces, to find curve sections that
// lie in the faces.
// TASK: Find common curve sections that lie in both faces.
// TASK: Add common curve sections to faces. (What does that mean
// specifically? Are we creating a new edge, and therefore new
// faces, there?)

// TASK: Implement.
todo!()
}

fn bounding_volume(&self) -> Aabb<3> {
// This is a conservative estimate of the bounding box: It's never going
// to be bigger than the bounding box of the original shape that another
// is being subtracted from.
self.shapes()[0].bounding_volume()
}
}
3 changes: 3 additions & 0 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod shape_processor;

mod circle;
mod difference_2d;
mod difference_3d;
mod group;
mod sketch;
mod sweep;
Expand Down Expand Up @@ -70,6 +71,8 @@ macro_rules! dispatch {
$(
fn $method(&self, $($arg_name: $arg_ty,)*) -> $ret {
match self {
Self::Difference(shape) =>
shape.$method($($arg_name,)*),
Self::Group(shape) => shape.$method($($arg_name,)*),
Self::Sweep(shape) => shape.$method($($arg_name,)*),
Self::Transform(shape) => shape.$method($($arg_name,)*),
Expand Down
34 changes: 34 additions & 0 deletions crates/fj/src/shape_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use crate::{Shape, Shape2d};
#[derive(Clone, Debug)]
#[repr(C)]
pub enum Shape3d {
/// A difference between two shapes
Difference(Box<Difference3d>),

/// A group of two 3-dimensional shapes
Group(Box<Group>),

Expand All @@ -20,6 +23,37 @@ impl From<Shape3d> for Shape {
}
}

/// A difference between two shapes
#[derive(Clone, Debug)]
#[repr(C)]
pub struct Difference3d {
shapes: [Shape3d; 2],
}

impl Difference3d {
/// Create a `Difference3d` from two shapes
pub fn from_shapes(shapes: [Shape3d; 2]) -> Self {
Self { shapes }
}

/// Access the shapes that make up the difference
pub fn shapes(&self) -> &[Shape3d; 2] {
&self.shapes
}
}

impl From<Difference3d> for Shape {
fn from(shape: Difference3d) -> Self {
Self::Shape3d(shape.into())
}
}

impl From<Difference3d> for Shape3d {
fn from(shape: Difference3d) -> Self {
Self::Difference(Box::new(shape))
}
}

/// A group of two 3-dimensional shapes
///
/// A group is a collection of disjoint shapes. It is not a union, in that the
Expand Down

0 comments on commit 52f995d

Please sign in to comment.