mirror of https://github.com/hannobraun/Fornjot
Return `Vec<Face>` from `ToShape::to_shape`
This commit is contained in:
parent
c437a02ac8
commit
8b1ecfe95f
|
@ -15,7 +15,7 @@ impl ToShape for fj::Circle {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
_: Tolerance,
|
_: Tolerance,
|
||||||
_: &mut DebugInfo,
|
_: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
let mut shape = Shape::new();
|
let mut shape = Shape::new();
|
||||||
|
|
||||||
// Circles have just a single round edge with no vertices. So none need
|
// Circles have just a single round edge with no vertices. So none need
|
||||||
|
@ -30,14 +30,16 @@ impl ToShape for fj::Circle {
|
||||||
let cycle_canonical = shape.insert(Cycle::new(vec![edge.canonical()]));
|
let cycle_canonical = shape.insert(Cycle::new(vec![edge.canonical()]));
|
||||||
|
|
||||||
let surface = shape.insert(Surface::xy_plane());
|
let surface = shape.insert(Surface::xy_plane());
|
||||||
shape.insert(Face::new(
|
let face = shape
|
||||||
surface,
|
.insert(Face::new(
|
||||||
vec![LocalForm::new(cycle_local, cycle_canonical)],
|
surface,
|
||||||
Vec::new(),
|
vec![LocalForm::new(cycle_local, cycle_canonical)],
|
||||||
self.color(),
|
Vec::new(),
|
||||||
));
|
self.color(),
|
||||||
|
))
|
||||||
|
.get();
|
||||||
|
|
||||||
let shape = validate(shape, config)?;
|
let shape = validate(vec![face], config)?;
|
||||||
|
|
||||||
Ok(shape)
|
Ok(shape)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ impl ToShape for fj::Difference2d {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
// This method assumes that `b` is fully contained within `a`:
|
// This method assumes that `b` is fully contained within `a`:
|
||||||
// https://github.com/hannobraun/Fornjot/issues/92
|
// https://github.com/hannobraun/Fornjot/issues/92
|
||||||
|
|
||||||
let mut difference = Shape::new();
|
let mut difference = Vec::new();
|
||||||
|
|
||||||
let mut exteriors = Vec::new();
|
let mut exteriors = Vec::new();
|
||||||
let mut interiors = Vec::new();
|
let mut interiors = Vec::new();
|
||||||
|
@ -72,7 +72,7 @@ impl ToShape for fj::Difference2d {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
difference.merge(Face::new(
|
difference.push(Face::new(
|
||||||
surface,
|
surface,
|
||||||
exteriors,
|
exteriors,
|
||||||
interiors,
|
interiors,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use fj_interop::debug::DebugInfo;
|
use fj_interop::debug::DebugInfo;
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::Tolerance,
|
algorithms::Tolerance,
|
||||||
shape::Shape,
|
objects::Face,
|
||||||
validation::{validate, Validated, ValidationConfig, ValidationError},
|
validation::{validate, Validated, ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::Aabb;
|
use fj_math::Aabb;
|
||||||
|
@ -14,14 +14,14 @@ impl ToShape for fj::Group {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
let mut shape = Shape::new();
|
let mut shape = Vec::new();
|
||||||
|
|
||||||
let a = self.a.to_shape(config, tolerance, debug_info)?;
|
let a = self.a.to_shape(config, tolerance, debug_info)?;
|
||||||
let b = self.b.to_shape(config, tolerance, debug_info)?;
|
let b = self.b.to_shape(config, tolerance, debug_info)?;
|
||||||
|
|
||||||
shape.merge_shape(&a);
|
shape.extend(a.into_inner());
|
||||||
shape.merge_shape(&b);
|
shape.extend(b.into_inner());
|
||||||
|
|
||||||
let shape = validate(shape, config)?;
|
let shape = validate(shape, config)?;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ mod transform;
|
||||||
use fj_interop::debug::DebugInfo;
|
use fj_interop::debug::DebugInfo;
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::Tolerance,
|
algorithms::Tolerance,
|
||||||
shape::Shape,
|
objects::Face,
|
||||||
validation::{Validated, ValidationConfig, ValidationError},
|
validation::{Validated, ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::Aabb;
|
use fj_math::Aabb;
|
||||||
|
@ -41,7 +41,7 @@ pub trait ToShape {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError>;
|
) -> Result<Validated<Vec<Face>>, ValidationError>;
|
||||||
|
|
||||||
/// Access the axis-aligned bounding box of a shape
|
/// Access the axis-aligned bounding box of a shape
|
||||||
///
|
///
|
||||||
|
@ -94,6 +94,6 @@ dispatch! {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError>;
|
) -> Result<Validated<Vec<Face>>, ValidationError>;
|
||||||
bounding_volume() -> Aabb<3>;
|
bounding_volume() -> Aabb<3>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::{triangulate, InvalidTolerance, Tolerance},
|
algorithms::{triangulate, InvalidTolerance, Tolerance},
|
||||||
iter::ObjectIters,
|
|
||||||
validation::{ValidationConfig, ValidationError},
|
validation::{ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::{Aabb, Point, Scalar};
|
use fj_math::{Aabb, Point, Scalar};
|
||||||
|
@ -41,11 +40,8 @@ impl ShapeProcessor {
|
||||||
|
|
||||||
let config = ValidationConfig::default();
|
let config = ValidationConfig::default();
|
||||||
let mut debug_info = DebugInfo::new();
|
let mut debug_info = DebugInfo::new();
|
||||||
let shape = shape
|
let shape = shape.to_shape(&config, tolerance, &mut debug_info)?;
|
||||||
.to_shape(&config, tolerance, &mut debug_info)?
|
let mesh = triangulate(shape.into_inner(), tolerance, &mut debug_info);
|
||||||
.face_iter()
|
|
||||||
.collect();
|
|
||||||
let mesh = triangulate(shape, tolerance, &mut debug_info);
|
|
||||||
|
|
||||||
Ok(ProcessedShape {
|
Ok(ProcessedShape {
|
||||||
aabb,
|
aabb,
|
||||||
|
|
|
@ -15,18 +15,19 @@ impl ToShape for fj::Sketch {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
_: Tolerance,
|
_: Tolerance,
|
||||||
_: &mut DebugInfo,
|
_: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
let mut shape = Shape::new();
|
let mut shape = Shape::new();
|
||||||
|
|
||||||
let surface = Surface::xy_plane();
|
let surface = Surface::xy_plane();
|
||||||
let points = self.to_points().into_iter().map(Point::from);
|
let points = self.to_points().into_iter().map(Point::from);
|
||||||
|
|
||||||
Face::builder(surface, &mut shape)
|
let sketch = Face::builder(surface, &mut shape)
|
||||||
.with_exterior_polygon(points)
|
.with_exterior_polygon(points)
|
||||||
.with_color(self.color())
|
.with_color(self.color())
|
||||||
.build();
|
.build()
|
||||||
|
.get();
|
||||||
|
|
||||||
let shape = validate(shape, config)?;
|
let shape = validate(vec![sketch], config)?;
|
||||||
|
|
||||||
Ok(shape)
|
Ok(shape)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use fj_interop::debug::DebugInfo;
|
use fj_interop::debug::DebugInfo;
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::{sweep, Tolerance},
|
algorithms::{sweep, Tolerance},
|
||||||
iter::ObjectIters,
|
objects::Face,
|
||||||
shape::Shape,
|
|
||||||
validation::{validate, Validated, ValidationConfig, ValidationError},
|
validation::{validate, Validated, ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::{Aabb, Vector};
|
use fj_math::{Aabb, Vector};
|
||||||
|
@ -15,20 +14,14 @@ impl ToShape for fj::Sweep {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
let shape = self.shape().to_shape(config, tolerance, debug_info)?;
|
let shape = self.shape().to_shape(config, tolerance, debug_info)?;
|
||||||
let path = Vector::from(self.path());
|
let path = Vector::from(self.path());
|
||||||
let color = self.shape().color();
|
let color = self.shape().color();
|
||||||
|
|
||||||
let shape = shape.face_iter().collect::<Vec<_>>();
|
let swept = sweep(shape.into_inner(), path, tolerance, color);
|
||||||
let swept = sweep(shape, path, tolerance, color);
|
|
||||||
|
|
||||||
let mut shape = Shape::new();
|
let swept = validate(swept, config)?;
|
||||||
for face in swept {
|
|
||||||
shape.merge(face);
|
|
||||||
}
|
|
||||||
|
|
||||||
let swept = validate(shape, config)?;
|
|
||||||
|
|
||||||
Ok(swept)
|
Ok(swept)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use fj_interop::debug::DebugInfo;
|
use fj_interop::debug::DebugInfo;
|
||||||
use fj_kernel::{
|
use fj_kernel::{
|
||||||
algorithms::{transform, Tolerance},
|
algorithms::{transform, Tolerance},
|
||||||
iter::ObjectIters,
|
objects::Face,
|
||||||
shape::Shape,
|
|
||||||
validation::{validate, Validated, ValidationConfig, ValidationError},
|
validation::{validate, Validated, ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::{Aabb, Transform, Vector};
|
use fj_math::{Aabb, Transform, Vector};
|
||||||
|
@ -15,19 +14,13 @@ impl ToShape for fj::Transform {
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
tolerance: Tolerance,
|
tolerance: Tolerance,
|
||||||
debug_info: &mut DebugInfo,
|
debug_info: &mut DebugInfo,
|
||||||
) -> Result<Validated<Shape>, ValidationError> {
|
) -> Result<Validated<Vec<Face>>, ValidationError> {
|
||||||
let shape = self.shape.to_shape(config, tolerance, debug_info)?;
|
let shape = self.shape.to_shape(config, tolerance, debug_info)?;
|
||||||
let shape = shape.into_inner();
|
let shape = shape.into_inner();
|
||||||
|
|
||||||
let shape = shape.face_iter().collect::<Vec<_>>();
|
|
||||||
let faces = transform(&shape, &make_transform(self));
|
let faces = transform(&shape, &make_transform(self));
|
||||||
|
|
||||||
let mut target = Shape::new();
|
let shape = validate(faces, config)?;
|
||||||
for face in faces {
|
|
||||||
target.merge(face);
|
|
||||||
}
|
|
||||||
|
|
||||||
let shape = validate(target, config)?;
|
|
||||||
|
|
||||||
Ok(shape)
|
Ok(shape)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue