This commit is contained in:
parent
ecbbe2068c
commit
da9312ad71
9 changed files with 23 additions and 47 deletions
|
@ -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]);
|
||||
|
|
|
@ -3,7 +3,7 @@ use sycamore::prelude::*;
|
|||
|
||||
use super::test_assembly_chooser::TestAssemblyChooser;
|
||||
use crate::{
|
||||
AppState,
|
||||
appState::AppState,
|
||||
assembly::{InversiveDistanceRegulator, Point, Sphere},
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use charming::{
|
|||
};
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use crate::{AppState, specified::SpecifiedValue};
|
||||
use crate::{appState::AppState, specified::SpecifiedValue};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DiagnosticsState {
|
||||
|
|
|
@ -16,7 +16,7 @@ use web_sys::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
AppState,
|
||||
appState::AppState,
|
||||
assembly::{Element, ElementColor, ElementMotion, Point, Sphere},
|
||||
};
|
||||
|
||||
|
|
|
@ -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<Self>, _element: &Rc<dyn Element>) -> 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")
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use sycamore::prelude::*;
|
|||
use web_sys::{console, wasm_bindgen::JsValue};
|
||||
|
||||
use crate::{
|
||||
AppState,
|
||||
appState::AppState,
|
||||
assembly::{
|
||||
Assembly,
|
||||
Element,
|
||||
|
|
|
@ -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<f64> {
|
||||
|
@ -46,7 +48,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[3]); //FIXME: This 3 should be Point::WEIGHT_COMPONENT
|
||||
rep.scale_mut(0.5 / rep[Point::WEIGHT_COMPONENT]);
|
||||
}
|
||||
|
||||
// --- partial matrices ---
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
pub mod engine;
|
||||
mod appState;
|
||||
mod assembly;
|
||||
mod components;
|
||||
pub mod engine;
|
||||
mod specified;
|
|
@ -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<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")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue