Refactor the server

This commit is contained in:
Andras Schmelczer 2026-01-31 20:25:54 +00:00
parent 3b9ad11d71
commit 01ec17ff04
15 changed files with 939 additions and 1226 deletions

View file

@ -14,9 +14,7 @@ pub struct GridIndex {
}
impl GridIndex {
/// Build the grid index from lat/lon arrays.
pub fn build(lat: &[f64], lon: &[f64], cell_size: f64) -> Self {
// Compute bounding box with a small margin
let mut min_lat = f64::INFINITY;
let mut max_lat = f64::NEG_INFINITY;
let mut min_lon = f64::INFINITY;
@ -39,7 +37,6 @@ impl GridIndex {
}
}
// Add margin
min_lat -= cell_size;
min_lon -= cell_size;
max_lat += cell_size;
@ -48,12 +45,12 @@ impl GridIndex {
let rows = ((max_lat - min_lat) / cell_size).ceil() as usize + 1;
let cols = ((max_lon - min_lon) / cell_size).ceil() as usize + 1;
eprintln!(
"Building grid index: {}x{} cells ({} total), cell_size={}",
rows,
cols,
rows * cols,
cell_size
tracing::debug!(
rows_grid = rows,
cols_grid = cols,
total_cells = rows * cols,
cell_size,
"Building grid index"
);
let mut cells: Vec<Vec<u32>> = vec![Vec::new(); rows * cols];
@ -65,7 +62,7 @@ impl GridIndex {
cells[idx].push(i as u32);
}
eprintln!("Grid index built.");
tracing::debug!("Grid index built");
GridIndex {
min_lat,
@ -77,7 +74,6 @@ impl GridIndex {
}
}
/// Query all row indices within the given bounding box.
pub fn query(&self, south: f64, west: f64, north: f64, east: f64) -> Vec<u32> {
let (r_min, r_max, c_min, c_max) = self.clamp_bounds(south, west, north, east);