diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index c263692..d48172f 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -270,7 +270,7 @@ pub struct Point { } impl Point { - const WEIGHT_COMPONENT: usize = 3; + pub const WEIGHT_COMPONENT: usize = 3; const NORM_COMPONENT: usize = 4; pub fn new( @@ -514,8 +514,7 @@ impl ProblemPoser for HalfCurvatureRegulator { pub enum Axis {X = 0, Y = 1, Z = 2} impl Axis { - pub const N_AXIS: usize = (Axis::Z as usize) + 1; - pub const NAME: [&str; Axis::N_AXIS] = ["X", "Y", "Z"]; + pub const NAME: [&str; Axis::CARDINALITY] = ["X", "Y", "Z"]; } pub struct PointCoordinateRegulator { @@ -555,15 +554,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::N_AXIS]; + let mut coords = [0.0; Axis::CARDINALITY]; let mut nset: usize = 0; for &MatrixEntry {index, value} in &(problem.frozen) { - if index.1 == col && index.0 < Axis::N_AXIS { + if index.1 == col && index.0 < Axis::CARDINALITY { nset += 1; coords[index.0] = value } } - if nset == Axis::N_AXIS { + if nset == Axis::CARDINALITY { 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 4196640..c22577a 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 51d58f1..323f95a 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, specified::SpecifiedValue}; +use crate::{appState::AppState, specified::SpecifiedValue}; #[derive(Clone)] struct DiagnosticsState { diff --git a/app-proto/src/components/display.rs b/app-proto/src/components/display.rs index 98be85e..aa4c3c2 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 79781fa..ecbb724 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,10 +123,11 @@ 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") { (Axis::NAME[self.axis as usize]) } - div(class = "regulator-type") { "Coordinate" } + div(class = "regulator-label") // for spacing + div(class = "regulator-type") { (name) } 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 0d387d3..95a2166 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 feb23cf..e6bf712 100644 --- a/app-proto/src/engine.rs +++ b/app-proto/src/engine.rs @@ -2,6 +2,8 @@ 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 { @@ -46,7 +48,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[3]); //FIXME: This 3 should be Point::WEIGHT_COMPONENT + rep.scale_mut(0.5 / rep[Point::WEIGHT_COMPONENT]); } // --- partial matrices --- diff --git a/app-proto/src/lib.rs b/app-proto/src/lib.rs index 0d9bc4a..1f418a8 100644 --- a/app-proto/src/lib.rs +++ b/app-proto/src/lib.rs @@ -1 +1,5 @@ -pub mod engine; \ No newline at end of file +mod appState; +mod assembly; +mod components; +pub mod engine; +mod specified; \ No newline at end of file diff --git a/app-proto/src/main.rs b/app-proto/src/main.rs index a03b026..61a04b1 100644 --- a/app-proto/src/main.rs +++ b/app-proto/src/main.rs @@ -1,3 +1,4 @@ +mod appState; mod assembly; mod components; mod engine; @@ -9,6 +10,7 @@ mod tests; use std::{collections::BTreeSet, rc::Rc}; use sycamore::prelude::*; +use appState::AppState; use assembly::{Assembly, Element}; use components::{ add_remove::AddRemove, @@ -17,38 +19,6 @@ 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")]