Assign each element a serial number
For future thread-safety, keep the next serial number in a static atomic variable.
This commit is contained in:
parent
65cee1ecc2
commit
6b2d44a58c
@ -1,7 +1,7 @@
|
|||||||
use nalgebra::{DMatrix, DVector};
|
use nalgebra::{DMatrix, DVector};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
use std::collections::BTreeSet;
|
use std::{collections::BTreeSet, sync::atomic::{AtomicU64, Ordering}};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||||
|
|
||||||
@ -13,6 +13,8 @@ pub type ConstraintKey = usize;
|
|||||||
|
|
||||||
pub type ElementColor = [f32; 3];
|
pub type ElementColor = [f32; 3];
|
||||||
|
|
||||||
|
static NEXT_ELEMENT_SERIAL: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Element {
|
pub struct Element {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@ -20,6 +22,10 @@ pub struct Element {
|
|||||||
pub color: ElementColor,
|
pub color: ElementColor,
|
||||||
pub representation: Signal<DVector<f64>>,
|
pub representation: Signal<DVector<f64>>,
|
||||||
pub constraints: Signal<BTreeSet<ConstraintKey>>,
|
pub constraints: Signal<BTreeSet<ConstraintKey>>,
|
||||||
|
|
||||||
|
// a serial number, assigned by `Element::new`, that uniquely identifies
|
||||||
|
// each element (until `NEXT_ELEMENT_SERIAL` wraps around)
|
||||||
|
pub serial: u64,
|
||||||
|
|
||||||
// the configuration matrix column index that was assigned to this element
|
// the configuration matrix column index that was assigned to this element
|
||||||
// last time the assembly was realized
|
// last time the assembly was realized
|
||||||
@ -39,6 +45,7 @@ impl Element {
|
|||||||
color: color,
|
color: color,
|
||||||
representation: create_signal(representation),
|
representation: create_signal(representation),
|
||||||
constraints: create_signal(BTreeSet::default()),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
|
serial: NEXT_ELEMENT_SERIAL.fetch_add(1, Ordering::SeqCst),
|
||||||
column_index: 0
|
column_index: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ pub fn Outline() -> View {
|
|||||||
view=|(key, elt)| view! {
|
view=|(key, elt)| view! {
|
||||||
ElementOutlineItem(key=key, element=elt)
|
ElementOutlineItem(key=key, element=elt)
|
||||||
},
|
},
|
||||||
key=|(key, _)| key.clone()
|
key=|(_, elt)| elt.serial
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user