Skip to content

Commit

Permalink
Merge pull request #17 from boydjohnson/feature/scrubbing-bubbles
Browse files Browse the repository at this point in the history
Feature/scrubbing bubbles
  • Loading branch information
boydjohnson authored Aug 11, 2024
2 parents 765af3f + e36f6c0 commit 678a5e0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 38 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "space-time"
version = "0.2.0"
version = "0.3.0"
authors = ["Boyd Johnson <[email protected]>"]
description = "A nightly only library of space-time filling curves that supports no-std."
license-file = "LICENSE.txt"
Expand All @@ -11,9 +11,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
num-integer = { version = "^0.1", default-features = false }
num-traits = { version = "^0.2", default-features = false, features = ["libm"] }
num-integer = { version = "0.1", default-features = false }
num-traits = { version = "0.2", default-features = false, features = ["libm"] }

[dev-dependencies]
quickcheck = "^0.9"
quickcheck_macros = "^0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"
6 changes: 3 additions & 3 deletions src/index_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub trait IndexRange: core::fmt::Debug {
/// Returns all three (lower, upper, contained) as a tuple.
fn tuple(&self) -> (u64, u64, bool) {
(
<Self as IndexRange>::lower(&self),
<Self as IndexRange>::upper(&self),
<Self as IndexRange>::lower(self),
<Self as IndexRange>::upper(self),
self.contained(),
)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ impl PartialEq for dyn IndexRange {

impl Eq for dyn IndexRange {}

///
/// A covered range.
#[derive(Debug, PartialEq, Eq)]
pub struct CoveredRange {
upper: u64,
Expand Down
6 changes: 3 additions & 3 deletions src/xzorder/xz2_sfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ impl XZ2SFC {
ymax = y_center;
}
(false, true) => {
cs += 1 + div_floor(4_u64.pow(self.g as u32 - i) - 1_u64, 3);
cs += 1 + div_floor(4_u64.pow(self.g - i) - 1_u64, 3);
xmin = x_center;
ymax = y_center;
}
(true, false) => {
cs += 1 + div_floor(2 * (4_u64.pow(self.g as u32 - i) - 1_u64), 3);
cs += 1 + div_floor(2 * (4_u64.pow(self.g - i) - 1_u64), 3);
xmax = x_center;
ymin = y_center;
}
(false, false) => {
cs += 1 + div_floor(3 * 4_u64.pow(self.g as u32 - i) - 1_u64, 3);
cs += 1 + div_floor(3 * 4_u64.pow(self.g - i) - 1_u64, 3);
xmin = x_center;
ymin = y_center;
}
Expand Down
10 changes: 7 additions & 3 deletions src/zorder/z_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ mod tests {

#[quickcheck]
fn test_split_and_combine(x: u32) -> bool {
Z2::combine(Z2::split(x)) == x
if x > Z2::MAX_MASK as u32 {
true
} else {
Z2::combine(Z2::split(x)) == x
}
}

#[test]
Expand Down Expand Up @@ -177,8 +181,8 @@ mod tests {
#[test]
fn test_longest_common_prefix() {
assert_eq!(
Z2::longest_common_prefix(&[u64::max_value(), u64::max_value() - 15]).prefix,
u64::max_value() - 15
Z2::longest_common_prefix(&[u64::MAX, u64::MAX - 15]).prefix,
u64::MAX - 15
);
assert_eq!(Z2::longest_common_prefix(&[15, 13]).prefix, 12); // 1111, 1101 => 1100 => 12
assert_eq!(Z2::longest_common_prefix(&[12, 15]).prefix, 12); // 1100, 1111 => 1100
Expand Down
27 changes: 15 additions & 12 deletions src/zorder/z_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,17 @@ impl ZCurve3D {
let depth_max: u32 = self.time_to_depth(t_max);
let max = Z3::new(col_max, row_max, depth_max);

let max_recurse = hints.iter().find_map(|h| {
let RangeComputeHints::MaxRecurse(max) = *h;
if max > MAX_RECURSION {
Some(MAX_RECURSION)
} else {
Some(max)
}
});
let max_recurse = hints
.iter()
.map(|h| {
let RangeComputeHints::MaxRecurse(max) = *h;
if max > MAX_RECURSION {
MAX_RECURSION
} else {
max
}
})
.next();

<Z3 as ZN>::zranges::<Z3>(
&[ZRange {
Expand Down Expand Up @@ -289,12 +292,12 @@ mod tests {
assert_eq!(Z3::new(23, 13, 200).decode(), (23, 13, 200));
// only 21 bits are saved, so MAX Value gets chopped
assert_eq!(
Z3::new(u16::max_value() as u32, 0, 0).decode(),
(u16::max_value() as u32, 0, 0)
Z3::new(u16::MAX as u32, 0, 0).decode(),
(u16::MAX as u32, 0, 0)
);
assert_eq!(
Z3::new(u16::max_value() as u32, 0, u16::max_value() as u32).decode(),
(u16::max_value() as u32, 0, u16::max_value() as u32)
Z3::new(u16::MAX as u32, 0, u16::MAX as u32).decode(),
(u16::MAX as u32, 0, u16::MAX as u32)
);
}

Expand Down
19 changes: 11 additions & 8 deletions src/zorder/z_curve_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ impl ZCurve2D {
let row_max = self.map_to_row(y_min);
let max = Z2::new(col_max, row_max);

let max_recurse = hints.iter().find_map(|h| {
let RangeComputeHints::MaxRecurse(max) = *h;
if max > Self::MAX_RECURSION {
Some(Self::MAX_RECURSION)
} else {
Some(max)
}
});
let max_recurse = hints
.iter()
.map(|h| {
let RangeComputeHints::MaxRecurse(max) = *h;
if max > Self::MAX_RECURSION {
Self::MAX_RECURSION
} else {
max
}
})
.next();

Z2::zranges::<Z2>(
&[ZRange {
Expand Down
8 changes: 4 additions & 4 deletions src/zorder/z_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ pub trait ZN {
fn overlaps(range: ZRange, value: ZRange) -> bool;

/// Compute the Z-index ranges that cover zbounds (Default values: precision = 64,
/// `max_recurse` = 7, `max_ranges` = `usize::max_value()`).
/// `max_recurse` = 7, `max_ranges` = `usize::MAX`).
#[must_use]
fn zranges_default<Z: ZN>(zbounds: &[ZRange]) -> Vec<Box<dyn IndexRange>> {
Self::zranges::<Z>(zbounds, 64, Some(usize::max_value()), Some(DEFAULT_RECURSE))
Self::zranges::<Z>(zbounds, 64, Some(usize::MAX), Some(DEFAULT_RECURSE))
}

/// Compute the Z-index ranges that cover zbounds.
Expand Down Expand Up @@ -110,7 +110,7 @@ pub trait ZN {
let mut level = 0;

let max_recurse = max_recurse.unwrap_or(DEFAULT_RECURSE);
let max_ranges = max_ranges.unwrap_or(usize::max_value());
let max_ranges = max_ranges.unwrap_or(usize::MAX);

loop {
let next = remaining.pop_front();
Expand Down Expand Up @@ -209,7 +209,7 @@ pub trait ZN {

bit_shift += Self::DIMENSIONS;
ZPrefix {
prefix: values[0] & (u64::max_value().wrapping_shl(bit_shift as u32)),
prefix: values[0] & (u64::MAX.wrapping_shl(bit_shift as u32)),
precision: 64 - bit_shift,
}
}
Expand Down

0 comments on commit 678a5e0

Please sign in to comment.