Rename constraints to observables
This commit is contained in:
parent
fb8e391587
commit
677ef47544
4 changed files with 78 additions and 78 deletions
|
@ -77,12 +77,12 @@ summary.selected {
|
||||||
background-color: var(--selection-highlight);
|
background-color: var(--selection-highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
summary > div, .constraint {
|
summary > div, .observable {
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
padding-bottom: 4px;
|
padding-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.element, .constraint {
|
.element, .observable {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
|
@ -107,7 +107,7 @@ details[open]:has(li) .element-switch::after {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.constraint-label {
|
.observable-label {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,22 +123,22 @@ details[open]:has(li) .element-switch::after {
|
||||||
width: 56px;
|
width: 56px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.constraint {
|
.observable {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.constraint.invalid {
|
.observable.invalid {
|
||||||
color: var(--text-invalid);
|
color: var(--text-invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
.constraint > input[type=text] {
|
.observable > input[type=text] {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
background-color: inherit;
|
background-color: inherit;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.constraint.invalid > input[type=text] {
|
.observable.invalid > input[type=text] {
|
||||||
border-color: var(--border-invalid);
|
border-color: var(--border-invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ use crate::{
|
||||||
AppState,
|
AppState,
|
||||||
assembly::{
|
assembly::{
|
||||||
Assembly,
|
Assembly,
|
||||||
Constraint,
|
Observable,
|
||||||
ConstraintRole,
|
ObservableRole,
|
||||||
Element
|
Element
|
||||||
},
|
},
|
||||||
engine::Q
|
engine::Q
|
||||||
|
@ -210,8 +210,8 @@ pub fn AddRemove() -> View {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let desired = create_signal(0.0);
|
let desired = create_signal(0.0);
|
||||||
let role = create_signal(ConstraintRole::Measure);
|
let role = create_signal(ObservableRole::Measure);
|
||||||
state.assembly.insert_constraint(Constraint {
|
state.assembly.insert_observable(Observable {
|
||||||
subjects: subjects,
|
subjects: subjects,
|
||||||
measured: measured,
|
measured: measured,
|
||||||
desired: desired,
|
desired: desired,
|
||||||
|
@ -221,16 +221,16 @@ pub fn AddRemove() -> View {
|
||||||
state.selection.update(|sel| sel.clear());
|
state.selection.update(|sel| sel.clear());
|
||||||
|
|
||||||
/* DEBUG */
|
/* DEBUG */
|
||||||
// print updated constraint list
|
// print updated observable list
|
||||||
console::log_1(&JsValue::from("Constraints:"));
|
console::log_1(&JsValue::from("Observables:"));
|
||||||
state.assembly.constraints.with(|csts| {
|
state.assembly.observables.with(|obsls| {
|
||||||
for (_, cst) in csts.into_iter() {
|
for (_, obs) in obsls.into_iter() {
|
||||||
console::log_5(
|
console::log_5(
|
||||||
&JsValue::from(" "),
|
&JsValue::from(" "),
|
||||||
&JsValue::from(cst.subjects.0),
|
&JsValue::from(obs.subjects.0),
|
||||||
&JsValue::from(cst.subjects.1),
|
&JsValue::from(obs.subjects.1),
|
||||||
&JsValue::from(":"),
|
&JsValue::from(":"),
|
||||||
&JsValue::from(cst.desired.get_untracked())
|
&JsValue::from(obs.desired.get_untracked())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -239,10 +239,10 @@ pub fn AddRemove() -> View {
|
||||||
// constrained, or is edited while constrained
|
// constrained, or is edited while constrained
|
||||||
create_effect(move || {
|
create_effect(move || {
|
||||||
console::log_1(&JsValue::from(
|
console::log_1(&JsValue::from(
|
||||||
format!("Constraint ({}, {}) updated", subjects.0, subjects.1)
|
format!("Updated constraint with subjects ({}, {})", subjects.0, subjects.1)
|
||||||
));
|
));
|
||||||
desired.track();
|
desired.track();
|
||||||
if role.with(|r| matches!(r, ConstraintRole::Constrain)) {
|
if role.with(|r| matches!(r, ObservableRole::Constrain)) {
|
||||||
state.assembly.realize();
|
state.assembly.realize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,9 +7,9 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||||
|
|
||||||
use crate::engine::{realize_gram, local_unif_to_std, ConfigSubspace, PartialMatrix};
|
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 ElementKey = usize;
|
||||||
pub type ConstraintKey = usize;
|
pub type ObservableKey = usize;
|
||||||
|
|
||||||
pub type ElementColor = [f32; 3];
|
pub type ElementColor = [f32; 3];
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ pub struct Element {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub color: ElementColor,
|
pub color: ElementColor,
|
||||||
pub representation: Signal<DVector<f64>>,
|
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
|
// a serial number, assigned by `Element::new`, that uniquely identifies
|
||||||
// each element
|
// each element
|
||||||
|
@ -61,7 +61,7 @@ impl Element {
|
||||||
label: label,
|
label: label,
|
||||||
color: color,
|
color: color,
|
||||||
representation: create_signal(representation),
|
representation: create_signal(representation),
|
||||||
constraints: create_signal(BTreeSet::default()),
|
observables: create_signal(BTreeSet::default()),
|
||||||
serial: serial,
|
serial: serial,
|
||||||
column_index: None
|
column_index: None
|
||||||
}
|
}
|
||||||
|
@ -111,19 +111,19 @@ impl Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ConstraintRole {
|
pub enum ObservableRole {
|
||||||
Measure,
|
Measure,
|
||||||
Constrain,
|
Constrain,
|
||||||
Invalid
|
Invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Constraint {
|
pub struct Observable {
|
||||||
pub subjects: (ElementKey, ElementKey),
|
pub subjects: (ElementKey, ElementKey),
|
||||||
pub measured: ReadSignal<f64>,
|
pub measured: ReadSignal<f64>,
|
||||||
pub desired: Signal<f64>,
|
pub desired: Signal<f64>,
|
||||||
pub desired_text: Signal<String>,
|
pub desired_text: Signal<String>,
|
||||||
pub role: Signal<ConstraintRole>
|
pub role: Signal<ObservableRole>
|
||||||
}
|
}
|
||||||
|
|
||||||
// the velocity is expressed in uniform coordinates
|
// 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
|
// a complete, view-independent description of an assembly
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Assembly {
|
pub struct Assembly {
|
||||||
// elements and constraints
|
// elements and observables
|
||||||
pub elements: Signal<Slab<Element>>,
|
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
|
// solution variety tangent space. the basis vectors are stored in
|
||||||
// configuration matrix format, ordered according to the elements' column
|
// configuration matrix format, ordered according to the elements' column
|
||||||
|
@ -161,13 +161,13 @@ impl Assembly {
|
||||||
pub fn new() -> Assembly {
|
pub fn new() -> Assembly {
|
||||||
Assembly {
|
Assembly {
|
||||||
elements: create_signal(Slab::new()),
|
elements: create_signal(Slab::new()),
|
||||||
constraints: create_signal(Slab::new()),
|
observables: create_signal(Slab::new()),
|
||||||
tangent: create_signal(ConfigSubspace::zero(0)),
|
tangent: create_signal(ConfigSubspace::zero(0)),
|
||||||
elements_by_id: create_signal(FxHashMap::default())
|
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
|
// insert an element into the assembly without checking whether we already
|
||||||
// have an element with the same identifier. any element that does have the
|
// 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) {
|
pub fn insert_observable(&self, observable: Observable) {
|
||||||
let subjects = constraint.subjects;
|
let subjects = observable.subjects;
|
||||||
let key = self.constraints.update(|csts| csts.insert(constraint));
|
let key = self.observables.update(|obsls| obsls.insert(observable));
|
||||||
let subject_constraints = self.elements.with(
|
let subject_observables = self.elements.with(
|
||||||
|elts| (elts[subjects.0].constraints, elts[subjects.1].constraints)
|
|elts| (elts[subjects.0].observables, elts[subjects.1].observables)
|
||||||
);
|
);
|
||||||
subject_constraints.0.update(|csts| csts.insert(key));
|
subject_observables.0.update(|obsls| obsls.insert(key));
|
||||||
subject_constraints.1.update(|csts| csts.insert(key));
|
subject_observables.1.update(|obsls| obsls.insert(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- realization ---
|
// --- realization ---
|
||||||
|
@ -234,13 +234,13 @@ impl Assembly {
|
||||||
let (gram, guess) = self.elements.with_untracked(|elts| {
|
let (gram, guess) = self.elements.with_untracked(|elts| {
|
||||||
// set up the off-diagonal part of the Gram matrix
|
// set up the off-diagonal part of the Gram matrix
|
||||||
let mut gram_to_be = PartialMatrix::new();
|
let mut gram_to_be = PartialMatrix::new();
|
||||||
self.constraints.with_untracked(|csts| {
|
self.observables.with_untracked(|obsls| {
|
||||||
for (_, cst) in csts {
|
for (_, obs) in obsls {
|
||||||
if cst.role.with_untracked(|role| matches!(role, ConstraintRole::Constrain)) {
|
if obs.role.with_untracked(|role| matches!(role, ObservableRole::Constrain)) {
|
||||||
let subjects = cst.subjects;
|
let subjects = obs.subjects;
|
||||||
let row = elts[subjects.0].column_index.unwrap();
|
let row = elts[subjects.0].column_index.unwrap();
|
||||||
let col = elts[subjects.1].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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,33 +12,33 @@ use crate::{
|
||||||
AppState,
|
AppState,
|
||||||
assembly,
|
assembly,
|
||||||
assembly::{
|
assembly::{
|
||||||
Constraint,
|
Observable,
|
||||||
ConstraintKey,
|
ObservableKey,
|
||||||
ConstraintRole::*,
|
ObservableRole::*,
|
||||||
ElementKey
|
ElementKey
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// an editable view of the Lorentz product representing a constraint
|
// an editable view of the Lorentz product representing an observable
|
||||||
#[component(inline_props)]
|
#[component(inline_props)]
|
||||||
fn LorentzProductInput(constraint: Constraint) -> View {
|
fn ObservableInput(observable: Observable) -> View {
|
||||||
view! {
|
view! {
|
||||||
input(
|
input(
|
||||||
r#type="text",
|
r#type="text",
|
||||||
placeholder=constraint.measured.with(|result| result.to_string()),
|
placeholder=observable.measured.with(|result| result.to_string()),
|
||||||
bind:value=constraint.desired_text,
|
bind:value=observable.desired_text,
|
||||||
on:change=move |event: Event| {
|
on:change=move |event: Event| {
|
||||||
let target: HtmlInputElement = event.target().unwrap().unchecked_into();
|
let target: HtmlInputElement = event.target().unwrap().unchecked_into();
|
||||||
let value = target.value();
|
let value = target.value();
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
constraint.role.set(Measure);
|
observable.role.set(Measure);
|
||||||
} else {
|
} else {
|
||||||
match target.value().parse::<f64>() {
|
match target.value().parse::<f64>() {
|
||||||
Ok(desired) => batch(|| {
|
Ok(desired) => batch(|| {
|
||||||
constraint.desired.set(desired);
|
observable.desired.set(desired);
|
||||||
constraint.role.set(Constrain);
|
observable.role.set(Constrain);
|
||||||
}),
|
}),
|
||||||
Err(_) => constraint.role.set(Invalid)
|
Err(_) => observable.role.set(Invalid)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,29 +46,29 @@ fn LorentzProductInput(constraint: Constraint) -> View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a list item that shows a constraint in an outline view of an element
|
// a list item that shows an observable in an outline view of an element
|
||||||
#[component(inline_props)]
|
#[component(inline_props)]
|
||||||
fn ConstraintOutlineItem(constraint_key: ConstraintKey, element_key: ElementKey) -> View {
|
fn ObservableOutlineItem(observable_key: ObservableKey, element_key: ElementKey) -> View {
|
||||||
let state = use_context::<AppState>();
|
let state = use_context::<AppState>();
|
||||||
let assembly = &state.assembly;
|
let assembly = &state.assembly;
|
||||||
let constraint = assembly.constraints.with(|csts| csts[constraint_key].clone());
|
let observable = assembly.observables.with(|obsls| obsls[observable_key].clone());
|
||||||
let other_subject = if constraint.subjects.0 == element_key {
|
let other_subject = if observable.subjects.0 == element_key {
|
||||||
constraint.subjects.1
|
observable.subjects.1
|
||||||
} else {
|
} else {
|
||||||
constraint.subjects.0
|
observable.subjects.0
|
||||||
};
|
};
|
||||||
let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone());
|
let other_subject_label = assembly.elements.with(|elts| elts[other_subject].label.clone());
|
||||||
let class = constraint.role.map(
|
let class = observable.role.map(
|
||||||
|role| match role {
|
|role| match role {
|
||||||
Measure => "constraint",
|
Measure => "observable",
|
||||||
Constrain => "constraint constrained",
|
Constrain => "observable constrained",
|
||||||
Invalid => "constraint invalid"
|
Invalid => "observable invalid"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
view! {
|
view! {
|
||||||
li(class=class.get()) {
|
li(class=class.get()) {
|
||||||
div(class="constraint-label") { (other_subject_label) }
|
div(class="observable-label") { (other_subject_label) }
|
||||||
LorentzProductInput(constraint=constraint)
|
ObservableInput(observable=observable)
|
||||||
div(class="status")
|
div(class="status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,9 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
).collect::<Vec<_>>()
|
).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let constrained = element.constraints.map(|csts| csts.len() > 0);
|
let observed = element.observables.map(|obsls| obsls.len() > 0);
|
||||||
let constraint_list = element.constraints.map(
|
let observable_list = element.observables.map(
|
||||||
|csts| csts.clone().into_iter().collect()
|
|obsls| obsls.clone().into_iter().collect()
|
||||||
);
|
);
|
||||||
let details_node = create_node_ref();
|
let details_node = create_node_ref();
|
||||||
view! {
|
view! {
|
||||||
|
@ -109,7 +109,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
state.select(key, event.shift_key());
|
state.select(key, event.shift_key());
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
},
|
},
|
||||||
"ArrowRight" if constrained.get() => {
|
"ArrowRight" if observed.get() => {
|
||||||
let _ = details_node
|
let _ = details_node
|
||||||
.get()
|
.get()
|
||||||
.unchecked_into::<web_sys::Element>()
|
.unchecked_into::<web_sys::Element>()
|
||||||
|
@ -156,16 +156,16 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
div(class="status")
|
div(class="status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ul(class="constraints") {
|
ul(class="observables") {
|
||||||
Keyed(
|
Keyed(
|
||||||
list=constraint_list,
|
list=observable_list,
|
||||||
view=move |cst_key| view! {
|
view=move |obs_key| view! {
|
||||||
ConstraintOutlineItem(
|
ObservableOutlineItem(
|
||||||
constraint_key=cst_key,
|
observable_key=obs_key,
|
||||||
element_key=key
|
element_key=key
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
key=|cst_key| cst_key.clone()
|
key=|obs_key| obs_key.clone()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,8 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
||||||
}
|
}
|
||||||
|
|
||||||
// a component that lists the elements of the current assembly, showing the
|
// a component that lists the elements of the current assembly, showing the
|
||||||
// constraints on each element as a collapsible sub-list. its implementation
|
// observables associated with each element as a collapsible sub-list. its
|
||||||
// is based on Kate Morley's HTML + CSS tree views:
|
// implementation is based on Kate Morley's HTML + CSS tree views:
|
||||||
//
|
//
|
||||||
// https://iamkate.com/code/tree-views/
|
// https://iamkate.com/code/tree-views/
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue