From 761f9eff14b6ceee7638f0e23e9de0bf195d53fc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 24 Apr 2023 12:04:12 +0200 Subject: [PATCH] Implement `UpdateFace` for `Polygon` --- .../fj-kernel/src/operations/update/face.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/fj-kernel/src/operations/update/face.rs b/crates/fj-kernel/src/operations/update/face.rs index 2de785677..6e41a25ff 100644 --- a/crates/fj-kernel/src/operations/update/face.rs +++ b/crates/fj-kernel/src/operations/update/face.rs @@ -1,5 +1,8 @@ +use std::array; + use crate::{ objects::{Cycle, Face}, + operations::Polygon, storage::Handle, }; @@ -47,3 +50,41 @@ impl UpdateFace for Face { ) } } + +impl UpdateFace for Polygon { + fn update_exterior( + &self, + f: impl FnOnce(&Handle) -> Handle, + ) -> Self { + let face = self.face.update_exterior(f); + let edges = array::from_fn(|i| { + face.exterior() + .nth_half_edge(i) + .expect("Operation should not have changed length of cycle") + .clone() + }); + let vertices = array::from_fn(|i| { + // The duplicated code here is unfortunate, but unless we get a + // stable `array::each_ref` and something like `array::unzip`, I'm + // not sure how to avoid it. + face.exterior() + .nth_half_edge(i) + .expect("Operation should not have changed length of cycle") + .start_vertex() + .clone() + }); + + Polygon { + face, + edges, + vertices, + } + } + + fn add_interiors( + &self, + _: impl IntoIterator>, + ) -> Self { + panic!("Adding interiors to `Polygon` is not supported.") + } +}