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.
This commit is contained in:
Aaron Fenyes 2024-11-10 20:13:40 -08:00
parent ed1890bffc
commit ced001bbfe
3 changed files with 10 additions and 6 deletions

View File

@ -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<f64>,
pub constraints: BTreeSet<usize>,
pub constraints: BTreeSet<ConstraintKey>,
// 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<f64>,
pub rep_text: Signal<String>,
pub rep_valid: Signal<bool>,
@ -36,7 +40,7 @@ pub struct Assembly {
pub constraints: Signal<Slab<Constraint>>,
// indexing
pub elements_by_id: Signal<FxHashMap<String, usize>>
pub elements_by_id: Signal<FxHashMap<String, ElementKey>>
}
impl Assembly {

View File

@ -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<FxHashSet<usize>>
selection: Signal<FxHashSet<ElementKey>>
}
impl AppState {

View File

@ -150,7 +150,7 @@ pub fn Outline() -> View {
ul(class="constraints") {
Keyed(
list=elt.constraints.into_iter().collect::<Vec<_>>(),
view=move |c_key: usize| {
view=move |c_key| {
let c_state = use_context::<AppState>();
let assembly = &c_state.assembly;
let cst = assembly.constraints.with(|csts| csts[c_key].clone());