From 6ced3335b5adb923f502064b0f66bdc36ff2d207 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 23 Mar 2023 12:56:57 +0100 Subject: [PATCH] Make return value more explicit --- crates/fj-kernel/src/operations/build/face.rs | 18 +++++++++++++-- crates/fj-kernel/src/operations/build/mod.rs | 6 ++++- .../fj-kernel/src/operations/build/shell.rs | 22 ++++++++++++------- crates/fj-kernel/src/operations/mod.rs | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/face.rs b/crates/fj-kernel/src/operations/build/face.rs index 045efbe5d..7fab183d7 100644 --- a/crates/fj-kernel/src/operations/build/face.rs +++ b/crates/fj-kernel/src/operations/build/face.rs @@ -18,7 +18,7 @@ pub trait BuildFace { points: [impl Into>; 3], edges: [Option>; 3], objects: &mut Service, - ) -> (Face, [Handle; 3]) { + ) -> Triangle { let [a, b, c] = points.map(Into::into); let surface = Surface::plane_from_points([a, b, c]).insert(objects); @@ -48,8 +48,22 @@ pub trait BuildFace { let face = Face::new(surface, exterior, [], None); - (face, global_edges) + Triangle { + face, + edges: global_edges, + } } } impl BuildFace for Face {} + +/// A triangle +/// +/// Returned by [`BuildFace::triangle`]. +pub struct Triangle { + /// The face that forms the triangle + pub face: Face, + + /// The edges of the triangle + pub edges: [Handle; 3], +} diff --git a/crates/fj-kernel/src/operations/build/mod.rs b/crates/fj-kernel/src/operations/build/mod.rs index 762c76fef..be6dfed0e 100644 --- a/crates/fj-kernel/src/operations/build/mod.rs +++ b/crates/fj-kernel/src/operations/build/mod.rs @@ -2,4 +2,8 @@ mod face; mod shell; mod surface; -pub use self::{face::BuildFace, shell::BuildShell, surface::BuildSurface}; +pub use self::{ + face::{BuildFace, Triangle}, + shell::BuildShell, + surface::BuildSurface, +}; diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index 968ba1678..6d4a917f1 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -6,7 +6,7 @@ use crate::{ services::Service, }; -use super::BuildFace; +use super::{BuildFace, Triangle}; /// Build a [`Shell`] pub trait BuildShell { @@ -17,13 +17,19 @@ pub trait BuildShell { ) -> Shell { let [a, b, c, d] = points.map(Into::into); - let (base, [ab, bc, ca]) = - Face::triangle([a, b, c], [None, None, None], objects); - let (side_a, [_, bd, da]) = - Face::triangle([a, b, d], [Some(ab), None, None], objects); - let (side_b, [_, _, dc]) = - Face::triangle([c, a, d], [Some(ca), Some(da), None], objects); - let (side_c, _) = + let Triangle { + face: base, + edges: [ab, bc, ca], + } = Face::triangle([a, b, c], [None, None, None], objects); + let Triangle { + face: side_a, + edges: [_, bd, da], + } = Face::triangle([a, b, d], [Some(ab), None, None], objects); + let Triangle { + face: side_b, + edges: [_, _, dc], + } = Face::triangle([c, a, d], [Some(ca), Some(da), None], objects); + let Triangle { face: side_c, .. } = Face::triangle([b, c, d], [Some(bc), Some(dc), Some(bd)], objects); let faces = diff --git a/crates/fj-kernel/src/operations/mod.rs b/crates/fj-kernel/src/operations/mod.rs index 7ed85caf8..0cfabab4c 100644 --- a/crates/fj-kernel/src/operations/mod.rs +++ b/crates/fj-kernel/src/operations/mod.rs @@ -4,6 +4,6 @@ mod build; mod insert; pub use self::{ - build::{BuildFace, BuildShell, BuildSurface}, + build::{BuildFace, BuildShell, BuildSurface, Triangle}, insert::Insert, };