mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
general: snapshot
This commit is contained in:
42
parser/src/structs/height_map_chunk_id.rs
Normal file
42
parser/src/structs/height_map_chunk_id.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use allocative::Allocative;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::HEIGHT_MAP_CHUNK_SIZE;
|
||||
|
||||
use super::{Height, MapChunkId};
|
||||
|
||||
#[derive(
|
||||
Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Allocative, Deref, DerefMut,
|
||||
)]
|
||||
pub struct HeightMapChunkId(Height);
|
||||
|
||||
impl HeightMapChunkId {
|
||||
pub fn new(height: &Height) -> Self {
|
||||
Self(Height::new(
|
||||
**height / HEIGHT_MAP_CHUNK_SIZE * HEIGHT_MAP_CHUNK_SIZE,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl MapChunkId for HeightMapChunkId {
|
||||
fn to_name(&self) -> String {
|
||||
let start = ***self;
|
||||
let end = start + HEIGHT_MAP_CHUNK_SIZE;
|
||||
|
||||
format!("{start}..{end}")
|
||||
}
|
||||
|
||||
fn from_name(name: &str) -> Self {
|
||||
Self(Height::new(
|
||||
name.split("..").next().unwrap().parse::<u32>().unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
fn to_usize(self) -> usize {
|
||||
**self as usize
|
||||
}
|
||||
|
||||
fn from_usize(id: usize) -> Self {
|
||||
Self(Height::new(id as u32))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user