From ced001bbfe2597bebbda2bcc8659d38d7ab1d3ff Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Sun, 10 Nov 2024 20:13:40 -0800 Subject: [PATCH] Alias the types of element and constraint keys This will make it easier to change the key types if we change how we store and access elements and constraints. --- app-proto/src/assembly.rs | 10 +++++++--- app-proto/src/main.rs | 4 ++-- app-proto/src/outline.rs | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 8217922..6c4aeb7 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -7,13 +7,17 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */ use crate::engine::{realize_gram, PartialMatrix}; +// the types of the keys we use to access an assembly's elements and constraints +pub type ElementKey = usize; +pub type ConstraintKey = usize; + #[derive(Clone, PartialEq)] pub struct Element { pub id: String, pub label: String, pub color: [f32; 3], pub representation: DVector, - pub constraints: BTreeSet, + pub constraints: BTreeSet, // internal properties, not reflected in any view pub index: usize @@ -21,7 +25,7 @@ pub struct Element { #[derive(Clone)] pub struct Constraint { - pub subjects: (usize, usize), + pub subjects: (ElementKey, ElementKey), pub rep: Signal, pub rep_text: Signal, pub rep_valid: Signal, @@ -36,7 +40,7 @@ pub struct Assembly { pub constraints: Signal>, // indexing - pub elements_by_id: Signal> + pub elements_by_id: Signal> } impl Assembly { diff --git a/app-proto/src/main.rs b/app-proto/src/main.rs index 2c71a83..897f9d4 100644 --- a/app-proto/src/main.rs +++ b/app-proto/src/main.rs @@ -8,14 +8,14 @@ use rustc_hash::FxHashSet; use sycamore::prelude::*; use add_remove::AddRemove; -use assembly::Assembly; +use assembly::{Assembly, ElementKey}; use display::Display; use outline::Outline; #[derive(Clone)] struct AppState { assembly: Assembly, - selection: Signal> + selection: Signal> } impl AppState { diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index 98b422f..0a8816d 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -150,7 +150,7 @@ pub fn Outline() -> View { ul(class="constraints") { Keyed( list=elt.constraints.into_iter().collect::>(), - view=move |c_key: usize| { + view=move |c_key| { let c_state = use_context::(); let assembly = &c_state.assembly; let cst = assembly.constraints.with(|csts| csts[c_key].clone());