Skip to content

Commit

Permalink
Fix hashmap iteration bug in building FK files
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Dec 24, 2024
1 parent 390219d commit 9cfa462
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
18 changes: 8 additions & 10 deletions anise/src/naif/kpl/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,16 @@ pub fn convert_fk<P: AsRef<Path> + fmt::Debug>(
}
// Build the quaternion from the Euler matrices
let from = id;
let mut to = item.data[&Parameter::Center].to_i32().unwrap();
let to = item.data[&Parameter::Center].to_i32().unwrap();
if let Some(class) = item.data.get(&Parameter::Class) {
if class.to_i32().unwrap() == 4 {
// This is a relative frame.
let relative_to = item.data.get(&Parameter::Relative).ok_or(DataSetError::Conversion {
action: format!("frame {id} is class 4 relative to, but the RELATIVE_TO token was not found"),
})?.to_string().unwrap();
if let Ok(parent) = dataset.get_by_name(&relative_to) {
to = parent.to;
} else {
// Not found yet, let's mark it as an ID to revisit.
ids_to_update.push((id, relative_to.clone()));
}

// Always mark as something to update later.
ids_to_update.push((id, relative_to.clone()));
}
}

Expand Down Expand Up @@ -441,9 +438,10 @@ pub fn convert_fk<P: AsRef<Path> + fmt::Debug>(
let parent_id = dataset.data[(*parent_idx) as usize].to;

// Modify this EP.
let this_idx = dataset.lut.by_id[&id];
let mut this_q = dataset.data[this_idx as usize];
this_q.from = parent_id;
let index = dataset.lut.by_id.get(&id).unwrap();
// Grab the data
let this_q = dataset.data.get_mut(*index as usize).unwrap();
this_q.to = parent_id;
}

dataset.set_crc32();
Expand Down
2 changes: 1 addition & 1 deletion anise/src/structure/lookuptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum LutError {
/// _Both_ the IDs and the name MUST be unique in the look up table.
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct LookUpTable<const ENTRIES: usize> {
/// Unique IDs of each item in the
/// Unique IDs of each item in the LUT
pub by_id: FnvIndexMap<NaifId, u32, ENTRIES>,
/// Corresponding index for each hash
pub by_name: FnvIndexMap<String<32>, u32, ENTRIES>,
Expand Down
6 changes: 3 additions & 3 deletions anise/tests/orientations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::path::PathBuf;

use anise::constants::frames::{
EARTH_ITRF93, EARTH_J2000, EME2000, IAU_JUPITER_FRAME, IAU_MOON_FRAME,
JUPITER_BARYCENTER_J2000, MOON_J2000, MOON_ME_DE440_ME421_FRAME, MOON_ME_FRAME,
MOON_PA_DE421_FRAME, MOON_PA_DE440_FRAME, MOON_PA_FRAME,
JUPITER_BARYCENTER_J2000, MOON_J2000, MOON_ME_DE440_ME421_FRAME, MOON_PA_DE421_FRAME,
MOON_PA_DE440_FRAME, MOON_PA_FRAME,
};
use anise::constants::orientations::{
ECLIPJ2000, IAU_JUPITER, IAU_MOON, ITRF93, J2000, MOON_PA, MOON_PA_DE421, MOON_PA_DE440,
ECLIPJ2000, IAU_JUPITER, IAU_MOON, ITRF93, J2000, MOON_PA_DE421, MOON_PA_DE440,
};
use anise::math::rotation::DCM;
use anise::math::Matrix3;
Expand Down

0 comments on commit 9cfa462

Please sign in to comment.