Rename constraints to observables

This commit is contained in:
Aaron Fenyes 2025-01-26 10:50:15 -08:00
parent fb8e391587
commit 677ef47544
4 changed files with 78 additions and 78 deletions

View file

@ -7,9 +7,9 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
use crate::engine::{realize_gram, local_unif_to_std, ConfigSubspace, PartialMatrix};
// the types of the keys we use to access an assembly's elements and constraints
// the types of the keys we use to access an assembly's elements and observables
pub type ElementKey = usize;
pub type ConstraintKey = usize;
pub type ObservableKey = usize;
pub type ElementColor = [f32; 3];
@ -26,7 +26,7 @@ pub struct Element {
pub label: String,
pub color: ElementColor,
pub representation: Signal<DVector<f64>>,
pub constraints: Signal<BTreeSet<ConstraintKey>>,
pub observables: Signal<BTreeSet<ObservableKey>>,
// a serial number, assigned by `Element::new`, that uniquely identifies
// each element
@ -61,7 +61,7 @@ impl Element {
label: label,
color: color,
representation: create_signal(representation),
constraints: create_signal(BTreeSet::default()),
observables: create_signal(BTreeSet::default()),
serial: serial,
column_index: None
}
@ -111,19 +111,19 @@ impl Element {
}
}
pub enum ConstraintRole {
pub enum ObservableRole {
Measure,
Constrain,
Invalid
}
#[derive(Clone)]
pub struct Constraint {
pub struct Observable {
pub subjects: (ElementKey, ElementKey),
pub measured: ReadSignal<f64>,
pub desired: Signal<f64>,
pub desired_text: Signal<String>,
pub role: Signal<ConstraintRole>
pub role: Signal<ObservableRole>
}
// the velocity is expressed in uniform coordinates
@ -137,9 +137,9 @@ type AssemblyMotion<'a> = Vec<ElementMotion<'a>>;
// a complete, view-independent description of an assembly
#[derive(Clone)]
pub struct Assembly {
// elements and constraints
// elements and observables
pub elements: Signal<Slab<Element>>,
pub constraints: Signal<Slab<Constraint>>,
pub observables: Signal<Slab<Observable>>,
// solution variety tangent space. the basis vectors are stored in
// configuration matrix format, ordered according to the elements' column
@ -161,13 +161,13 @@ impl Assembly {
pub fn new() -> Assembly {
Assembly {
elements: create_signal(Slab::new()),
constraints: create_signal(Slab::new()),
observables: create_signal(Slab::new()),
tangent: create_signal(ConfigSubspace::zero(0)),
elements_by_id: create_signal(FxHashMap::default())
}
}
// --- inserting elements and constraints ---
// --- inserting elements and observables ---
// insert an element into the assembly without checking whether we already
// have an element with the same identifier. any element that does have the
@ -210,14 +210,14 @@ impl Assembly {
);
}
pub fn insert_constraint(&self, constraint: Constraint) {
let subjects = constraint.subjects;
let key = self.constraints.update(|csts| csts.insert(constraint));
let subject_constraints = self.elements.with(
|elts| (elts[subjects.0].constraints, elts[subjects.1].constraints)
pub fn insert_observable(&self, observable: Observable) {
let subjects = observable.subjects;
let key = self.observables.update(|obsls| obsls.insert(observable));
let subject_observables = self.elements.with(
|elts| (elts[subjects.0].observables, elts[subjects.1].observables)
);
subject_constraints.0.update(|csts| csts.insert(key));
subject_constraints.1.update(|csts| csts.insert(key));
subject_observables.0.update(|obsls| obsls.insert(key));
subject_observables.1.update(|obsls| obsls.insert(key));
}
// --- realization ---
@ -234,13 +234,13 @@ impl Assembly {
let (gram, guess) = self.elements.with_untracked(|elts| {
// set up the off-diagonal part of the Gram matrix
let mut gram_to_be = PartialMatrix::new();
self.constraints.with_untracked(|csts| {
for (_, cst) in csts {
if cst.role.with_untracked(|role| matches!(role, ConstraintRole::Constrain)) {
let subjects = cst.subjects;
self.observables.with_untracked(|obsls| {
for (_, obs) in obsls {
if obs.role.with_untracked(|role| matches!(role, ObservableRole::Constrain)) {
let subjects = obs.subjects;
let row = elts[subjects.0].column_index.unwrap();
let col = elts[subjects.1].column_index.unwrap();
gram_to_be.push_sym(row, col, cst.desired.get_untracked());
gram_to_be.push_sym(row, col, obs.desired.get_untracked());
}
}
});