forked from StudioInfinity/dyna3
Compare commits
No commits in common. "adc60ac5c160ceee11ee205352a1665b29fc6e94" and "46ffd6c285b6a6b924a1083f67057bdff5206379" have entirely different histories.
adc60ac5c1
...
46ffd6c285
2 changed files with 28 additions and 52 deletions
|
|
@ -127,7 +127,7 @@ pub trait Element: Serial + ProblemPoser + DisplayItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for dyn Element {
|
impl Debug for dyn Element {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
self.id().fmt(f)
|
self.id().fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -305,14 +305,13 @@ impl Element for Point {
|
||||||
point(0.0, 0.0, 0.0),
|
point(0.0, 0.0, 0.0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_regulators(self: Rc<Self>) -> Vec<Rc<dyn Regulator>> {
|
fn default_regulators(self: Rc<Self>) -> Vec<Rc<dyn Regulator>> {
|
||||||
all::<Axis>()
|
all::<Axis>()
|
||||||
.map(
|
.map(|axis| {
|
||||||
|axis| Rc::new(
|
Rc::new(PointCoordinateRegulator::new(self.clone(), axis))
|
||||||
PointCoordinateRegulator::new(self.clone(), axis)
|
as Rc::<dyn Regulator>
|
||||||
) as Rc::<dyn Regulator>
|
})
|
||||||
)
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -512,18 +511,10 @@ impl ProblemPoser for HalfCurvatureRegulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Sequence)]
|
#[derive(Clone, Copy, Sequence)]
|
||||||
pub enum Axis { X = 0, Y = 1, Z = 2 }
|
pub enum Axis {X = 0, Y = 1, Z = 2}
|
||||||
|
|
||||||
impl Axis {
|
impl Axis {
|
||||||
fn name(&self) -> &'static str {
|
pub const NAME: [&str; Axis::CARDINALITY] = ["X", "Y", "Z"];
|
||||||
match self { Axis::X => "X", Axis::Y => "Y", Axis::Z => "Z" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Axis {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str(self.name())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PointCoordinateRegulator {
|
pub struct PointCoordinateRegulator {
|
||||||
|
|
@ -539,32 +530,19 @@ impl PointCoordinateRegulator {
|
||||||
let measurement = subject.representation().map(
|
let measurement = subject.representation().map(
|
||||||
move |rep| rep[axis as usize]
|
move |rep| rep[axis as usize]
|
||||||
);
|
);
|
||||||
|
|
||||||
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
let set_point = create_signal(SpecifiedValue::from_empty_spec());
|
||||||
let serial = Self::next_serial();
|
Self { subject, axis, measurement, set_point, serial: Self::next_serial() }
|
||||||
|
|
||||||
Self { subject, axis, measurement, set_point, serial }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serial for PointCoordinateRegulator {
|
impl Serial for PointCoordinateRegulator {
|
||||||
fn serial(&self) -> u64 {
|
fn serial(&self) -> u64 { self.serial }
|
||||||
self.serial
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Regulator for PointCoordinateRegulator {
|
impl Regulator for PointCoordinateRegulator {
|
||||||
fn subjects(&self) -> Vec<Rc<dyn Element>> {
|
fn subjects(&self) -> Vec<Rc<dyn Element>> { vec![self.subject.clone()] }
|
||||||
vec![self.subject.clone()]
|
fn measurement(&self) -> ReadSignal<f64> { self.measurement }
|
||||||
}
|
fn set_point(&self) -> Signal<SpecifiedValue> { self.set_point }
|
||||||
|
|
||||||
fn measurement(&self) -> ReadSignal<f64> {
|
|
||||||
self.measurement
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_point(&self) -> Signal<SpecifiedValue> {
|
|
||||||
self.set_point
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProblemPoser for PointCoordinateRegulator {
|
impl ProblemPoser for PointCoordinateRegulator {
|
||||||
|
|
@ -572,25 +550,22 @@ impl ProblemPoser for PointCoordinateRegulator {
|
||||||
self.set_point.with_untracked(|set_pt| {
|
self.set_point.with_untracked(|set_pt| {
|
||||||
if let Some(val) = set_pt.value {
|
if let Some(val) = set_pt.value {
|
||||||
let col = self.subject.column_index().expect(
|
let col = self.subject.column_index().expect(
|
||||||
"Subject should be indexed before point coordinate regulator writes problem data"
|
"Subject must be indexed before point-coordinate regulator poses.");
|
||||||
);
|
|
||||||
problem.frozen.push(self.axis as usize, col, val);
|
problem.frozen.push(self.axis as usize, col, val);
|
||||||
|
// Check if all three spatial coordinates have been frozen, and if so,
|
||||||
// if all three of the subject's spatial coordinates have been
|
// freeze the norm component as well
|
||||||
// frozen, then freeze its norm component too
|
let mut coords = [0.0; Axis::CARDINALITY];
|
||||||
let mut coords_frozen = [0.0; Axis::CARDINALITY];
|
let mut nset: usize = 0;
|
||||||
let mut n_set: usize = 0;
|
for &MatrixEntry {index, value} in &(problem.frozen) {
|
||||||
for &MatrixEntry { index, value } in &(problem.frozen) {
|
if index.1 == col && index.0 < Axis::CARDINALITY {
|
||||||
let (row_frozen, col_frozen) = index;
|
nset += 1;
|
||||||
if col_frozen == col && row_frozen < Axis::CARDINALITY {
|
coords[index.0] = value
|
||||||
n_set += 1;
|
|
||||||
coords_frozen[row_frozen] = value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n_set == Axis::CARDINALITY {
|
if nset == Axis::CARDINALITY {
|
||||||
let [x, y, z] = coords_frozen;
|
let [x, y, z] = coords;
|
||||||
let norm = point(x, y, z)[Point::NORM_COMPONENT];
|
problem.frozen.push(
|
||||||
problem.frozen.push(Point::NORM_COMPONENT, col, norm);
|
Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use web_sys::{KeyboardEvent, MouseEvent, wasm_bindgen::JsCast};
|
||||||
use crate::{
|
use crate::{
|
||||||
AppState,
|
AppState,
|
||||||
assembly::{
|
assembly::{
|
||||||
|
Axis,
|
||||||
Element,
|
Element,
|
||||||
HalfCurvatureRegulator,
|
HalfCurvatureRegulator,
|
||||||
InversiveDistanceRegulator,
|
InversiveDistanceRegulator,
|
||||||
|
|
@ -122,7 +123,7 @@ impl OutlineItem for HalfCurvatureRegulator {
|
||||||
|
|
||||||
impl OutlineItem for PointCoordinateRegulator {
|
impl OutlineItem for PointCoordinateRegulator {
|
||||||
fn outline_item(self: Rc<Self>, _element: &Rc<dyn Element>) -> View {
|
fn outline_item(self: Rc<Self>, _element: &Rc<dyn Element>) -> View {
|
||||||
let name = format!("{} coordinate", self.axis);
|
let name = format!("{} coordinate", Axis::NAME[self.axis as usize]);
|
||||||
view! {
|
view! {
|
||||||
li(class = "regulator") {
|
li(class = "regulator") {
|
||||||
div(class = "regulator-label") // for spacing
|
div(class = "regulator-label") // for spacing
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue