diff --git a/app-proto/src/add_remove.rs b/app-proto/src/add_remove.rs index 4972d3c..deac2bb 100644 --- a/app-proto/src/add_remove.rs +++ b/app-proto/src/add_remove.rs @@ -4,7 +4,7 @@ use web_sys::{console, wasm_bindgen::JsValue}; use crate::{ engine, AppState, - assembly::{Assembly, Element} + assembly::{Assembly, Element, ProductRegulator} }; /* DEBUG */ @@ -189,7 +189,9 @@ pub fn AddRemove() -> View { .try_into() .unwrap() ); - state.assembly.insert_new_product_regulator(subjects); + state.assembly.insert_regulator( + ProductRegulator::new(subjects, &state.assembly) + ); state.selection.update(|sel| sel.clear()); } ) { "🔗" } diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index be52461..0eb3e64 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -155,6 +155,29 @@ pub struct ProductRegulator { pub set_point: Signal } +impl ProductRegulator { + pub fn new(subjects: [ElementKey; 2], assembly: &Assembly) -> ProductRegulator { + let measurement = assembly.elements.map( + move |elts| { + let representations = subjects.map(|subj| elts[subj].representation); + representations[0].with(|rep_0| + representations[1].with(|rep_1| + rep_0.dot(&(&*Q * rep_1)) + ) + ) + } + ); + + let set_point = create_signal(SpecifiedValue::from_empty_spec()); + + ProductRegulator { + subjects: subjects, + measurement: measurement, + set_point: set_point + } + } +} + impl Regulator for ProductRegulator { fn subjects(&self) -> Vec { self.subjects.into() @@ -192,6 +215,23 @@ pub struct HalfCurvatureRegulator { pub set_point: Signal } +impl HalfCurvatureRegulator { + pub fn new(subject: ElementKey, assembly: &Assembly) -> HalfCurvatureRegulator { + const CURVATURE_COMPONENT: usize = 3; + let measurement = assembly.elements.map( + move |elts| elts[subject].representation.with(|rep| rep[CURVATURE_COMPONENT]) + ); + + let set_point = create_signal(SpecifiedValue::from_empty_spec()); + + HalfCurvatureRegulator { + subject: subject, + measurement: measurement, + set_point: set_point + } + } +} + impl Regulator for HalfCurvatureRegulator { fn subjects(&self) -> Vec { vec![self.subject] @@ -285,7 +325,7 @@ impl Assembly { self.elements_by_id.update(|elts_by_id| elts_by_id.insert(id, key)); // regulate the sphere's curvature - self.insert_new_half_curvature_regulator(key); + self.insert_regulator(HalfCurvatureRegulator::new(key, &self)); key } @@ -323,7 +363,7 @@ impl Assembly { ); } - fn insert_regulator(&self, regulator: T) { + pub fn insert_regulator(&self, regulator: T) { // add the regulator to the assembly's regulator list let regulator_rc = Rc::new(regulator); let key = self.regulators.update( @@ -377,39 +417,6 @@ impl Assembly { }); } - pub fn insert_new_product_regulator(&self, subjects: [ElementKey; 2]) { - // create and insert a new product regulator - let measurement = self.elements.map( - move |elts| { - let representations = subjects.map(|subj| elts[subj].representation); - representations[0].with(|rep_0| - representations[1].with(|rep_1| - rep_0.dot(&(&*Q * rep_1)) - ) - ) - } - ); - let set_point = create_signal(SpecifiedValue::from_empty_spec()); - self.insert_regulator(ProductRegulator { - subjects: subjects, - measurement: measurement, - set_point: set_point - }); - } - - pub fn insert_new_half_curvature_regulator(&self, subject: ElementKey) { - // create and insert a new half-curvature regulator - let measurement = self.elements.map( - move |elts| elts[subject].representation.with(|rep| rep[3]) - ); - let set_point = create_signal(SpecifiedValue::from_empty_spec()); - self.insert_regulator(HalfCurvatureRegulator { - subject: subject, - measurement: measurement, - set_point: set_point - }); - } - // --- realization --- pub fn realize(&self) {