https://github.com/yvt/zhang_hilbert
A Rust crate for generating an arbitrary-sized pseudo-Hilbert scan
https://github.com/yvt/zhang_hilbert
Last synced: 5 months ago
JSON representation
A Rust crate for generating an arbitrary-sized pseudo-Hilbert scan
- Host: GitHub
- URL: https://github.com/yvt/zhang_hilbert
- Owner: yvt
- License: apache-2.0
- Created: 2019-02-26T05:31:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-06T15:00:39.000Z (about 7 years ago)
- Last Synced: 2026-01-15T16:16:10.281Z (6 months ago)
- Language: Rust
- Size: 34.2 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# `zhang_hilbert`
[
](https://docs.rs/zhang_hilbert/)
This crate provides iterator types that produce an arbitrary-sized
pseudo-Hilbert scan based on “A Pseudo-Hilbert Scan for Arbitrarily-Sized
Arrays” by Zhang, et al.

```rust
use zhang_hilbert::ArbHilbertScan32;
for [x, y] in ArbHilbertScan32::new([11, 42]) {
assert!(x >= 0 && y >= 0 && x < 11 && y < 42);
println!("{:?}", [x, y]);
}
```
## Differences from the original algorithm
### The last `E_B(E, O)` block
This implementation uses a different curve-type selection rule for the
last `E_B(E, O)` block in a `E_R(E, O)` rectangle. This makes the leaving
point fixed at a known point in more cases, making the output suitable for
tiling.
```
cargo run --example hilbertgen -- -a zhang 6 7
,---, ,---, ,---, ,---,
'-, '-' ,-' '-, '-' ,-'
,-' ,-, '-, ,-' ,-, '-,
'-, | '---' '-, | '---'
,-' '-, ,-- ,-' '-----,
'-, ,-' '-, '-, ,-----'
--' '-----' --' '------
Original This implementation
cargo run --example hilbertgen -- -a zhang 4 3
,------ ,-----,
'-----, '-, ,-'
------' --' '--
Original This implementation
```
### Aspect-ratio bounded tiling
The algorithm accepts any rectangle size, but the output quality
deteriorates as the proportions of the rectangle gets distant from square.
`ArbHilbertScanCore` improves it by dividing the rectangle into multiple
rectangles whose proportions are closer to square than the original
rectangle is (thus their aspect ratios are bounded).
```
$ cargo run --example hilbertgen -- 40 7
,---, ,---, ,---, ,---, ,---, ,-, ,---, ,---, ,---, ,---, ,-, ,---, ,---, ,---,
'-, '-' ,-' '-, '-' ,-' '-, '-' '-' ,-' '-, '-' ,-' '-, '-' '-' ,-' '-, '-' ,-'
,-' ,-, '-, ,-' ,-, '-, ,-' ,-, ,-, '-, ,-' ,-, '-, ,-' ,-, ,-, '-, ,-' ,-, '-,
'-, | '---' '-, | '---' '---' | | '---' '-, | '---' '---' | | '---' '-, | '---'
,-' '-----, ,-' '-----, ,-----' '-----, ,-' '-----, ,-----' '-----, ,-' '-----,
'-, ,-----' '-, ,-----' '-----, ,-----' '-, ,-----' '-----, ,-----' '-, ,-----'
--' '---------' '-------------' '---------' '-------------' '---------' '------
$ cargo run --example hilbertgen -- -a zhang 40 7
,-----------------------, ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,---------------,
'---------------------, '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' ,-------------'
,---------------------' ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,-, ,-, '-------------,
'-----------------------' '-' '-' '-' '-' '-' | | '-' '-' '-' '---------------'
,---------------------------------------------' '-----------------------------,
'---------------------------------------------, ,-----------------------------'
----------------------------------------------' '------------------------------
```
### The `division` function
The `division` function was modified for efficient implementation. As a
result, it produces an different output for the input `3⋅2ⁿ`.
License: MIT/Apache-2.0