diff --git a/app-proto/main.css b/app-proto/main.css index a1ff9da..d71ce4a 100644 --- a/app-proto/main.css +++ b/app-proto/main.css @@ -78,12 +78,12 @@ summary.selected { background-color: var(--selection-highlight); } -summary > div, .observable { +summary > div, .regulator { padding-top: 4px; padding-bottom: 4px; } -.element, .observable { +.element, .regulator { display: flex; flex-grow: 1; padding-left: 8px; @@ -108,7 +108,7 @@ details[open]:has(li) .element-switch::after { flex-grow: 1; } -.observable-label { +.regulator-label { flex-grow: 1; } @@ -124,37 +124,37 @@ details[open]:has(li) .element-switch::after { width: 56px; } -.observable { +.regulator { font-style: italic; } -.observable-type { +.regulator-type { padding: 2px 8px 0px 8px; font-size: 10pt; } -.observable.invalid-constraint { +.regulator.invalid-constraint { color: var(--text-invalid); } -.observable > input { +.regulator > input { color: inherit; background-color: inherit; border: 1px solid var(--border); border-radius: 2px; } -.observable > input::placeholder { +.regulator > input::placeholder { color: inherit; opacity: 54%; font-style: italic; } -.observable.valid-constraint > input { +.regulator.valid-constraint > input { background-color: var(--display-background); } -.observable.invalid-constraint > input { +.regulator.invalid-constraint > input { border-color: var(--border-invalid); } diff --git a/app-proto/src/add_remove.rs b/app-proto/src/add_remove.rs index 640925a..d8d6163 100644 --- a/app-proto/src/add_remove.rs +++ b/app-proto/src/add_remove.rs @@ -6,8 +6,8 @@ use crate::{ AppState, assembly::{ Assembly, - Observable, - ObservableRole, + Regulator, + RegulatorRole, Element }, engine::Q @@ -210,8 +210,8 @@ pub fn AddRemove() -> View { } ); let desired = create_signal(0.0); - let role = create_signal(ObservableRole::Measurement); - state.assembly.insert_observable(Observable { + let role = create_signal(RegulatorRole::Measurement); + state.assembly.insert_regulator(Regulator { subjects: subjects, measured: measured, desired: desired, @@ -221,22 +221,22 @@ pub fn AddRemove() -> View { state.selection.update(|sel| sel.clear()); /* DEBUG */ - // print updated observable list - console::log_1(&JsValue::from("Observables:")); - state.assembly.observables.with(|obsls| { - for (_, obs) in obsls.into_iter() { + // print updated regulator list + console::log_1(&JsValue::from("Regulators:")); + state.assembly.regulators.with(|regs| { + for (_, reg) in regs.into_iter() { console::log_5( &JsValue::from(" "), - &JsValue::from(obs.subjects.0), - &JsValue::from(obs.subjects.1), + &JsValue::from(reg.subjects.0), + &JsValue::from(reg.subjects.1), &JsValue::from(":"), - &JsValue::from(obs.desired.get_untracked()) + &JsValue::from(reg.desired.get_untracked()) ); } }); - // update the realization when the observable becomes - // constrained, or is edited while constrained + // update the realization when the regulator becomes + // a constraint, or is edited while acting as a constraint create_effect(move || { console::log_1(&JsValue::from( format!("Updated constraint with subjects ({}, {})", subjects.0, subjects.1) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index ba2f9c5..7c9418e 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -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 observables +// the types of the keys we use to access an assembly's elements and regulators pub type ElementKey = usize; -pub type ObservableKey = usize; +pub type RegulatorKey = usize; pub type ElementColor = [f32; 3]; @@ -26,7 +26,7 @@ pub struct Element { pub label: String, pub color: ElementColor, pub representation: Signal>, - pub observables: Signal>, + pub regulators: Signal>, // 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), - observables: create_signal(BTreeSet::default()), + regulators: create_signal(BTreeSet::default()), serial: serial, column_index: None } @@ -111,30 +111,30 @@ impl Element { } } -pub enum ObservableRole { +pub enum RegulatorRole { Measurement, Constraint(bool) } -impl ObservableRole { +impl RegulatorRole { pub fn is_valid_constraint(&self) -> bool { match self { - ObservableRole::Measurement => false, - ObservableRole::Constraint(valid) => *valid + RegulatorRole::Measurement => false, + RegulatorRole::Constraint(valid) => *valid } } } #[derive(Clone)] -pub struct Observable { +pub struct Regulator { pub subjects: (ElementKey, ElementKey), pub measured: ReadSignal, pub desired: Signal, pub desired_text: Signal, - pub role: Signal + pub role: Signal } -impl Observable { +impl Regulator { fn role_is_valid_constraint_untracked(&self) -> bool { self.role.with_untracked(|role| role.is_valid_constraint()) } @@ -151,9 +151,9 @@ type AssemblyMotion<'a> = Vec>; // a complete, view-independent description of an assembly #[derive(Clone)] pub struct Assembly { - // elements and observables + // elements and regulators pub elements: Signal>, - pub observables: Signal>, + pub regulators: Signal>, // solution variety tangent space. the basis vectors are stored in // configuration matrix format, ordered according to the elements' column @@ -175,13 +175,13 @@ impl Assembly { pub fn new() -> Assembly { Assembly { elements: create_signal(Slab::new()), - observables: create_signal(Slab::new()), + regulators: create_signal(Slab::new()), tangent: create_signal(ConfigSubspace::zero(0)), elements_by_id: create_signal(FxHashMap::default()) } } - // --- inserting elements and observables --- + // --- inserting elements and regulators --- // insert an element into the assembly without checking whether we already // have an element with the same identifier. any element that does have the @@ -224,14 +224,14 @@ impl Assembly { ); } - 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) + pub fn insert_regulator(&self, regulator: Regulator) { + let subjects = regulator.subjects; + let key = self.regulators.update(|regs| regs.insert(regulator)); + let subject_regulators = self.elements.with( + |elts| (elts[subjects.0].regulators, elts[subjects.1].regulators) ); - subject_observables.0.update(|obsls| obsls.insert(key)); - subject_observables.1.update(|obsls| obsls.insert(key)); + subject_regulators.0.update(|regs| regs.insert(key)); + subject_regulators.1.update(|regs| regs.insert(key)); } // --- realization --- @@ -248,13 +248,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.observables.with_untracked(|obsls| { - for (_, obs) in obsls { - if obs.role_is_valid_constraint_untracked() { - let subjects = obs.subjects; + self.regulators.with_untracked(|regs| { + for (_, reg) in regs { + if reg.role_is_valid_constraint_untracked() { + let subjects = reg.subjects; let row = elts[subjects.0].column_index.unwrap(); let col = elts[subjects.1].column_index.unwrap(); - gram_to_be.push_sym(row, col, obs.desired.get_untracked()); + gram_to_be.push_sym(row, col, reg.desired.get_untracked()); } } }); diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index f341357..6e3e0d3 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -12,33 +12,33 @@ use crate::{ AppState, assembly, assembly::{ - Observable, - ObservableKey, - ObservableRole::*, + Regulator, + RegulatorKey, + RegulatorRole::*, ElementKey } }; -// an editable view of the Lorentz product representing an observable +// an editable view of a regulator #[component(inline_props)] -fn ObservableInput(observable: Observable) -> View { +fn RegulatorInput(regulator: Regulator) -> View { view! { input( r#type="text", - placeholder=observable.measured.with(|result| result.to_string()), - bind:value=observable.desired_text, + placeholder=regulator.measured.with(|result| result.to_string()), + bind:value=regulator.desired_text, on:change=move |event: Event| { let target: HtmlInputElement = event.target().unwrap().unchecked_into(); let value = target.value(); if value.is_empty() { - observable.role.set(Measurement); + regulator.role.set(Measurement); } else { match target.value().parse::() { Ok(desired) => batch(|| { - observable.desired.set(desired); - observable.role.set(Constraint(true)); + regulator.desired.set(desired); + regulator.role.set(Constraint(true)); }), - Err(_) => observable.role.set(Constraint(false)) + Err(_) => regulator.role.set(Constraint(false)) }; } } @@ -46,30 +46,30 @@ fn ObservableInput(observable: Observable) -> View { } } -// a list item that shows an observable in an outline view of an element +// a list item that shows a regulator in an outline view of an element #[component(inline_props)] -fn ObservableOutlineItem(observable_key: ObservableKey, element_key: ElementKey) -> View { +fn RegulatorOutlineItem(regulator_key: RegulatorKey, element_key: ElementKey) -> View { let state = use_context::(); let assembly = &state.assembly; - let observable = assembly.observables.with(|obsls| obsls[observable_key].clone()); - let other_subject = if observable.subjects.0 == element_key { - observable.subjects.1 + let regulator = assembly.regulators.with(|regs| regs[regulator_key].clone()); + let other_subject = if regulator.subjects.0 == element_key { + regulator.subjects.1 } else { - observable.subjects.0 + regulator.subjects.0 }; let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone()); - let class = observable.role.map( + let class = regulator.role.map( |role| match role { - Measurement => "observable", - Constraint(true) => "observable valid-constraint", - Constraint(false) => "observable invalid-constraint" + Measurement => "regulator", + Constraint(true) => "regulator valid-constraint", + Constraint(false) => "regulator invalid-constraint" } ); view! { li(class=class.get()) { - div(class="observable-label") { (other_subject_label) } - div(class="observable-type") { "Inversive distance" } - ObservableInput(observable=observable) + div(class="regulator-label") { (other_subject_label) } + div(class="regulator-type") { "Inversive distance" } + RegulatorInput(regulator=regulator) div(class="status") } } @@ -93,9 +93,9 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { ).collect::>() ) }; - let observed = element.observables.map(|obsls| obsls.len() > 0); - let observable_list = element.observables.map( - |obsls| obsls.clone().into_iter().collect() + let regulated = element.regulators.map(|regs| regs.len() > 0); + let regulator_list = element.regulators.map( + |regs| regs.clone().into_iter().collect() ); let details_node = create_node_ref(); view! { @@ -110,7 +110,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { state.select(key, event.shift_key()); event.prevent_default(); }, - "ArrowRight" if observed.get() => { + "ArrowRight" if regulated.get() => { let _ = details_node .get() .unchecked_into::() @@ -157,16 +157,16 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { div(class="status") } } - ul(class="observables") { + ul(class="regulators") { Keyed( - list=observable_list, - view=move |obs_key| view! { - ObservableOutlineItem( - observable_key=obs_key, + list=regulator_list, + view=move |reg_key| view! { + RegulatorOutlineItem( + regulator_key=reg_key, element_key=key ) }, - key=|obs_key| obs_key.clone() + key=|reg_key| reg_key.clone() ) } } @@ -174,9 +174,9 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { } } -// a component that lists the elements of the current assembly, showing the -// observables associated with each element as a collapsible sub-list. its -// implementation is based on Kate Morley's HTML + CSS tree views: +// a component that lists the elements of the current assembly, showing each +// element's regulators in a collapsible sub-list. its implementation is based +// on Kate Morley's HTML + CSS tree views: // // https://iamkate.com/code/tree-views/ //