|
@@ -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 {
|