Преглед изворни кода

Updated to the lastest point

point v0.1.4 -> v0.1.5

This update allows us to properly obtain the index for a given point,
the code at least has no errors... but it may not work right.
Apollo пре 1 месец
родитељ
комит
6910d29643
3 измењених фајлова са 19 додато и 19 уклоњено
  1. 2 2
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 16 16
      src/chunk.rs

+ 2 - 2
Cargo.lock

@@ -1162,8 +1162,8 @@ dependencies = [
 
 [[package]]
 name = "point"
-version = "0.1.4"
-source = "git+https://git.red-green.com/david/point#9ca4a3450f55740cb36a6ab09de3b56fb2af5c7c"
+version = "0.1.5"
+source = "git+https://git.red-green.com/david/point#5776731e72b6f2dbbdaf887236b1622cc3b3c6b6"
 dependencies = [
  "anyhow",
  "num",

+ 1 - 1
Cargo.toml

@@ -10,7 +10,7 @@ color-eyre = "0.6.3"
 crossterm = "0.28.1"
 delegate = "0.13.0"
 futures = "0.3.31"
-point = { git = "https://git.red-green.com/david/point", version = "0.1.4", features = ["serde"] }
+point = { git = "https://git.red-green.com/david/point", version = "0.1.5", features = ["serde"] }
 ratatui = { version = "0.28.1", features = ["unstable-widget-ref"] }
 russh = "0.45.0"
 russh-keys = "0.45.0"

+ 16 - 16
src/chunk.rs

@@ -10,42 +10,42 @@ pub struct Chunk {
 impl Index<Point<u64>> for Chunk {
     type Output = u64;
     fn index(&self, index: Point<u64>) -> &Self::Output {
-        let idx = index.distance_value();
+        let idx = index.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             panic!("index out of bounds");
         }
-        &self.tiles[idx as usize]
+        &self.tiles[idx]
     }
 }
 
 impl IndexMut<Point<u64>> for Chunk {
     fn index_mut(&mut self, index: Point<u64>) -> &mut Self::Output {
-        let idx = index.distance_value();
+        let idx = index.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             panic!("index out of bounds");
         }
-        &mut self.tiles[idx as usize]
+        &mut self.tiles[idx]
     }
 }
 
 impl Index<&Point<u64>> for Chunk {
     type Output = u64;
     fn index(&self, index: &Point<u64>) -> &Self::Output {
-        let idx = index.distance_value();
+        let idx = index.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             panic!("index out of bounds");
         }
-        &self.tiles[idx as usize]
+        &self.tiles[idx]
     }
 }
 
 impl IndexMut<&Point<u64>> for Chunk {
     fn index_mut(&mut self, index: &Point<u64>) -> &mut Self::Output {
-        let idx = index.distance_value();
+        let idx = index.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             panic!("index out of bounds");
         }
-        &mut self.tiles[idx as usize]
+        &mut self.tiles[idx]
     }
 }
 
@@ -61,34 +61,34 @@ impl Chunk {
         s
     }
     pub fn get(&self, pos: &Point<u64>) -> Option<&u64> {
-        let idx = pos.distance_value();
+        let idx = pos.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             return None;
         }
-        self.tiles.get(idx as usize)
+        self.tiles.get(idx)
     }
     pub fn get_mut(&mut self, pos: &Point<u64>) -> Option<&mut u64> {
-        let idx = pos.distance_value();
+        let idx = pos.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             return None;
         }
-        self.tiles.get_mut(idx as usize)
+        self.tiles.get_mut(idx)
     }
     pub fn set(&mut self, pos: &Point<u64>, value: u64) -> bool {
-        let idx = pos.distance_value();
+        let idx = pos.distance(&Point::default()).round_ties_even() as usize;
         if idx >= 32*32 {
             return false;
         }
-        self.tiles[idx as usize] = value;
+        self.tiles[idx] = value;
         true
     }
     pub fn fill(&mut self, pos1: &Point<u64>, pos2: &Point<u64>, value: u64) -> bool {
         let (corn1, corn2) = match pos1.partial_cmp(pos2).unwrap() {
             Greater => {
-                (pos2.distance_value(), pos1.distance_value())
+                (pos2.distance(&Point::default()).round_ties_even() as usize, pos1.distance(&Point::default()).round_ties_even() as usize)
             },
             _ => {
-                (pos1.distance_value(), pos2.distance_value())
+                (pos1.distance(&Point::default()).round_ties_even() as usize, pos2.distance(&Point::default()).round_ties_even() as usize)
             }
         };
         if corn1 >= 32*32 || corn2 >= 32*32 {