Compare commits

..

No commits in common. "da9312ad7116dac397cd28e976914220f12a5dec" and "ecbbe2068c2003ff848292364d42a63f97b03698" have entirely different histories.

9 changed files with 47 additions and 23 deletions

View file

@ -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]);

View file

@ -3,7 +3,7 @@ use sycamore::prelude::*;
use super::test_assembly_chooser::TestAssemblyChooser;
use crate::{
appState::AppState,
AppState,
assembly::{InversiveDistanceRegulator, Point, Sphere},
};

View file

@ -7,7 +7,7 @@ use charming::{
};
use sycamore::prelude::*;
use crate::{appState::AppState, specified::SpecifiedValue};
use crate::{AppState, specified::SpecifiedValue};
#[derive(Clone)]
struct DiagnosticsState {

View file

@ -16,7 +16,7 @@ use web_sys::{
};
use crate::{
appState::AppState,
AppState,
assembly::{Element, ElementColor, ElementMotion, Point, Sphere},
};

View file

@ -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<Self>, _element: &Rc<dyn Element>) -> 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")
}

View file

@ -5,7 +5,7 @@ use sycamore::prelude::*;
use web_sys::{console, wasm_bindgen::JsValue};
use crate::{
appState::AppState,
AppState,
assembly::{
Assembly,
Element,

View file

@ -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<f64> {
@ -48,7 +46,7 @@ pub fn project_sphere_to_normalized(rep: &mut DVector<f64>) {
// normalize a point's representation vector by scaling
pub fn project_point_to_normalized(rep: &mut DVector<f64>) {
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 ---

View file

@ -1,5 +1 @@
mod appState;
mod assembly;
mod components;
pub mod engine;
mod specified;
pub mod engine;

View file

@ -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<BTreeSet<Rc<dyn Element>>>,
}
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<dyn Element>, 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")]