From 4fd79b9e47bce0a829aff4e3178374af217fa487 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Tue, 17 Dec 2024 18:21:53 -0800 Subject: [PATCH] Add structures for element and assembly motions --- app-proto/src/assembly.rs | 15 +++++++++++---- app-proto/src/display.rs | 11 +++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 1684716..07b0aba 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -119,6 +119,13 @@ pub struct Constraint { pub active: Signal } +pub struct ElementMotion<'a> { + pub key: ElementKey, + pub velocity: DVectorView<'a, f64> +} + +type AssemblyMotion<'a> = Vec>; + // a complete, view-independent description of an assembly #[derive(Clone)] pub struct Assembly { @@ -290,7 +297,7 @@ impl Assembly { // --- deformation --- - pub fn deform(&self, element_motions: Vec<(ElementKey, DVectorView)>) { + pub fn deform(&self, motion: AssemblyMotion) { /* KLUDGE */ // when the tangent space is zero, we currently need to avoid calling // its `proj` method, because it will panic rather than returning zero. @@ -307,9 +314,9 @@ impl Assembly { // project the element motions onto the tangent space of the solution // variety, and sum them to get a deformation of the whole assembly - for (elt_key, elt_motion) in element_motions { - let column_index = self.elements.with(|elts| elts[elt_key].column_index); - motion_proj += self.tangent.with(|tan| tan.proj(&elt_motion, column_index)); + for elt_motion in motion { + let column_index = self.elements.with(|elts| elts[elt_motion.key].column_index); + motion_proj += self.tangent.with(|tan| tan.proj(&elt_motion.velocity, column_index)); } // step each element along the mass shell geodesic that matches its diff --git a/app-proto/src/display.rs b/app-proto/src/display.rs index 673985c..d8ee23c 100644 --- a/app-proto/src/display.rs +++ b/app-proto/src/display.rs @@ -14,7 +14,7 @@ use web_sys::{ wasm_bindgen::{JsCast, JsValue} }; -use crate::{AppState, assembly::ElementKey}; +use crate::{AppState, assembly::{ElementKey, ElementMotion}}; fn compile_shader( context: &WebGl2RenderingContext, @@ -341,7 +341,14 @@ pub fn Display() -> View { ]) }; let elt_motion: DVector = time_step * TRANSLATION_SPEED * vel_field * rep; - assembly_for_raf.deform(vec![(sel, elt_motion.as_view())]); + assembly_for_raf.deform( + vec![ + ElementMotion { + key: sel, + velocity: elt_motion.as_view() + } + ] + ); scene_changed.set(true); } }