From 1f22276b6defec05c18396b86626dcd0be7a365c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 21 Apr 2023 09:40:23 +0200 Subject: [PATCH] Make use of join op in `BuildFace::tetrahedron` --- .../fj-kernel/src/operations/build/shell.rs | 104 +++++------------- 1 file changed, 30 insertions(+), 74 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index a61298f0d..a913232ee 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -2,12 +2,12 @@ use fj_math::Point; use crate::{ objects::{Face, Objects, Shell}, - operations::{Insert, UpdateCycle, UpdateFace, UpdateHalfEdge}, + operations::{Insert, JoinCycle, UpdateFace}, services::Service, storage::Handle, }; -use super::{BuildFace, Polygon}; +use super::BuildFace; /// Build a [`Shell`] pub trait BuildShell { @@ -35,78 +35,34 @@ pub trait BuildShell { ) -> Tetrahedron { let [a, b, c, d] = points.map(Into::into); - let [Polygon { - face: face_abc, - edges: [ab, bc, ca], - vertices: [a, b, c], - }, Polygon { - face: face_bad, - edges: [ba, ad, db], - vertices: [_, _, d], - }, Polygon { - face: face_dac, - edges: [da, ac, cd], - .. - }, Polygon { - face: face_cbd, - edges: [cb, bd, dc], - .. - }] = [ - Face::triangle([a, b, c], objects), - Face::triangle([b, a, d], objects), - Face::triangle([d, a, c], objects), - Face::triangle([c, b, d], objects), - ]; - - let face_bad = face_bad.update_exterior(|cycle| { - let ba_joined = ba - .replace_start_vertex(b.clone()) - .replace_global_form(ab.global_form().clone()) - .insert(objects); - let ad_joined = ad.replace_start_vertex(a.clone()).insert(objects); - - cycle - .replace_half_edge(&ba, ba_joined) - .replace_half_edge(&ad, ad_joined) - .insert(objects) - }); - let face_dac = face_dac.update_exterior(|cycle| { - let da_joined = da - .replace_start_vertex(d.clone()) - .replace_global_form(ad.global_form().clone()) - .insert(objects); - let ac_joined = ac - .replace_start_vertex(a) - .replace_global_form(ca.global_form().clone()) - .insert(objects); - let cd_joined = cd.replace_start_vertex(c.clone()).insert(objects); - - cycle - .replace_half_edge(&da, da_joined) - .replace_half_edge(&ac, ac_joined) - .replace_half_edge(&cd, cd_joined) - .insert(objects) - }); - let face_cbd = face_cbd.update_exterior(|cycle| { - let cb_joined = cb - .replace_start_vertex(c) - .replace_global_form(bc.global_form().clone()) - .insert(objects); - let bd_joined = bd - .replace_start_vertex(b) - .replace_global_form(db.global_form().clone()) - .insert(objects); - let dc_joined = dc - .replace_start_vertex(d) - .replace_global_form(cd.global_form().clone()) - .insert(objects); - - cycle - .replace_half_edge(&cb, cb_joined) - .replace_half_edge(&bd, bd_joined) - .replace_half_edge(&dc, dc_joined) - .insert(objects) - }); + let face_abc = Face::triangle([a, b, c], objects).face; + let face_bad = + Face::triangle([b, a, d], objects) + .face + .update_exterior(|cycle| { + cycle + .join_to(face_abc.exterior(), 0..=0, 0..=0, objects) + .insert(objects) + }); + let face_dac = + Face::triangle([d, a, c], objects) + .face + .update_exterior(|cycle| { + cycle + .join_to(face_abc.exterior(), 1..=1, 2..=2, objects) + .join_to(face_bad.exterior(), 0..=0, 1..=1, objects) + .insert(objects) + }); + let face_cbd = + Face::triangle([c, b, d], objects) + .face + .update_exterior(|cycle| { + cycle + .join_to(face_abc.exterior(), 0..=0, 1..=1, objects) + .join_to(face_bad.exterior(), 1..=1, 2..=2, objects) + .join_to(face_dac.exterior(), 2..=2, 2..=2, objects) + .insert(objects) + }); let faces = [face_abc, face_bad, face_dac, face_cbd] .map(|face| face.insert(objects));