]> git.taranathan.com Git - cart.git/commitdiff
grid
authorTaran Nathan <moogoesmeow123@gmail.com>
Thu, 21 May 2026 22:39:36 +0000 (15:39 -0700)
committerTaran Nathan <moogoesmeow123@gmail.com>
Thu, 21 May 2026 22:39:50 +0000 (15:39 -0700)
roomy/src/main.rs

index 60917bcd619e87390597825aa5d280b8ed78c8c8..fd213c218af2fe7927bb0e35b34aeed6fa0cf2c6 100644 (file)
@@ -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<f64> {
 
     Point2::from(distance + Vector2::from(cart_pos.coords))
 }
+
+fn points_to_grid(points: &Vec<Point2<f64>>) -> 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,
+        }
+    }
+}