mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-18 06:06:09 +00:00
Merge pull request #1201 from hannobraun/planes
Remove redundant argument from `Shape::compute_brep`
This commit is contained in:
commit
3de803041d
@ -9,8 +9,6 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::Aabb;
|
use fj_math::Aabb;
|
||||||
|
|
||||||
use crate::planes::Planes;
|
|
||||||
|
|
||||||
use super::Shape;
|
use super::Shape;
|
||||||
|
|
||||||
impl Shape for fj::Difference2d {
|
impl Shape for fj::Difference2d {
|
||||||
@ -20,7 +18,6 @@ impl Shape for fj::Difference2d {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
// This method assumes that `b` is fully contained within `a`:
|
// This method assumes that `b` is fully contained within `a`:
|
||||||
@ -35,9 +32,8 @@ impl Shape for fj::Difference2d {
|
|||||||
// - https://doc.rust-lang.org/std/primitive.array.html#method.each_ref
|
// - https://doc.rust-lang.org/std/primitive.array.html#method.each_ref
|
||||||
// - https://doc.rust-lang.org/std/primitive.array.html#method.try_map
|
// - https://doc.rust-lang.org/std/primitive.array.html#method.try_map
|
||||||
let [a, b] = self.shapes();
|
let [a, b] = self.shapes();
|
||||||
let [a, b] = [a, b].map(|shape| {
|
let [a, b] =
|
||||||
shape.compute_brep(config, objects, planes, debug_info)
|
[a, b].map(|shape| shape.compute_brep(config, objects, debug_info));
|
||||||
});
|
|
||||||
let [a, b] = [a?, b?];
|
let [a, b] = [a?, b?];
|
||||||
|
|
||||||
if let Some(face) = a.face_iter().next() {
|
if let Some(face) = a.face_iter().next() {
|
||||||
|
@ -7,8 +7,6 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::Aabb;
|
use fj_math::Aabb;
|
||||||
|
|
||||||
use crate::planes::Planes;
|
|
||||||
|
|
||||||
use super::Shape;
|
use super::Shape;
|
||||||
|
|
||||||
impl Shape for fj::Group {
|
impl Shape for fj::Group {
|
||||||
@ -18,13 +16,12 @@ impl Shape for fj::Group {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
let mut faces = Faces::new();
|
let mut faces = Faces::new();
|
||||||
|
|
||||||
let a = self.a.compute_brep(config, objects, planes, debug_info)?;
|
let a = self.a.compute_brep(config, objects, debug_info)?;
|
||||||
let b = self.b.compute_brep(config, objects, planes, debug_info)?;
|
let b = self.b.compute_brep(config, objects, debug_info)?;
|
||||||
|
|
||||||
faces.extend(a.into_inner());
|
faces.extend(a.into_inner());
|
||||||
faces.extend(b.into_inner());
|
faces.extend(b.into_inner());
|
||||||
|
@ -20,13 +20,10 @@ pub mod shape_processor;
|
|||||||
|
|
||||||
mod difference_2d;
|
mod difference_2d;
|
||||||
mod group;
|
mod group;
|
||||||
mod planes;
|
|
||||||
mod sketch;
|
mod sketch;
|
||||||
mod sweep;
|
mod sweep;
|
||||||
mod transform;
|
mod transform;
|
||||||
|
|
||||||
pub use self::planes::Planes;
|
|
||||||
|
|
||||||
use fj_interop::debug::DebugInfo;
|
use fj_interop::debug::DebugInfo;
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::validate::{
|
algorithms::validate::{
|
||||||
@ -46,7 +43,6 @@ pub trait Shape {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError>;
|
) -> Result<Validated<Self::Brep>, ValidationError>;
|
||||||
|
|
||||||
@ -64,20 +60,19 @@ impl Shape for fj::Shape {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
match self {
|
match self {
|
||||||
Self::Shape2d(shape) => shape
|
Self::Shape2d(shape) => shape
|
||||||
.compute_brep(config, objects, planes, debug_info)?
|
.compute_brep(config, objects, debug_info)?
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.into_faces()
|
.into_faces()
|
||||||
.validate_with_config(config),
|
.validate_with_config(config),
|
||||||
Self::Group(shape) => {
|
Self::Group(shape) => {
|
||||||
shape.compute_brep(config, objects, planes, debug_info)
|
shape.compute_brep(config, objects, debug_info)
|
||||||
}
|
}
|
||||||
Self::Sweep(shape) => shape
|
Self::Sweep(shape) => shape
|
||||||
.compute_brep(config, objects, planes, debug_info)?
|
.compute_brep(config, objects, debug_info)?
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.into_shells()
|
.into_shells()
|
||||||
.map(|shell| shell.into_faces())
|
.map(|shell| shell.into_faces())
|
||||||
@ -88,7 +83,7 @@ impl Shape for fj::Shape {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.validate_with_config(config),
|
.validate_with_config(config),
|
||||||
Self::Transform(shape) => {
|
Self::Transform(shape) => {
|
||||||
shape.compute_brep(config, objects, planes, debug_info)
|
shape.compute_brep(config, objects, debug_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,15 +105,14 @@ impl Shape for fj::Shape2d {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
match self {
|
match self {
|
||||||
Self::Difference(shape) => {
|
Self::Difference(shape) => {
|
||||||
shape.compute_brep(config, objects, planes, debug_info)
|
shape.compute_brep(config, objects, debug_info)
|
||||||
}
|
}
|
||||||
Self::Sketch(shape) => {
|
Self::Sketch(shape) => {
|
||||||
shape.compute_brep(config, objects, planes, debug_info)
|
shape.compute_brep(config, objects, debug_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
use fj_kernel::{
|
|
||||||
objects::{Objects, Surface},
|
|
||||||
storage::Handle,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The static planes
|
|
||||||
///
|
|
||||||
/// Keeps [`Handle`]s to the xy-, xz- and yz-planes. The purpose of this struct
|
|
||||||
/// is to provide these handles to implementations of [`Shape`], so they don't
|
|
||||||
/// have to create a duplicate `Surface` whenever they need one of those.
|
|
||||||
///
|
|
||||||
/// [`Shape`]: crate::Shape
|
|
||||||
pub struct Planes {
|
|
||||||
xy: Handle<Surface>,
|
|
||||||
xz: Handle<Surface>,
|
|
||||||
yz: Handle<Surface>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Planes {
|
|
||||||
/// Create a new instance of `Planes`
|
|
||||||
///
|
|
||||||
/// Please note that the whole point of this struct is to not duplicate the
|
|
||||||
/// standard planes, and creating multiple instances of it defeats that
|
|
||||||
/// point.
|
|
||||||
///
|
|
||||||
/// Create one instance of this struct, then share it everywhere it's
|
|
||||||
/// needed.
|
|
||||||
pub fn new(objects: &Objects) -> Self {
|
|
||||||
let xy = objects.surfaces.xy_plane();
|
|
||||||
let xz = objects.surfaces.xz_plane();
|
|
||||||
let yz = objects.surfaces.yz_plane();
|
|
||||||
|
|
||||||
Self { xy, xz, yz }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Access the xy-plane
|
|
||||||
pub fn xy(&self) -> Handle<Surface> {
|
|
||||||
self.xy.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Access the xz-plane
|
|
||||||
pub fn xz(&self) -> Handle<Surface> {
|
|
||||||
self.xz.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Access the yz-plane
|
|
||||||
pub fn yz(&self) -> Handle<Surface> {
|
|
||||||
self.yz.clone()
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::Scalar;
|
use fj_math::Scalar;
|
||||||
|
|
||||||
use crate::{planes::Planes, Shape as _};
|
use crate::Shape as _;
|
||||||
|
|
||||||
/// Processes an [`fj::Shape`] into a [`ProcessedShape`]
|
/// Processes an [`fj::Shape`] into a [`ProcessedShape`]
|
||||||
pub struct ShapeProcessor {
|
pub struct ShapeProcessor {
|
||||||
@ -44,10 +44,8 @@ impl ShapeProcessor {
|
|||||||
|
|
||||||
let config = ValidationConfig::default();
|
let config = ValidationConfig::default();
|
||||||
let objects = Objects::new();
|
let objects = Objects::new();
|
||||||
let planes = Planes::new(&objects);
|
|
||||||
let mut debug_info = DebugInfo::new();
|
let mut debug_info = DebugInfo::new();
|
||||||
let shape =
|
let shape = shape.compute_brep(&config, &objects, &mut debug_info)?;
|
||||||
shape.compute_brep(&config, &objects, &planes, &mut debug_info)?;
|
|
||||||
let mesh = (&shape.into_inner(), tolerance).triangulate();
|
let mesh = (&shape.into_inner(), tolerance).triangulate();
|
||||||
|
|
||||||
Ok(ProcessedShape {
|
Ok(ProcessedShape {
|
||||||
|
@ -8,8 +8,6 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::{Aabb, Point};
|
use fj_math::{Aabb, Point};
|
||||||
|
|
||||||
use crate::planes::Planes;
|
|
||||||
|
|
||||||
use super::Shape;
|
use super::Shape;
|
||||||
|
|
||||||
impl Shape for fj::Sketch {
|
impl Shape for fj::Sketch {
|
||||||
@ -19,10 +17,9 @@ impl Shape for fj::Sketch {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
_: &mut DebugInfo,
|
_: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
let surface = planes.xy();
|
let surface = objects.surfaces.xy_plane();
|
||||||
|
|
||||||
let face = match self.chain() {
|
let face = match self.chain() {
|
||||||
fj::Chain::Circle(circle) => {
|
fj::Chain::Circle(circle) => {
|
||||||
|
@ -8,8 +8,6 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::{Aabb, Vector};
|
use fj_math::{Aabb, Vector};
|
||||||
|
|
||||||
use crate::planes::Planes;
|
|
||||||
|
|
||||||
use super::Shape;
|
use super::Shape;
|
||||||
|
|
||||||
impl Shape for fj::Sweep {
|
impl Shape for fj::Sweep {
|
||||||
@ -19,12 +17,9 @@ impl Shape for fj::Sweep {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
let sketch = self
|
let sketch = self.shape().compute_brep(config, objects, debug_info)?;
|
||||||
.shape()
|
|
||||||
.compute_brep(config, objects, planes, debug_info)?;
|
|
||||||
let path = Vector::from(self.path());
|
let path = Vector::from(self.path());
|
||||||
|
|
||||||
let solid = sketch.into_inner().sweep(path, objects);
|
let solid = sketch.into_inner().sweep(path, objects);
|
||||||
|
@ -8,8 +8,6 @@ use fj_kernel::{
|
|||||||
};
|
};
|
||||||
use fj_math::{Aabb, Transform, Vector};
|
use fj_math::{Aabb, Transform, Vector};
|
||||||
|
|
||||||
use crate::planes::Planes;
|
|
||||||
|
|
||||||
use super::Shape;
|
use super::Shape;
|
||||||
|
|
||||||
impl Shape for fj::Transform {
|
impl Shape for fj::Transform {
|
||||||
@ -19,12 +17,11 @@ impl Shape for fj::Transform {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
objects: &Objects,
|
objects: &Objects,
|
||||||
planes: &Planes,
|
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Self::Brep>, ValidationError> {
|
) -> Result<Validated<Self::Brep>, ValidationError> {
|
||||||
let faces = self
|
let faces = self
|
||||||
.shape
|
.shape
|
||||||
.compute_brep(config, objects, planes, debug_info)?
|
.compute_brep(config, objects, debug_info)?
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.transform(&make_transform(self), objects);
|
.transform(&make_transform(self), objects);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user