feat: Point coordinate regulators #118

Merged
Vectornaut merged 9 commits from glen/dyna3:pointCoordRegulators into main 2025-10-13 22:52:03 +00:00
3 changed files with 11 additions and 10 deletions
Showing only changes of commit 46ffd6c285 - Show all commits

View file

@ -514,8 +514,7 @@ impl ProblemPoser for HalfCurvatureRegulator {
pub enum Axis {X = 0, Y = 1, Z = 2} pub enum Axis {X = 0, Y = 1, Z = 2}
impl Axis { impl Axis {
pub const N_AXIS: usize = (Axis::Z as usize) + 1; pub const NAME: [&str; Axis::CARDINALITY] = ["X", "Y", "Z"];
pub const NAME: [&str; Axis::N_AXIS] = ["X", "Y", "Z"];
} }
pub struct PointCoordinateRegulator { pub struct PointCoordinateRegulator {
@ -553,17 +552,17 @@ impl ProblemPoser for PointCoordinateRegulator {
let col = self.subject.column_index().expect( let col = self.subject.column_index().expect(
"Subject must be indexed before point-coordinate regulator poses."); "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 coordinates have been frozen, and if so, // Check if all three spatial coordinates have been frozen, and if so,
// freeze the coradius as well // freeze the norm component as well
let mut coords = [0.0; Axis::N_AXIS]; let mut coords = [0.0; Axis::CARDINALITY];
let mut nset: usize = 0; let mut nset: usize = 0;
for &MatrixEntry {index, value} in &(problem.frozen) { 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; nset += 1;
coords[index.0] = value coords[index.0] = value
} }
} }
if nset == Axis::N_AXIS { if nset == Axis::CARDINALITY {
let [x, y, z] = coords; let [x, y, z] = coords;
problem.frozen.push( problem.frozen.push(
Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]); Point::NORM_COMPONENT, col, point(x,y,z)[Point::NORM_COMPONENT]);
@ -773,6 +772,7 @@ impl Assembly {
/* DEBUG */ /* DEBUG */
// log the Gram matrix // log the Gram matrix
console_log!("Gram matrix:\n{}", problem.gram); console_log!("Gram matrix:\n{}", problem.gram);
console_log!("Frozen entries:\n{}", problem.frozen);
/* DEBUG */ /* DEBUG */
// log the initial configuration matrix // log the initial configuration matrix

View file

@ -123,10 +123,11 @@ 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", Axis::NAME[self.axis as usize]);
view! { view! {
li(class = "regulator") { li(class = "regulator") {
div(class = "regulator-label") { (Axis::NAME[self.axis as usize]) } div(class = "regulator-label") // for spacing
div(class = "regulator-type") { "Coordinate" } div(class = "regulator-type") { (name) }
RegulatorInput(regulator = self) RegulatorInput(regulator = self)
div(class = "status") div(class = "status")
} }

View file

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