forked from StudioInfinity/dyna3
Compare commits
No commits in common. "99a9c3ec55921b81550ec663eeefb8a02dec2804" and "620a6be918cc1a860aaa1f3e217db3fe32d4e8db" have entirely different histories.
99a9c3ec55
...
620a6be918
1 changed files with 21 additions and 27 deletions
|
@ -148,15 +148,7 @@ pub trait Regulator: ProblemPoser + OutlineItem {
|
||||||
fn measurement(&self) -> ReadSignal<f64>;
|
fn measurement(&self) -> ReadSignal<f64>;
|
||||||
fn set_point(&self) -> Signal<SpecifiedValue>;
|
fn set_point(&self) -> Signal<SpecifiedValue>;
|
||||||
|
|
||||||
// this method is used to responsively precondition the assembly for
|
fn activate(&self, _assembly: &Assembly) {}
|
||||||
// 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 {
|
pub struct InversiveDistanceRegulator {
|
||||||
|
@ -180,7 +172,11 @@ impl InversiveDistanceRegulator {
|
||||||
|
|
||||||
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
||||||
|
|
||||||
InversiveDistanceRegulator { subjects, measurement, set_point }
|
InversiveDistanceRegulator {
|
||||||
|
subjects: subjects,
|
||||||
|
measurement: measurement,
|
||||||
|
set_point: set_point
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +227,11 @@ impl HalfCurvatureRegulator {
|
||||||
|
|
||||||
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
||||||
|
|
||||||
HalfCurvatureRegulator { subject, measurement, set_point }
|
HalfCurvatureRegulator {
|
||||||
|
subject: subject,
|
||||||
|
measurement: measurement,
|
||||||
|
set_point: set_point
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,18 +248,14 @@ impl Regulator for HalfCurvatureRegulator {
|
||||||
self.set_point
|
self.set_point
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_activate(&self, assembly: &Assembly) -> bool {
|
fn activate(&self, assembly: &Assembly) {
|
||||||
match self.set_point.with(|set_pt| set_pt.value) {
|
if let Some(half_curv) = self.set_point.with_untracked(|set_pt| set_pt.value) {
|
||||||
Some(half_curv) => {
|
|
||||||
let representation = assembly.elements.with_untracked(
|
let representation = assembly.elements.with_untracked(
|
||||||
|elts| elts[self.subject].representation
|
|elts| elts[self.subject].representation
|
||||||
);
|
);
|
||||||
representation.update(
|
representation.update(
|
||||||
|rep| change_half_curvature(rep, half_curv)
|
|rep| change_half_curvature(rep, half_curv)
|
||||||
);
|
);
|
||||||
true
|
|
||||||
}
|
|
||||||
None => false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -391,13 +387,11 @@ impl Assembly {
|
||||||
// edited while acting as a constraint
|
// edited while acting as a constraint
|
||||||
let self_for_effect = self.clone();
|
let self_for_effect = self.clone();
|
||||||
create_effect(move || {
|
create_effect(move || {
|
||||||
/* DEBUG */
|
|
||||||
// log the regulator update
|
|
||||||
console::log_1(&JsValue::from(
|
console::log_1(&JsValue::from(
|
||||||
format!("Updated regulator with subjects {:?}", regulator_rc.subjects())
|
format!("Updated regulator with subjects {:?}", regulator_rc.subjects())
|
||||||
));
|
));
|
||||||
|
if regulator_rc.set_point().with(|set_pt| set_pt.is_present()) {
|
||||||
if regulator_rc.try_activate(&self_for_effect) {
|
regulator_rc.activate(&self_for_effect);
|
||||||
self_for_effect.realize();
|
self_for_effect.realize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue