From adc60ac5c160ceee11ee205352a1665b29fc6e94 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Tue, 7 Oct 2025 16:19:14 -0700 Subject: [PATCH] Spruce up formatting and error messages Make the new code's formatting and error messages more consistent with the previous code. I don't necessarily have a strong preference for the previous conventions, but I do like stuff to be consistent. --- app-proto/src/assembly.rs | 63 +++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/app-proto/src/assembly.rs b/app-proto/src/assembly.rs index 4da9422..b1e5d7c 100644 --- a/app-proto/src/assembly.rs +++ b/app-proto/src/assembly.rs @@ -305,13 +305,14 @@ impl Element for Point { point(0.0, 0.0, 0.0), ) } - + fn default_regulators(self: Rc) -> Vec> { all::() - .map(|axis| { - Rc::new(PointCoordinateRegulator::new(self.clone(), axis)) - as Rc:: - }) + .map( + |axis| Rc::new( + PointCoordinateRegulator::new(self.clone(), axis) + ) as Rc:: + ) .collect() } @@ -538,19 +539,32 @@ impl PointCoordinateRegulator { let measurement = subject.representation().map( move |rep| rep[axis as usize] ); + let set_point = create_signal(SpecifiedValue::from_empty_spec()); - Self { subject, axis, measurement, set_point, serial: Self::next_serial() } + let serial = Self::next_serial(); + + Self { subject, axis, measurement, set_point, serial } } } impl Serial for PointCoordinateRegulator { - fn serial(&self) -> u64 { self.serial } + fn serial(&self) -> u64 { + self.serial + } } impl Regulator for PointCoordinateRegulator { - fn subjects(&self) -> Vec> { vec![self.subject.clone()] } - fn measurement(&self) -> ReadSignal { self.measurement } - fn set_point(&self) -> Signal { self.set_point } + fn subjects(&self) -> Vec> { + vec![self.subject.clone()] + } + + fn measurement(&self) -> ReadSignal { + self.measurement + } + + fn set_point(&self) -> Signal { + self.set_point + } } impl ProblemPoser for PointCoordinateRegulator { @@ -558,22 +572,25 @@ impl ProblemPoser for PointCoordinateRegulator { self.set_point.with_untracked(|set_pt| { if let Some(val) = set_pt.value { let col = self.subject.column_index().expect( - "Subject must be indexed before point-coordinate regulator poses."); + "Subject should be indexed before point coordinate regulator writes problem data" + ); problem.frozen.push(self.axis as usize, col, val); - // Check if all three spatial coordinates have been frozen, and if so, - // freeze the norm component as well - 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::CARDINALITY { - nset += 1; - coords[index.0] = value + + // if all three of the subject's spatial coordinates have been + // frozen, then freeze its norm component too + let mut coords_frozen = [0.0; Axis::CARDINALITY]; + let mut n_set: usize = 0; + for &MatrixEntry { index, value } in &(problem.frozen) { + let (row_frozen, col_frozen) = index; + if col_frozen == col && row_frozen < Axis::CARDINALITY { + n_set += 1; + coords_frozen[row_frozen] = value } } - if nset == Axis::CARDINALITY { - let [x, y, z] = coords; - problem.frozen.push( - Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]); + if n_set == Axis::CARDINALITY { + let [x, y, z] = coords_frozen; + let norm = point(x, y, z)[Point::NORM_COMPONENT]; + problem.frozen.push(Point::NORM_COMPONENT, col, norm); } } });