Dispatch normalization routines correctly #87
2 changed files with 14 additions and 13 deletions
|
@ -18,9 +18,9 @@ use crate::{
|
||||||
Q,
|
Q,
|
||||||
change_half_curvature,
|
change_half_curvature,
|
||||||
local_unif_to_std,
|
local_unif_to_std,
|
||||||
normalize_mut_point,
|
|
||||||
normalize_mut_sphere,
|
|
||||||
point,
|
point,
|
||||||
|
project_point_to_normalized,
|
||||||
|
project_sphere_to_normalized,
|
||||||
realize_gram,
|
realize_gram,
|
||||||
sphere,
|
sphere,
|
||||||
ConfigSubspace,
|
ConfigSubspace,
|
||||||
|
@ -108,8 +108,9 @@ pub trait Element: Serial + ProblemPoser + DisplayItem {
|
||||||
// element is responsible for keeping this set up to date
|
// element is responsible for keeping this set up to date
|
||||||
fn regulators(&self) -> Signal<BTreeSet<Rc<dyn Regulator>>>;
|
fn regulators(&self) -> Signal<BTreeSet<Rc<dyn Regulator>>>;
|
||||||
|
|
||||||
glen marked this conversation as resolved
Outdated
|
|||||||
// normalize a representation vector for this kind of element
|
// project a representation vector for this kind of element onto its
|
||||||
fn normalize_mut_rep(&self, rep: &mut DVector<f64>);
|
// normalization variety
|
||||||
|
fn project_to_normalized(&self, rep: &mut DVector<f64>);
|
||||||
|
|
||||||
// the configuration matrix column index that was assigned to the element
|
// the configuration matrix column index that was assigned to the element
|
||||||
// last time the assembly was realized, or `None` if the element has never
|
// last time the assembly was realized, or `None` if the element has never
|
||||||
|
@ -225,8 +226,8 @@ impl Element for Sphere {
|
||||||
self.regulators
|
self.regulators
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_mut_rep(&self, rep: &mut DVector<f64>) {
|
fn project_to_normalized(&self, rep: &mut DVector<f64>) {
|
||||||
normalize_mut_sphere(rep);
|
project_sphere_to_normalized(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_index(&self) -> Option<usize> {
|
fn column_index(&self) -> Option<usize> {
|
||||||
|
@ -321,8 +322,8 @@ impl Element for Point {
|
||||||
self.regulators
|
self.regulators
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_mut_rep(&self, rep: &mut DVector<f64>) {
|
fn project_to_normalized(&self, rep: &mut DVector<f64>) {
|
||||||
normalize_mut_point(rep);
|
project_point_to_normalized(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_index(&self) -> Option<usize> {
|
fn column_index(&self) -> Option<usize> {
|
||||||
|
@ -789,7 +790,7 @@ impl Assembly {
|
||||||
// step the element along the deformation and then
|
// step the element along the deformation and then
|
||||||
// restore its normalization
|
// restore its normalization
|
||||||
*rep += motion_proj.column(column_index);
|
*rep += motion_proj.column(column_index);
|
||||||
elt.normalize_mut_rep(rep);
|
elt.project_to_normalized(rep);
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
console_log!("No velocity to unpack for fresh element \"{}\"", elt.id())
|
console_log!("No velocity to unpack for fresh element \"{}\"", elt.id())
|
||||||
|
|
|
@ -35,9 +35,9 @@ pub fn sphere_with_offset(dir_x: f64, dir_y: f64, dir_z: f64, off: f64, curv: f6
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize a sphere's representation vector by contracting toward the last
|
// project a sphere's representation vector to the normalization variety by
|
||||||
// coordinate axis
|
// contracting toward the last coordinate axis
|
||||||
pub fn normalize_mut_sphere(rep: &mut DVector<f64>) {
|
pub fn project_sphere_to_normalized(rep: &mut DVector<f64>) {
|
||||||
let q_sp = rep.fixed_rows::<3>(0).norm_squared();
|
let q_sp = rep.fixed_rows::<3>(0).norm_squared();
|
||||||
let half_q_lt = -2.0 * rep[3] * rep[4];
|
let half_q_lt = -2.0 * rep[3] * rep[4];
|
||||||
let half_q_lt_sq = half_q_lt * half_q_lt;
|
let half_q_lt_sq = half_q_lt * half_q_lt;
|
||||||
|
@ -46,7 +46,7 @@ pub fn normalize_mut_sphere(rep: &mut DVector<f64>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize a point's representation vector by scaling
|
// normalize a point's representation vector by scaling
|
||||||
pub fn normalize_mut_point(rep: &mut DVector<f64>) {
|
pub fn project_point_to_normalized(rep: &mut DVector<f64>) {
|
||||||
rep.scale_mut(0.5 / rep[3]);
|
rep.scale_mut(0.5 / rep[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue
Do you like the word "normalize" or "canonicalize"? I feel like the latter more explicitly means "choose the favored representative of an equivalence class" (which I think is mainly what's going on here) and the former can have broader meanings in which the entity is actually changed, like when you find a unit vector in the same direction -- I think that's sometimes called normalization. Only make a change if you feel like "canonicalize" would be a better/clearer choice.
In my mind, an element is represented by a line through the origin in
\mathbb{R}^{4,1}
, so choosing a favored representative is equivalent to choosing a particular scaling. That's why I used the word "normalization." However, the implementation ofnormalize_rep_mut
for spheres actually changes the equivalence class. That's because the only thing we usenormalize_rep_mut
for right now is to keep elements normalized during nudging, and normalizing in a way that preserves the equivalence class makes nudging less stable. If both "normalize" and "canonicalize" imply staying within an equivalence class for you, then maybe we need another term entirely.Ah, hmm, I hadn't appreciated that the result of normalize_rep_mut might be in a different equivalence class. "Normalize" does not by itself connote "stay in the same equivalence class, but "normalize representation" does seem to imply strongly that we are just choosing a different representation of the same entity. So I would agree the name needs to change -- but just "normalize" without the "representation" would be OK, since we're not just picking a different representation of the same geometric entity. If you don't like that, perhaps "stabilize" or "standardize" or "choose_canonical" or "nearby_canonical" or something?
How about something like
proj_to_normalized
, to communicate that we're projecting the given representation vector to the normalized configuration variety for the given element type?The
rep
isn't working as intended in the namenormalize_rep_mut
anyway. I added it to emphasize that this method acts on the representation vector provided as an argument, not the vector representing the element the method is called from. This makes it different from thenormalize_mut
methods for nalgebra matrices.(Using an associated function instead of a method would be the best way to clarify this, but I don't think it's possible to call associated functions from trait objects. This complaint about the limitation and this unsuccessful attempt to lift the limitation seem to demonstrate that it exists, or at least used to exist. If you want, though, I can try again to use an associated function and look at exactly what compiler error it produced.)
Sure, any of
project_to_canonical
orproject_to_normal
orproject_to_normalized
orcanonical_projection
ornormal_projection
would be fine, whatever seems simplest/clearest to you. I'd suggest that with a name that's already this long, there's no point in abbreviating withproj
-- just use whatever full wordproj
would be an abbreviation for. Using a method is fine, don't worry about the associated function thing.I just pushed a commit with better names (
54b34e0582
). My look-over before pushing was a bit cursory; I'll look at it harder later today.I've looked at the renaming commit again and I still think it's fine, so let me know what you think!