fix - resue of process model method, removed anyhow dependency, cleaned up args #2307

This commit is contained in:
raj-gandhi-eicon 2025-05-24 13:20:57 +05:30
parent 254791eeea
commit c934aa7c6a
11 changed files with 26 additions and 103 deletions

4
Cargo.lock generated
View File

@ -686,7 +686,6 @@ checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929"
name = "cuboid"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"fj",
]
@ -1364,7 +1363,6 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
name = "holes"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"cuboid",
"fj",
@ -3430,7 +3428,6 @@ dependencies = [
name = "spacer"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"fj",
]
@ -3474,7 +3471,6 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
name = "star"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"fj",
]

View File

@ -46,53 +46,8 @@ impl Instance {
for<'r> (&'r M, Tolerance): Triangulate,
for<'r> &'r M: BoundingVolume<3>,
{
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(tracing_subscriber::EnvFilter::from_default_env())
.init();
let args = Args::parse();
if !args.ignore_validation {
self.core.layers.validation.take_errors()?;
}
let aabb = model.aabb(&self.core.layers.geometry).unwrap_or(Aabb {
min: Point::origin(),
max: Point::origin(),
});
let tolerance = match args.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)?
}
Some(user_defined_tolerance) => user_defined_tolerance,
};
let tri_mesh = (model, tolerance).triangulate(&mut self.core);
if let Some(path) = args.export {
export::export(tri_mesh.all_triangles(), &path)?;
return Ok(());
}
make_viewer_and_spawn_thread(|viewer| {
viewer.display_model(tri_mesh);
})?;
Ok(())
self.process_model_args(model, args)
}
/// Process a model with pre-parsed arguments

View File

@ -3,11 +3,6 @@ name = "cuboid"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "cuboid"
path = "src/main.rs"
[dependencies]
fj = { path = "../../crates/fj" }
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0"

View File

@ -1,30 +1,28 @@
use clap::Parser;
use fj::{Args, Instance};
#[derive(Parser)]
struct Parameters {
/// Size of the cuboid, as a comma-separated vector `x,y,z`
#[arg(long, value_parser = parse_vector_3, default_value = "1,1,1")]
size: [f64; 3],
/// Size of the cuboid along the x-axis
#[arg(long, default_value = "3.0")]
x: f64,
/// Size of the cuboid along the y-axis
#[arg(long, default_value = "2.0")]
y: f64,
/// Size of the cuboid along the z-axis
#[arg(long, default_value = "1.0")]
z: f64,
#[command(flatten)]
fj: Args,
fj: fj::Args,
}
fn parse_vector_3(arg: &str) -> anyhow::Result<[f64; 3]> {
Ok(arg
.split(',')
.map(str::parse)
.collect::<Result<Vec<f64>, _>>()?
.as_slice()
.try_into()?)
}
fn main() -> anyhow::Result<()> {
let mut fj = Instance::new();
fn main() -> fj::Result {
let mut fj = fj::Instance::new();
let params = Parameters::parse();
let model = cuboid::model(params.size, &mut fj.core);
let model = cuboid::model([params.x, params.y, params.z], &mut fj.core);
fj.process_model_args(&model, params.fj)?;
Ok(())

View File

@ -3,12 +3,7 @@ name = "holes"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "holes"
path = "src/main.rs"
[dependencies]
fj = { path = "../../crates/fj" }
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0"
cuboid = { path = "../cuboid" }

View File

@ -13,7 +13,7 @@ pub fn model(radius: impl Into<Scalar>, core: &mut fj::core::Core) -> Solid {
let radius = radius.into();
let size = radius * 4.;
let cuboid = ::cuboid::model([size * 2., size, size], core);
let cuboid = cuboid::model([size * 2., size, size], core);
cuboid.update_shell(
cuboid.shells().only(),

View File

@ -1,6 +1,4 @@
use anyhow::Result;
use clap::Parser;
use fj::{Args, Instance};
#[derive(Parser)]
struct Parameters {
@ -9,11 +7,11 @@ struct Parameters {
radius: f64,
#[command(flatten)]
fj: Args,
fj: fj::Args,
}
fn main() -> Result<()> {
let mut fj = Instance::new();
fn main() -> fj::Result {
let mut fj = fj::Instance::new();
let params = Parameters::parse();
let model = holes::model(params.radius, &mut fj.core);

View File

@ -3,11 +3,6 @@ name = "spacer"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "spacer"
path = "src/main.rs"
[dependencies]
fj = { path = "../../crates/fj" }
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0"

View File

@ -1,6 +1,4 @@
use anyhow::Result;
use clap::Parser;
use fj::{Args, Instance};
#[derive(Parser)]
struct Parameters {
@ -17,11 +15,11 @@ struct Parameters {
height: f64,
#[command(flatten)]
fj: Args,
fj: fj::Args,
}
fn main() -> Result<()> {
let mut fj = Instance::new();
fn main() -> fj::Result {
let mut fj = fj::Instance::new();
let params = Parameters::parse();
let model = spacer::model(

View File

@ -3,11 +3,6 @@ name = "star"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "star"
path = "src/main.rs"
[dependencies]
fj = { path = "../../crates/fj" }
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0"

View File

@ -1,6 +1,4 @@
use anyhow::Result;
use clap::Parser;
use fj::{Args, Instance};
#[derive(Parser)]
struct Parameters {
@ -21,11 +19,11 @@ struct Parameters {
height: f64,
#[command(flatten)]
fj: Args,
fj: fj::Args,
}
fn main() -> Result<()> {
let mut fj = Instance::new();
fn main() -> fj::Result {
let mut fj = fj::Instance::new();
let params = Parameters::parse();
let model = star::model(