From: Taran Nathan Date: Thu, 21 May 2026 22:39:36 +0000 (-0700) Subject: grid X-Git-Url: https://git.taranathan.com/?a=commitdiff_plain;h=90247f49cd64f34d15c1d42f3083d1380f9240be;p=cart.git grid --- diff --git a/roomy/src/main.rs b/roomy/src/main.rs index 60917bc..fd213c2 100644 --- a/roomy/src/main.rs +++ b/roomy/src/main.rs @@ -1,8 +1,12 @@ +use std::collections::HashMap; + use anyhow::{Result, bail}; use csv::ReaderBuilder; -use nalgebra::{Point2, Rotation2, Vector2}; +use nalgebra::{DMatrix, Point2, Rotation2, Vector2}; use structs::*; +const POINT_WEIGHT: f64 = 0.1; + fn main() -> Result<()> { let mut reader = ReaderBuilder::new() .has_headers(false) @@ -31,3 +35,35 @@ fn record_to_point(record: &Record) -> Point2 { Point2::from(distance + Vector2::from(cart_pos.coords)) } + +fn points_to_grid(points: &Vec>) -> Grid { + let mut grid = Grid::new(0.1, HashMap::new()); + + for point in points { + let coords = ( + (point.x % grid.resolution) as i32, + (point.y % grid.resolution) as i32, + ); + grid.strengths.insert( + coords, + grid.strengths.get(&coords).unwrap_or(&0.0) + POINT_WEIGHT, + ); + } + + grid +} + +#[derive(Debug)] +struct Grid { + pub resolution: f64, + pub strengths: HashMap<(i32, i32), f64>, +} + +impl Grid { + fn new(resolution: f64, strengths: HashMap<(i32, i32), f64>) -> Self { + Grid { + resolution: resolution, + strengths: strengths, + } + } +}