From 90247f49cd64f34d15c1d42f3083d1380f9240be Mon Sep 17 00:00:00 2001 From: Taran Nathan Date: Thu, 21 May 2026 15:39:36 -0700 Subject: [PATCH] grid --- roomy/src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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, + } + } +} -- 2.39.5