mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-07 07:45:52 +00:00
Move ShapeProcessor
to fj-operations
It can't stay in `fj-app`, as the export code (which I intend to move into its own crate) depends on it. I think `fj-operations` is a good place for it, as the code that's already there has practically the same dependencies as `ShapeProcessor`.
This commit is contained in:
parent
3156ae2624
commit
fc408cdcc7
@ -10,10 +10,7 @@ use std::time::Instant;
|
|||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use fj_host::{Model, Parameters};
|
use fj_host::{Model, Parameters};
|
||||||
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
use fj_operations::shape_processor::ShapeProcessor;
|
||||||
use fj_kernel::algorithms::{triangulate, Tolerance};
|
|
||||||
use fj_math::{Aabb, Point, Scalar};
|
|
||||||
use fj_operations::ToShape as _;
|
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use tracing::{trace, warn};
|
use tracing::{trace, warn};
|
||||||
use tracing_subscriber::fmt::format;
|
use tracing_subscriber::fmt::format;
|
||||||
@ -224,50 +221,3 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ShapeProcessor {
|
|
||||||
tolerance: Option<Tolerance>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ShapeProcessor {
|
|
||||||
fn process(&self, shape: &fj::Shape) -> ProcessedShape {
|
|
||||||
let aabb = shape.bounding_volume();
|
|
||||||
|
|
||||||
let tolerance = match self.tolerance {
|
|
||||||
None => {
|
|
||||||
// Compute a reasonable default for the tolerance value. To do
|
|
||||||
// this, we just look at the smallest non-zero extent of the
|
|
||||||
// bounding box and divide that by some value.
|
|
||||||
let mut min_extent = Scalar::MAX;
|
|
||||||
for extent in aabb.size().components {
|
|
||||||
if extent > Scalar::ZERO && extent < min_extent {
|
|
||||||
min_extent = extent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let tolerance = min_extent / Scalar::from_f64(1000.);
|
|
||||||
Tolerance::from_scalar(tolerance).unwrap()
|
|
||||||
}
|
|
||||||
Some(user_defined_tolerance) => user_defined_tolerance,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_info = DebugInfo::new();
|
|
||||||
let mesh = triangulate(
|
|
||||||
shape.to_shape(tolerance, &mut debug_info),
|
|
||||||
tolerance,
|
|
||||||
&mut debug_info,
|
|
||||||
);
|
|
||||||
|
|
||||||
ProcessedShape {
|
|
||||||
aabb,
|
|
||||||
mesh,
|
|
||||||
debug_info,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ProcessedShape {
|
|
||||||
aabb: Aabb<3>,
|
|
||||||
mesh: Mesh<Point<3>>,
|
|
||||||
debug_info: DebugInfo,
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
pub mod shape_processor;
|
||||||
|
|
||||||
mod circle;
|
mod circle;
|
||||||
mod difference_2d;
|
mod difference_2d;
|
||||||
mod group;
|
mod group;
|
||||||
|
65
fj-operations/src/shape_processor.rs
Normal file
65
fj-operations/src/shape_processor.rs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
//! API for processing shapes
|
||||||
|
|
||||||
|
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
||||||
|
use fj_kernel::algorithms::{triangulate, Tolerance};
|
||||||
|
use fj_math::{Aabb, Point, Scalar};
|
||||||
|
|
||||||
|
use crate::ToShape as _;
|
||||||
|
|
||||||
|
/// Processes an [`fj::Shape`] into a [`ProcessedShape`]
|
||||||
|
pub struct ShapeProcessor {
|
||||||
|
/// The tolerance value used for creating the triangle mesh
|
||||||
|
pub tolerance: Option<Tolerance>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShapeProcessor {
|
||||||
|
/// Process an [`fj::Shape`] into [`ProcessedShape`]
|
||||||
|
pub fn process(&self, shape: &fj::Shape) -> ProcessedShape {
|
||||||
|
let aabb = shape.bounding_volume();
|
||||||
|
|
||||||
|
let tolerance = match self.tolerance {
|
||||||
|
None => {
|
||||||
|
// Compute a reasonable default for the tolerance value. To do
|
||||||
|
// this, we just look at the smallest non-zero extent of the
|
||||||
|
// bounding box and divide that by some value.
|
||||||
|
let mut min_extent = Scalar::MAX;
|
||||||
|
for extent in aabb.size().components {
|
||||||
|
if extent > Scalar::ZERO && extent < min_extent {
|
||||||
|
min_extent = extent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let tolerance = min_extent / Scalar::from_f64(1000.);
|
||||||
|
Tolerance::from_scalar(tolerance).unwrap()
|
||||||
|
}
|
||||||
|
Some(user_defined_tolerance) => user_defined_tolerance,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut debug_info = DebugInfo::new();
|
||||||
|
let mesh = triangulate(
|
||||||
|
shape.to_shape(tolerance, &mut debug_info),
|
||||||
|
tolerance,
|
||||||
|
&mut debug_info,
|
||||||
|
);
|
||||||
|
|
||||||
|
ProcessedShape {
|
||||||
|
aabb,
|
||||||
|
mesh,
|
||||||
|
debug_info,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A processed shape
|
||||||
|
///
|
||||||
|
/// Created by [`ShapeProcessor::process`].
|
||||||
|
pub struct ProcessedShape {
|
||||||
|
/// The axis-aligned bounding box of the shape
|
||||||
|
pub aabb: Aabb<3>,
|
||||||
|
|
||||||
|
/// The triangle mesh that approximates the original shape
|
||||||
|
pub mesh: Mesh<Point<3>>,
|
||||||
|
|
||||||
|
/// The debug info generated while processing the shape
|
||||||
|
pub debug_info: DebugInfo,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user