Skip to content

Commit

Permalink
better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rennzie committed Nov 10, 2023
1 parent 4fa77c6 commit e8ccfba
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/grid/ntv2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ impl Ntv2Grid {
})
}

// As defined by the FGRID subroutine in the NTv2 spec: https://web.archive.org/web/20140127204822if_/http://www.mgs.gov.on.ca:80/stdprodconsume/groups/content/@mgs/@iandit/documents/resourcelist/stel02_047447.pdf (page 42)
// As defined by the FGRID subroutine in the NTv2 [spec](https://web.archive.org/web/20140127204822if_/http://www.mgs.gov.on.ca:80/stdprodconsume/groups/content/@mgs/@iandit/documents/resourcelist/stel02_047447.pdf) (page 42)
fn find_grid(&self, coord: &Coor4D, margin: f64) -> Option<&BaseGrid> {
// Start with grids whose parent grid id is `NONE`
let mut current_parent_id: String = "NONE".to_string();
let mut queue = self.lookup_table.get(&current_parent_id).unwrap().clone();

while let Some(child_id) = queue.pop() {
// It will be safe to unwrap as a panic means we didn't
// properly add the grids to the lookup table & subgrids properties
// Unwrappping is safe as a panic means we didn't
// properly populate the `lookup_table` & `subgrids` properties
let current_grid = self.subgrids.get(&child_id).unwrap();

// The NTv2 spec has a myriad of different options for handling coordinates
// that fall on the boundaries of a grid. We've chosen to ignore them for now
// and just return the first grid that contains the coordinate.
// and return most dense AND first grid that contains the coordinate.
// This should be relatively safe given then NTv2 spec does ensure that grids cannot overlap.
// See the FGRID subroutine in the NTv2 spec linked above for more details.
// We may want to consider enforcing a margin of 0.0 for inner grids.
// NOTE: We may want to consider enforcing a margin of 0.0 for inner grids.
if current_grid.contains(coord, margin) {
current_parent_id = child_id.clone();

Expand All @@ -93,7 +93,7 @@ impl Ntv2Grid {
break;
}
}
println!("Found grid: {}", current_parent_id);

self.subgrids.get(&current_parent_id)
}
}
Expand All @@ -103,9 +103,8 @@ impl Grid for Ntv2Grid {
2
}

/// Checks if a `Coord4D` is margin the grid limits +- `margin` grid units
/// Checks if a `Coord4D` is within the grid limits +- `margin` grid units
fn contains(&self, position: &Coor4D, margin: f64) -> bool {
// If `.get` returns Some then the grid contains the coordinate
if let Some(_) = self.find_grid(position, margin) {
return true;
}
Expand Down

0 comments on commit e8ccfba

Please sign in to comment.