mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
Replace DivRem trait with num-integer crate
This commit is contained in:
parent
1049aad03d
commit
96736bd7ed
4 changed files with 32 additions and 27 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -14,6 +14,12 @@ version = "1.0.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -231,6 +237,7 @@ dependencies = [
|
||||||
"fastnbt",
|
"fastnbt",
|
||||||
"flate2",
|
"flate2",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
"num-integer",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -243,6 +250,25 @@ dependencies = [
|
||||||
"adler",
|
"adler",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.17.0"
|
version = "1.17.0"
|
||||||
|
|
|
@ -15,4 +15,5 @@ enumflags2 = "0.7.5"
|
||||||
fastnbt = "2.3.2"
|
fastnbt = "2.3.2"
|
||||||
flate2 = "1.0.25"
|
flate2 = "1.0.25"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
|
num-integer = "0.1.45"
|
||||||
serde = "1.0.152"
|
serde = "1.0.152"
|
||||||
|
|
25
src/types.rs
25
src/types.rs
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::{Div, Index, IndexMut, Rem},
|
ops::{Index, IndexMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use itertools::iproduct;
|
use itertools::iproduct;
|
||||||
|
@ -113,26 +113,3 @@ impl<T> IndexMut<ChunkCoords> for ChunkArray<T> {
|
||||||
&mut self.0[index.z.0 as usize][index.x.0 as usize]
|
&mut self.0[index.z.0 as usize][index.x.0 as usize]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate division and remainder at the same time
|
|
||||||
pub trait DivRem<Rhs>
|
|
||||||
where
|
|
||||||
Self: Div<Rhs>,
|
|
||||||
Self: Rem<Rhs>,
|
|
||||||
{
|
|
||||||
/// Returns the result of the division and remainder operations
|
|
||||||
/// with the same inputs
|
|
||||||
fn div_rem(self, rhs: Rhs) -> (<Self as Div<Rhs>>::Output, <Self as Rem<Rhs>>::Output);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Lhs, Rhs> DivRem<Rhs> for Lhs
|
|
||||||
where
|
|
||||||
Self: Div<Rhs>,
|
|
||||||
Self: Rem<Rhs>,
|
|
||||||
Self: Copy,
|
|
||||||
Rhs: Copy,
|
|
||||||
{
|
|
||||||
fn div_rem(self, rhs: Rhs) -> (<Self as Div<Rhs>>::Output, <Self as Rem<Rhs>>::Output) {
|
|
||||||
(self / rhs, self % rhs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
use num_integer::div_rem;
|
||||||
|
|
||||||
use super::de;
|
use super::de;
|
||||||
use crate::{resource, types::*};
|
use crate::{resource, types::*};
|
||||||
|
@ -112,11 +113,11 @@ impl<'a> SectionV1_13<'a> {
|
||||||
|
|
||||||
let shifted = if self.aligned_blocks {
|
let shifted = if self.aligned_blocks {
|
||||||
let blocks_per_word = 64 / bits;
|
let blocks_per_word = 64 / bits;
|
||||||
let (word, shift) = offset.div_rem(blocks_per_word);
|
let (word, shift) = div_rem(offset, blocks_per_word);
|
||||||
block_states[word] as u64 >> (shift * bits)
|
block_states[word] as u64 >> (shift * bits)
|
||||||
} else {
|
} else {
|
||||||
let bit_offset = offset * bits;
|
let bit_offset = offset * bits;
|
||||||
let (word, bit_shift) = bit_offset.div_rem(64);
|
let (word, bit_shift) = div_rem(bit_offset, 64);
|
||||||
|
|
||||||
if bit_shift + bits <= 64 {
|
if bit_shift + bits <= 64 {
|
||||||
block_states[word] as u64 >> bit_shift
|
block_states[word] as u64 >> bit_shift
|
||||||
|
@ -170,7 +171,7 @@ impl<'a> Section for SectionV0<'a> {
|
||||||
let offset = coords.offset();
|
let offset = coords.offset();
|
||||||
let block = self.blocks[offset] as u8;
|
let block = self.blocks[offset] as u8;
|
||||||
|
|
||||||
let (data_offset, data_nibble) = offset.div_rem(2);
|
let (data_offset, data_nibble) = div_rem(offset, 2);
|
||||||
let data_byte = self.data[data_offset] as u8;
|
let data_byte = self.data[data_offset] as u8;
|
||||||
let data = if data_nibble == 1 {
|
let data = if data_nibble == 1 {
|
||||||
data_byte >> 4
|
data_byte >> 4
|
||||||
|
|
Loading…
Add table
Reference in a new issue