flow_rs_core/spatial/
grid.rs

1//! Grid-based spatial partitioning
2
3use crate::types::Position;
4
5/// Grid cell coordinate
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct GridCell {
8    pub x: i32,
9    pub y: i32,
10}
11
12impl GridCell {
13    /// Create a new grid cell
14    pub fn new(x: i32, y: i32) -> Self {
15        Self { x, y }
16    }
17
18    /// Create a grid cell from a position and cell size
19    pub fn from_position(pos: Position, cell_size: f64) -> Self {
20        Self {
21            x: (pos.x / cell_size).floor() as i32,
22            y: (pos.y / cell_size).floor() as i32,
23        }
24    }
25}