chore: Remove trailing whitespace #129

Open
glen wants to merge 10 commits from glen/dyna3:noTrailingWhitespace into main
Showing only changes of commit d68f0d2b15 - Show all commits

View file

@ -256,19 +256,12 @@ impl Serial for Sphere {
} }
} }
fn index_message(thing: &str, name: &str, actor: &str) -> String {
format!(
"{thing} \"{name}\" must be indexed before {actor} writes problem data"
)
}
impl ProblemPoser for Sphere { impl ProblemPoser for Sphere {
fn pose(&self, problem: &mut ConstraintProblem) { fn pose(&self, problem: &mut ConstraintProblem) {
let index = self.column_index().expect( let index = self.column_index().expect(
indexing_error("Sphere", &self.id, "it").as_str()); indexing_error("Sphere", &self.id, "it").as_str());
problem.gram.push_sym(index, index, 1.0); problem.gram.push_sym(index, index, 1.0);
problem.guess.set_column( problem.guess.set_column(index, &self.representation.get_clone_untracked());
index, &self.representation.get_clone_untracked());
} }
} }
@ -374,8 +367,7 @@ impl ProblemPoser for Point {
indexing_error("Point", &self.id, "it").as_str()); indexing_error("Point", &self.id, "it").as_str());
problem.gram.push_sym(index, index, 0.0); problem.gram.push_sym(index, index, 0.0);
problem.frozen.push(Self::WEIGHT_COMPONENT, index, 0.5); problem.frozen.push(Self::WEIGHT_COMPONENT, index, 0.5);
problem.guess.set_column( problem.guess.set_column(index, &self.representation.get_clone_untracked());
index, &self.representation.get_clone_untracked());
} }
} }
@ -420,8 +412,7 @@ pub struct InversiveDistanceRegulator {
impl InversiveDistanceRegulator { impl InversiveDistanceRegulator {
pub fn new(subjects: [Rc<dyn Element>; 2]) -> Self { pub fn new(subjects: [Rc<dyn Element>; 2]) -> Self {
let representations = subjects.each_ref().map( let representations = subjects.each_ref().map(|subj| subj.representation());
|subj| subj.representation());
let measurement = create_memo(move || { let measurement = create_memo(move || {
representations[0].with(|rep_0| representations[0].with(|rep_0|
representations[1].with(|rep_1| representations[1].with(|rep_1|
@ -553,9 +544,7 @@ impl PointCoordinateRegulator {
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());
Self { Self { subject, axis, measurement, set_point, serial: Self::next_serial() }
subject, axis, measurement, set_point, serial: Self::next_serial()
}
} }
} }
@ -590,9 +579,7 @@ impl ProblemPoser for PointCoordinateRegulator {
if nset == Axis::CARDINALITY { if nset == Axis::CARDINALITY {
let [x, y, z] = coords; let [x, y, z] = coords;
problem.frozen.push( problem.frozen.push(
Point::NORM_COMPONENT, Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]);
col,
point(x,y,z)[Point::NORM_COMPONENT]);
} }
} }
}); });
@ -691,8 +678,7 @@ impl Assembly {
let id = elt.id().clone(); let id = elt.id().clone();
let elt_rc = Rc::new(elt); let elt_rc = Rc::new(elt);
self.elements.update(|elts| elts.insert(elt_rc.clone())); self.elements.update(|elts| elts.insert(elt_rc.clone()));
self.elements_by_id.update( self.elements_by_id.update(|elts_by_id| elts_by_id.insert(id, elt_rc.clone()));
|elts_by_id| elts_by_id.insert(id, elt_rc.clone()));
// create and insert the element's default regulators // create and insert the element's default regulators
for reg in elt_rc.default_regulators() { for reg in elt_rc.default_regulators() {
@ -701,9 +687,7 @@ impl Assembly {
} }
pub fn try_insert_element(&self, elt: impl Element + 'static) -> bool { pub fn try_insert_element(&self, elt: impl Element + 'static) -> bool {
let can_insert = self.elements_by_id.with_untracked( let can_insert = self.elements_by_id.with_untracked(|elts_by_id| !elts_by_id.contains_key(elt.id()));
|elts_by_id| !elts_by_id.contains_key(elt.id())
);
if can_insert { if can_insert {
self.insert_element_unchecked(elt); self.insert_element_unchecked(elt);
} }
@ -768,8 +752,7 @@ impl Assembly {
pub fn load_config(&self, config: &DMatrix<f64>) { pub fn load_config(&self, config: &DMatrix<f64>) {
for elt in self.elements.get_clone_untracked() { for elt in self.elements.get_clone_untracked() {
elt.representation().update( elt.representation().update(
|rep| rep.set_column( |rep| rep.set_column(0, &config.column(elt.column_index().unwrap()))
0, &config.column(elt.column_index().unwrap()))
); );
} }
} }
@ -914,8 +897,7 @@ impl Assembly {
if column_index < realized_dim { if column_index < realized_dim {
// this element had a column index when we started, so by // this element had a column index when we started, so by
// invariant (1), it's reflected in the tangent space // invariant (1), it's reflected in the tangent space
let mut target_columns = let mut target_columns = motion_proj.columns_mut(0, realized_dim);
motion_proj.columns_mut(0, realized_dim);
target_columns += self.tangent.with( target_columns += self.tangent.with(
|tan| tan.proj(&elt_motion.velocity, column_index) |tan| tan.proj(&elt_motion.velocity, column_index)
); );
@ -923,10 +905,9 @@ impl Assembly {
// this element didn't have a column index when we started, so // this element didn't have a column index when we started, so
// by invariant (2), it's unconstrained // by invariant (2), it's unconstrained
let mut target_column = motion_proj.column_mut(column_index); let mut target_column = motion_proj.column_mut(column_index);
let unif_to_std = elt_motion let unif_to_std = elt_motion.element.representation().with_untracked(
.element.representation() |rep| local_unif_to_std(rep.as_view())
.with_untracked( );
|rep| local_unif_to_std(rep.as_view()));
target_column += unif_to_std * elt_motion.velocity; target_column += unif_to_std * elt_motion.velocity;
} }
} }
@ -943,9 +924,7 @@ impl Assembly {
elt.project_to_normalized(rep); elt.project_to_normalized(rep);
}, },
None => { None => {
console_log!( console_log!("No velocity to unpack for fresh element \"{}\"", elt.id())
"No velocity to unpack for fresh element \"{}\"",
elt.id())
}, },
}; };
}); });
@ -980,15 +959,13 @@ mod tests {
fn unindexed_subject_test_inversive_distance() { fn unindexed_subject_test_inversive_distance() {
let _ = create_root(|| { let _ = create_root(|| {
let subjects = [0, 1].map( let subjects = [0, 1].map(
|k| Rc::new(Sphere::default( |k| Rc::new(Sphere::default(format!("sphere{k}"), k)) as Rc<dyn Element>
format!("sphere{k}"), k)) as Rc<dyn Element>
); );
subjects[0].set_column_index(0); subjects[0].set_column_index(0);
InversiveDistanceRegulator { InversiveDistanceRegulator {
subjects: subjects, subjects: subjects,
measurement: create_memo(|| 0.0), measurement: create_memo(|| 0.0),
set_point: create_signal( set_point: create_signal(SpecifiedValue::try_from("0.0".to_string()).unwrap()),
SpecifiedValue::try_from("0.0".to_string()).unwrap()),
serial: InversiveDistanceRegulator::next_serial() serial: InversiveDistanceRegulator::next_serial()
}.pose(&mut ConstraintProblem::new(2)); }.pose(&mut ConstraintProblem::new(2));
}); });
@ -1017,10 +994,8 @@ mod tests {
// nudge the sphere repeatedly along the `z` axis // nudge the sphere repeatedly along the `z` axis
const STEP_SIZE: f64 = 0.0025; const STEP_SIZE: f64 = 0.0025;
const STEP_CNT: usize = 400; const STEP_CNT: usize = 400;
let sphere = assembly.elements_by_id.with( let sphere = assembly.elements_by_id.with(|elts_by_id| elts_by_id[sphere_id].clone());
|elts_by_id| elts_by_id[sphere_id].clone()); let velocity = DVector::from_column_slice(&[0.0, 0.0, STEP_SIZE, 0.0]);
let velocity =
DVector::from_column_slice(&[0.0, 0.0, STEP_SIZE, 0.0]);
for _ in 0..STEP_CNT { for _ in 0..STEP_CNT {
assembly.deform( assembly.deform(
vec![ vec![
@ -1038,8 +1013,7 @@ mod tests {
let final_half_curv = sphere.representation().with_untracked( let final_half_curv = sphere.representation().with_untracked(
|rep| rep[Sphere::CURVATURE_COMPONENT] |rep| rep[Sphere::CURVATURE_COMPONENT]
); );
assert!((final_half_curv / INITIAL_HALF_CURV - 1.0).abs() assert!((final_half_curv / INITIAL_HALF_CURV - 1.0).abs() < DRIFT_TOL);
< DRIFT_TOL);
}); });
} }
} }