diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index d48172f..c263692 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -270,7 +270,7 @@ pub struct Point { } impl Point { - pub const WEIGHT_COMPONENT: usize = 3; + const WEIGHT_COMPONENT: usize = 3; const NORM_COMPONENT: usize = 4; pub fn new( @@ -514,7 +514,8 @@ impl ProblemPoser for HalfCurvatureRegulator { pub enum Axis {X = 0, Y = 1, Z = 2} impl Axis { - pub const NAME: [&str; Axis::CARDINALITY] = ["X", "Y", "Z"]; + pub const N_AXIS: usize = (Axis::Z as usize) + 1; + pub const NAME: [&str; Axis::N_AXIS] = ["X", "Y", "Z"]; } pub struct PointCoordinateRegulator { @@ -554,15 +555,15 @@ impl ProblemPoser for PointCoordinateRegulator { problem.frozen.push(self.axis as usize, col, val); // Check if all three coordinates have been frozen, and if so, // freeze the coradius as well - let mut coords = [0.0; Axis::CARDINALITY]; + let mut coords = [0.0; Axis::N_AXIS]; let mut nset: usize = 0; for &MatrixEntry {index, value} in &(problem.frozen) { - if index.1 == col && index.0 < Axis::CARDINALITY { + if index.1 == col && index.0 < Axis::N_AXIS { nset += 1; coords[index.0] = value } } - if nset == Axis::CARDINALITY { + if nset == Axis::N_AXIS { let [x, y, z] = coords; problem.frozen.push( Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]); diff --git a/app-proto/src/components/add_remove.rs b/app-proto/src/components/add_remove.rs index c22577a..4196640 100644 --- a/app-proto/src/components/add_remove.rs +++ b/app-proto/src/components/add_remove.rs @@ -3,7 +3,7 @@ use sycamore::prelude::*; use super::test_assembly_chooser::TestAssemblyChooser; use crate::{ - appState::AppState, + AppState, assembly::{InversiveDistanceRegulator, Point, Sphere}, }; diff --git a/app-proto/src/components/diagnostics.rs b/app-proto/src/components/diagnostics.rs index 323f95a..51d58f1 100644 --- a/app-proto/src/components/diagnostics.rs +++ b/app-proto/src/components/diagnostics.rs @@ -7,7 +7,7 @@ use charming::{ }; use sycamore::prelude::*; -use crate::{appState::AppState, specified::SpecifiedValue}; +use crate::{AppState, specified::SpecifiedValue}; #[derive(Clone)] struct DiagnosticsState { diff --git a/app-proto/src/components/display.rs b/app-proto/src/components/display.rs index aa4c3c2..98be85e 100644 --- a/app-proto/src/components/display.rs +++ b/app-proto/src/components/display.rs @@ -16,7 +16,7 @@ use web_sys::{ }; use crate::{ - appState::AppState, + AppState, assembly::{Element, ElementColor, ElementMotion, Point, Sphere}, }; diff --git a/app-proto/src/components/outline.rs b/app-proto/src/components/outline.rs index ecbb724..79781fa 100644 --- a/app-proto/src/components/outline.rs +++ b/app-proto/src/components/outline.rs @@ -4,7 +4,7 @@ use sycamore::prelude::*; use web_sys::{KeyboardEvent, MouseEvent, wasm_bindgen::JsCast}; use crate::{ - appState::AppState, + AppState, assembly::{ Axis, Element, @@ -123,11 +123,10 @@ impl OutlineItem for HalfCurvatureRegulator { impl OutlineItem for PointCoordinateRegulator { fn outline_item(self: Rc, _element: &Rc) -> View { - let name = format!("{} coordinate", Axis::NAME[self.axis as usize]); view! { li(class = "regulator") { - div(class = "regulator-label") // for spacing - div(class = "regulator-type") { (name) } + div(class = "regulator-label") { (Axis::NAME[self.axis as usize]) } + div(class = "regulator-type") { "Coordinate" } RegulatorInput(regulator = self) div(class = "status") } diff --git a/app-proto/src/components/test_assembly_chooser.rs b/app-proto/src/components/test_assembly_chooser.rs index 95a2166..0d387d3 100644 --- a/app-proto/src/components/test_assembly_chooser.rs +++ b/app-proto/src/components/test_assembly_chooser.rs @@ -5,7 +5,7 @@ use sycamore::prelude::*; use web_sys::{console, wasm_bindgen::JsValue}; use crate::{ - appState::AppState, + AppState, assembly::{ Assembly, Element, diff --git a/app-proto/src/engine.rs b/app-proto/src/engine.rs index e6bf712..feb23cf 100644 --- a/app-proto/src/engine.rs +++ b/app-proto/src/engine.rs @@ -2,8 +2,6 @@ use lazy_static::lazy_static; use nalgebra::{Const, DMatrix, DVector, DVectorView, Dyn, SymmetricEigen}; use std::fmt::{Display, Error, Formatter}; -use crate::assembly::Point; - // --- elements --- pub fn point(x: f64, y: f64, z: f64) -> DVector { @@ -48,7 +46,7 @@ pub fn project_sphere_to_normalized(rep: &mut DVector) { // normalize a point's representation vector by scaling pub fn project_point_to_normalized(rep: &mut DVector) { - rep.scale_mut(0.5 / rep[Point::WEIGHT_COMPONENT]); + rep.scale_mut(0.5 / rep[3]); //FIXME: This 3 should be Point::WEIGHT_COMPONENT } // --- partial matrices --- diff --git a/app-proto/src/lib.rs b/app-proto/src/lib.rs index 1f418a8..0d9bc4a 100644 --- a/app-proto/src/lib.rs +++ b/app-proto/src/lib.rs @@ -1,5 +1 @@ -mod appState; -mod assembly; -mod components; -pub mod engine; -mod specified; \ No newline at end of file +pub mod engine; \ No newline at end of file diff --git a/app-proto/src/main.rs b/app-proto/src/main.rs index 61a04b1..a03b026 100644 --- a/app-proto/src/main.rs +++ b/app-proto/src/main.rs @@ -1,4 +1,3 @@ -mod appState; mod assembly; mod components; mod engine; @@ -10,7 +9,6 @@ mod tests; use std::{collections::BTreeSet, rc::Rc}; use sycamore::prelude::*; -use appState::AppState; use assembly::{Assembly, Element}; use components::{ add_remove::AddRemove, @@ -19,6 +17,38 @@ use components::{ outline::Outline, }; +#[derive(Clone)] +struct AppState { + assembly: Assembly, + selection: Signal>>, +} + +impl AppState { + fn new() -> Self { + Self { + assembly: Assembly::new(), + selection: create_signal(BTreeSet::default()), + } + } + + // in single-selection mode, select the given element. in multiple-selection + // mode, toggle whether the given element is selected + fn select(&self, element: &Rc, multi: bool) { + if multi { + self.selection.update(|sel| { + if !sel.remove(element) { + sel.insert(element.clone()); + } + }); + } else { + self.selection.update(|sel| { + sel.clear(); + sel.insert(element.clone()); + }); + } + } +} + fn main() { // set the console error panic hook #[cfg(feature = "console_error_panic_hook")]