Compare commits
No commits in common. "133b725053f8c925f416d7e6e7f6f91b11be62b7" and "7bc3a9eeae91f719d441dff0eeb1bef6c6e1f89a" have entirely different histories.
133b725053
...
7bc3a9eeae
@ -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, sync::atomic::{AtomicU64, Ordering}};
|
use std::{cell::Cell, collections::BTreeSet};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||||
|
|
||||||
@ -13,12 +13,9 @@ pub type ConstraintKey = usize;
|
|||||||
|
|
||||||
pub type ElementColor = [f32; 3];
|
pub type ElementColor = [f32; 3];
|
||||||
|
|
||||||
/* KLUDGE */
|
thread_local! {
|
||||||
// we should reconsider this design when we build a system for switching between
|
static NEXT_ELEMENT_SERIAL: Cell<u64> = Cell::new(0);
|
||||||
// assemblies. at that point, we might want to switch to hierarchical keys,
|
}
|
||||||
// where each each element has a key that identifies it within its assembly and
|
|
||||||
// each assembly has a key that identifies it within the sesssion
|
|
||||||
static NEXT_ELEMENT_SERIAL: AtomicU64 = AtomicU64::new(0);
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Element {
|
pub struct Element {
|
||||||
@ -44,16 +41,9 @@ impl Element {
|
|||||||
color: ElementColor,
|
color: ElementColor,
|
||||||
representation: DVector<f64>
|
representation: DVector<f64>
|
||||||
) -> Element {
|
) -> Element {
|
||||||
// take the next serial number, panicking if that was the last number we
|
// take the next serial number
|
||||||
// had left. the technique we use to panic on overflow is taken from
|
let serial = NEXT_ELEMENT_SERIAL.get();
|
||||||
// _Rust Atomics and Locks_, by Mara Bos
|
NEXT_ELEMENT_SERIAL.set(serial.wrapping_add(1));
|
||||||
//
|
|
||||||
// https://marabos.nl/atomics/atomics.html#example-handle-overflow
|
|
||||||
//
|
|
||||||
let serial = NEXT_ELEMENT_SERIAL.fetch_update(
|
|
||||||
Ordering::SeqCst, Ordering::SeqCst,
|
|
||||||
|serial| serial.checked_add(1)
|
|
||||||
).expect("Out of serial numbers for elements");
|
|
||||||
|
|
||||||
Element {
|
Element {
|
||||||
id: id,
|
id: id,
|
||||||
|
Loading…
Reference in New Issue
Block a user