-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from hannobraun/shape
Simplify creation of boundary representation
- Loading branch information
Showing
12 changed files
with
290 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,95 @@ | ||
use crate::{ | ||
debug::DebugInfo, | ||
kernel::{ | ||
topology::{ | ||
edges::Edges, | ||
faces::{Face, Faces}, | ||
vertices::Vertices, | ||
}, | ||
kernel::topology::{ | ||
edges::Edges, | ||
faces::{Face, Faces}, | ||
vertices::Vertices, | ||
Shape, | ||
}, | ||
math::{Aabb, Scalar}, | ||
}; | ||
|
||
impl Shape for fj::Difference2d { | ||
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.a.bounding_volume() | ||
} | ||
use super::ToShape; | ||
|
||
fn faces(&self, tolerance: Scalar, debug_info: &mut DebugInfo) -> Faces { | ||
impl ToShape for fj::Difference2d { | ||
fn to_shape(&self, tolerance: Scalar, debug_info: &mut DebugInfo) -> Shape { | ||
// This method assumes that `b` is fully contained within `a`: | ||
// https://github.com/hannobraun/Fornjot/issues/92 | ||
|
||
let mut a = self.a.faces(tolerance, debug_info); | ||
let mut b = self.b.faces(tolerance, debug_info); | ||
let mut a = self.a.to_shape(tolerance, debug_info); | ||
let mut b = self.b.to_shape(tolerance, debug_info); | ||
|
||
let (a, b) = if a.0.len() == 1 && b.0.len() == 1 { | ||
// Can't panic. We just checked that length of `a` and `b` is 1. | ||
(a.0.pop().unwrap(), b.0.pop().unwrap()) | ||
} else { | ||
// See issue: | ||
// https://github.com/hannobraun/Fornjot/issues/95 | ||
todo!( | ||
"The 2-dimensional difference operation only supports one face \ | ||
in each operand." | ||
); | ||
}; | ||
let edges = { | ||
let (a, b) = if a.edges.cycles.len() == 1 | ||
&& b.edges.cycles.len() == 1 | ||
{ | ||
(a.edges.cycles.pop().unwrap(), b.edges.cycles.pop().unwrap()) | ||
} else { | ||
// See issue: | ||
// https://github.com/hannobraun/Fornjot/issues/95 | ||
todo!( | ||
"The 2-dimensional difference operation only supports one \ | ||
cycle in each operand." | ||
); | ||
}; | ||
|
||
let (a, b, surface_a, surface_b) = match (a, b) { | ||
( | ||
Face::Face { | ||
edges: a, | ||
surface: surface_a, | ||
}, | ||
Face::Face { | ||
edges: b, | ||
surface: surface_b, | ||
}, | ||
) => (a, b, surface_a, surface_b), | ||
_ => { | ||
// None of the 2D types still use the triangles representation. | ||
unreachable!() | ||
} | ||
Edges { cycles: vec![a, b] } | ||
}; | ||
|
||
if surface_a != surface_b { | ||
// Panicking is not great, but as long as we don't have a real error | ||
// handling mechanism, it will do. | ||
panic!("Trying to subtract sketches with different surfaces.") | ||
} | ||
let surface = surface_a; | ||
|
||
let mut edges = a; | ||
edges.cycles.extend(b.cycles); | ||
let faces = { | ||
let (a, b) = if a.faces.0.len() == 1 && b.faces.0.len() == 1 { | ||
// Can't panic. We just checked that length of `a` and `b` is 1. | ||
(a.faces.0.pop().unwrap(), b.faces.0.pop().unwrap()) | ||
} else { | ||
// See issue: | ||
// https://github.com/hannobraun/Fornjot/issues/95 | ||
todo!( | ||
"The 2-dimensional difference operation only supports one \ | ||
face in each operand." | ||
); | ||
}; | ||
|
||
Faces(vec![Face::Face { edges, surface }]) | ||
} | ||
let (a, b, surface_a, surface_b) = match (a, b) { | ||
( | ||
Face::Face { | ||
edges: a, | ||
surface: surface_a, | ||
}, | ||
Face::Face { | ||
edges: b, | ||
surface: surface_b, | ||
}, | ||
) => (a, b, surface_a, surface_b), | ||
_ => { | ||
// None of the 2D types still use the triangles representation. | ||
unreachable!() | ||
} | ||
}; | ||
|
||
fn edges(&self) -> Edges { | ||
// This method assumes that `b` is fully contained within `a`: | ||
// https://github.com/hannobraun/Fornjot/issues/92 | ||
if surface_a != surface_b { | ||
// Panicking is not great, but as long as we don't have a real | ||
// error handling mechanism, it will do. | ||
panic!("Trying to subtract sketches with different surfaces.") | ||
} | ||
let surface = surface_a; | ||
|
||
let mut a = self.a.edges(); | ||
let mut b = self.b.edges(); | ||
let mut edges = a; | ||
edges.cycles.extend(b.cycles); | ||
|
||
let (a, b) = if a.cycles.len() == 1 && b.cycles.len() == 1 { | ||
(a.cycles.pop().unwrap(), b.cycles.pop().unwrap()) | ||
} else { | ||
// See issue: | ||
// https://github.com/hannobraun/Fornjot/issues/95 | ||
todo!( | ||
"The 2-dimensional difference operation only supports one \ | ||
cycle in each operand." | ||
); | ||
Faces(vec![Face::Face { edges, surface }]) | ||
}; | ||
|
||
Edges { cycles: vec![a, b] } | ||
Shape { | ||
vertices: Vertices(Vec::new()), | ||
edges, | ||
faces, | ||
} | ||
} | ||
|
||
fn vertices(&self) -> Vertices { | ||
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.a.bounding_volume() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
use crate::{ | ||
debug::DebugInfo, | ||
kernel::{ | ||
topology::{edges::Edges, faces::Faces, vertices::Vertices}, | ||
Shape, | ||
}, | ||
kernel::topology::{edges::Edges, faces::Faces, vertices::Vertices, Shape}, | ||
math::{Aabb, Scalar}, | ||
}; | ||
|
||
impl Shape for fj::Difference { | ||
use super::ToShape; | ||
|
||
impl ToShape for fj::Difference { | ||
fn to_shape(&self, _: Scalar, _: &mut DebugInfo) -> Shape { | ||
Shape { | ||
vertices: Vertices(Vec::new()), | ||
edges: Edges { cycles: Vec::new() }, | ||
faces: Faces(Vec::new()), | ||
} | ||
} | ||
|
||
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.a.bounding_volume() | ||
} | ||
|
||
fn faces(&self, _tolerance: Scalar, _: &mut DebugInfo) -> Faces { | ||
todo!() | ||
} | ||
|
||
fn edges(&self) -> Edges { | ||
todo!() | ||
} | ||
|
||
fn vertices(&self) -> Vertices { | ||
todo!() | ||
} | ||
} |
Oops, something went wrong.