forked from StudioInfinity/dyna3
App: insert constraints consistently
Also, write constructors for state objects.
This commit is contained in:
parent
050e2373a6
commit
4a24a01928
2 changed files with 37 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
|||
use nalgebra::DVector;
|
||||
use rustc_hash::FxHashSet;
|
||||
use slab::Slab;
|
||||
use sycamore::reactive::Signal;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Element {
|
||||
|
@ -22,4 +22,22 @@ pub struct Constraint {
|
|||
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);
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue