From 016608d8ebd358152aec969fe8994c893ff246f2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Apr 2025 14:00:15 +0200 Subject: [PATCH] Simplify parameters of export functions --- crates/fj-export/src/lib.rs | 26 ++++++++++++-------------- crates/fj/src/instance.rs | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/crates/fj-export/src/lib.rs b/crates/fj-export/src/lib.rs index aa33fcac1..d7bcf393f 100644 --- a/crates/fj-export/src/lib.rs +++ b/crates/fj-export/src/lib.rs @@ -16,7 +16,7 @@ use std::{ use thiserror::Error; -use fj_interop::{MeshTriangle, vertices_to_indexed_vertices}; +use fj_interop::vertices_to_indexed_vertices; use fj_math::Triangle; /// # Export the provided mesh to the file at the given path @@ -26,8 +26,8 @@ use fj_math::Triangle; /// /// Currently 3MF & STL file types are supported. The case insensitive file /// extension of the provided path is used to switch between supported types. -pub fn export<'r>( - triangles: impl IntoIterator, +pub fn export( + triangles: impl IntoIterator>, path: impl AsRef, ) -> Result<(), Error> { match path.as_ref().extension() { @@ -51,14 +51,12 @@ pub fn export<'r>( } /// # Export the provided mesh to the provided writer in the 3MF format -pub fn export_3mf<'r>( - triangles: impl IntoIterator, +pub fn export_3mf( + triangles: impl IntoIterator>, write: impl Write + Seek, ) -> Result<(), Error> { let (vertices, indices) = vertices_to_indexed_vertices( - triangles - .into_iter() - .flat_map(|triangle| triangle.inner.points), + triangles.into_iter().flat_map(|triangle| triangle.points), |point| threemf::model::Vertex { x: point.x.into_f64(), y: point.y.into_f64(), @@ -88,13 +86,13 @@ pub fn export_3mf<'r>( } /// # Export the provided mesh to the provided writer in the STL format -pub fn export_stl<'r>( - triangles: impl IntoIterator, +pub fn export_stl( + triangles: impl IntoIterator>, mut write: impl Write, ) -> Result<(), Error> { let points = triangles .into_iter() - .map(|triangle| triangle.inner.points) + .map(|triangle| triangle.points) .collect::>(); let vertices = points.iter().map(|points| { @@ -135,13 +133,13 @@ pub fn export_stl<'r>( } /// # Export the provided mesh to the provided writer in the OBJ format -pub fn export_obj<'r>( - triangles: impl IntoIterator, +pub fn export_obj( + triangles: impl IntoIterator>, mut write: impl Write, ) -> Result<(), Error> { for (cnt, t) in triangles.into_iter().enumerate() { // write each point of the triangle - for v in t.inner.points { + for v in t.points { wavefront_rs::obj::writer::Writer { auto_newline: true } .write( &mut write, diff --git a/crates/fj/src/instance.rs b/crates/fj/src/instance.rs index d805abe22..622231307 100644 --- a/crates/fj/src/instance.rs +++ b/crates/fj/src/instance.rs @@ -84,7 +84,7 @@ impl Instance { let tri_mesh = (model, tolerance).triangulate(&mut self.core); if let Some(path) = args.export { - export::export(tri_mesh.triangles.iter(), &path)?; + export::export(tri_mesh.all_triangles(), &path)?; return Ok(()); }