forked from StudioInfinity/dyna3
44 lines
No EOL
1 KiB
Rust
44 lines
No EOL
1 KiB
Rust
use nalgebra::DVector;
|
|
use rustc_hash::FxHashSet;
|
|
use slab::Slab;
|
|
use sycamore::prelude::*;
|
|
|
|
#[derive(Clone, PartialEq)]
|
|
pub struct Element {
|
|
pub id: String,
|
|
pub label: String,
|
|
pub color: [f32; 3],
|
|
pub rep: DVector<f64>,
|
|
pub constraints: FxHashSet<usize>
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Constraint {
|
|
pub args: (usize, usize),
|
|
pub rep: f64
|
|
}
|
|
|
|
// a complete, view-independent description of an assembly
|
|
#[derive(Clone)]
|
|
pub struct Assembly {
|
|
pub elements: Signal<Slab<Element>>,
|
|
pub constraints: Signal<Slab<Constraint>>
|
|
}
|
|
|
|
impl Assembly {
|
|
pub fn new() -> Assembly {
|
|
Assembly {
|
|
elements: create_signal(Slab::new()),
|
|
constraints: create_signal(Slab::new())
|
|
}
|
|
}
|
|
|
|
pub fn insert_constraint(&self, constraint: Constraint) {
|
|
let args = constraint.args;
|
|
let key = self.constraints.update(|csts| csts.insert(constraint));
|
|
self.elements.update(|elts| {
|
|
elts[args.0].constraints.insert(key);
|
|
elts[args.1].constraints.insert(key);
|
|
})
|
|
}
|
|
} |