Give each element a serial number #22
@ -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::{cell::Cell, 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,9 +13,7 @@ pub type ConstraintKey = usize;
|
|||||||
|
|
||||||
pub type ElementColor = [f32; 3];
|
pub type ElementColor = [f32; 3];
|
||||||
|
|
||||||
thread_local! {
|
static NEXT_ELEMENT_SERIAL: AtomicU64 = AtomicU64::new(0);
|
||||||
static NEXT_ELEMENT_SERIAL: Cell<u64> = Cell::new(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Element {
|
pub struct Element {
|
||||||
@ -41,17 +39,13 @@ impl Element {
|
|||||||
color: ElementColor,
|
color: ElementColor,
|
||||||
representation: DVector<f64>
|
representation: DVector<f64>
|
||||||
) -> Element {
|
) -> Element {
|
||||||
// take the next serial number
|
|
||||||
let serial = NEXT_ELEMENT_SERIAL.get();
|
|
||||||
NEXT_ELEMENT_SERIAL.set(serial.wrapping_add(1));
|
|
||||||
|
|
||||||
Element {
|
Element {
|
||||||
id: id,
|
id: id,
|
||||||
label: label,
|
label: label,
|
||||||
color: color,
|
color: color,
|
||||||
representation: create_signal(representation),
|
representation: create_signal(representation),
|
||||||
constraints: create_signal(BTreeSet::default()),
|
constraints: create_signal(BTreeSet::default()),
|
||||||
serial: serial,
|
serial: NEXT_ELEMENT_SERIAL.fetch_add(1, Ordering::SeqCst),
|
||||||
column_index: 0
|
column_index: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user