From 1ac4a73cd917e61d876ed926fa286e23a3206cee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 4 Apr 2025 12:49:13 +0200 Subject: [PATCH] Extract building connecting face to dedicated fn --- .../2025-03-18/src/operations/connect.rs | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/experiments/2025-03-18/src/operations/connect.rs b/experiments/2025-03-18/src/operations/connect.rs index 8f94cc9ab..79deec385 100644 --- a/experiments/2025-03-18/src/operations/connect.rs +++ b/experiments/2025-03-18/src/operations/connect.rs @@ -2,7 +2,10 @@ use crate::{ handle::Handle, math::Plane, topology::{ - curve::Curve, face::Face, half_edge::HalfEdge, solid::Solid, + curve::Curve, + face::{Face, HalfEdgeWithEndVertex}, + half_edge::HalfEdge, + solid::Solid, surface::Surface, }, }; @@ -54,42 +57,45 @@ fn build_connecting_faces(bottom: &Face, top: &Face) -> Vec> { bottom .half_edges_with_end_vertex() .zip(top.half_edges_with_end_vertex()) - .map(|(bottom, top)| { - let is_internal = - match [bottom.half_edge.is_internal, top.half_edge.is_internal] - { - [true, true] => true, - [false, false] => false, - _ => { - panic!( - "Trying to connect an internal half-edge of one \ - face to an external half-edge of another" - ); - } - }; - - let a = &bottom.half_edge.start; - let b = bottom.end_vertex; - let c = top.end_vertex; - let d = &top.half_edge.start; - - let surface = Handle::new(Surface { - geometry: Box::new(Plane::from_points( - [a, b, d].map(|vertex| vertex.point), - )), - }); - let face = Face::new( - surface, - [a, b, c, d].map(|vertex| { - Handle::new(HalfEdge { - curve: Handle::new(Curve {}), - start: vertex.clone(), - is_internal: false, - }) - }), - is_internal, - ); - Handle::new(face) - }) + .map(|(bottom, top)| build_single_connecting_face([bottom, top])) .collect::>() } + +fn build_single_connecting_face( + [bottom, top]: [HalfEdgeWithEndVertex; 2], +) -> Handle { + let is_internal = + match [bottom.half_edge.is_internal, top.half_edge.is_internal] { + [true, true] => true, + [false, false] => false, + _ => { + panic!( + "Trying to connect an internal half-edge of one \ + face to an external half-edge of another" + ); + } + }; + + let a = &bottom.half_edge.start; + let b = bottom.end_vertex; + let c = top.end_vertex; + let d = &top.half_edge.start; + + let surface = Handle::new(Surface { + geometry: Box::new(Plane::from_points( + [a, b, d].map(|vertex| vertex.point), + )), + }); + let face = Face::new( + surface, + [a, b, c, d].map(|vertex| { + Handle::new(HalfEdge { + curve: Handle::new(Curve {}), + start: vertex.clone(), + is_internal: false, + }) + }), + is_internal, + ); + Handle::new(face) +}