From 5506ec1f43bdeceb995af792200600e703823272 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Thu, 17 Apr 2025 21:25:22 -0700 Subject: [PATCH] Make regulator activation less redundant --- app-proto/src/assembly.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 1850771..68a2863 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -148,7 +148,15 @@ pub trait Regulator: ProblemPoser + OutlineItem { fn measurement(&self) -> ReadSignal; fn set_point(&self) -> Signal; - fn activate(&self, _assembly: &Assembly) {} + // this method is used to responsively precondition the assembly for + // realization when the regulator becomes a constraint, or is edited while + // acting as a constraint. it should track the set point, do any desired + // preconditioning when the set point is present, and use its return value + // to report whether the set is present. the default implementation does no + // preconditioning + fn try_activate(&self, _assembly: &Assembly) -> bool { + self.set_point().with(|set_pt| set_pt.is_present()) + } } pub struct InversiveDistanceRegulator { @@ -240,14 +248,18 @@ impl Regulator for HalfCurvatureRegulator { self.set_point } - fn activate(&self, assembly: &Assembly) { - if let Some(half_curv) = self.set_point.with_untracked(|set_pt| set_pt.value) { - let representation = assembly.elements.with_untracked( - |elts| elts[self.subject].representation - ); - representation.update( - |rep| change_half_curvature(rep, half_curv) - ); + fn try_activate(&self, assembly: &Assembly) -> bool { + match self.set_point.with(|set_pt| set_pt.value) { + Some(half_curv) => { + let representation = assembly.elements.with_untracked( + |elts| elts[self.subject].representation + ); + representation.update( + |rep| change_half_curvature(rep, half_curv) + ); + true + } + None => false } } } @@ -382,8 +394,7 @@ impl Assembly { console::log_1(&JsValue::from( format!("Updated regulator with subjects {:?}", regulator_rc.subjects()) )); - if regulator_rc.set_point().with(|set_pt| set_pt.is_present()) { - regulator_rc.activate(&self_for_effect); + if regulator_rc.try_activate(&self_for_effect) { self_for_effect.realize(); } });