Skip to content

Add Moore curve support with efficient LUT implementation#19

Open
Copilot wants to merge 3 commits intomainfrom
copilot/support-hilbert-derivatives
Open

Add Moore curve support with efficient LUT implementation#19
Copilot wants to merge 3 commits intomainfrom
copilot/support-hilbert-derivatives

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 11, 2025

Implements Moore curve variant (closed-loop Hilbert derivative) while maintaining fast_hilbert's performance characteristics. Moore curves use the same 4-state LUT approach as standard Hilbert curves but with different state transitions and an initial order handling.

API Changes

Added two public functions:

  • xy2h_moore(x, y, order) - 2D → 1D Moore curve transformation
  • h2xy_moore(h, order) - 1D → 2D Moore curve transformation
// Moore curve produces a closed loop (endpoints meet)
let h = fast_hilbert::xy2h_moore(1u32, 0u32, 1);
assert_eq!(h, 3u64);

let (x, y) = fast_hilbert::h2xy_moore::<u32>(3u64, 1);
assert_eq!((x, y), (1, 0));

Implementation

Refactored core functions - Extracted xy2h_lut3() and h2xy_lut3() internal helpers to share logic between Hilbert and Moore implementations. Both variants now use the same optimized LUT-based algorithm with different state transition tables.

Extended UnsignedBase trait - Added ONE, TWO, THREE, SIXTY_THREE, BITS constants and PartialEq bound required for Moore curve state logic. Removed redundant constants from Unsigned trait implementations.

Moore-specific LUTs - Pre-computed 256-byte lookup tables for Moore curve state transitions, matching the memory footprint of standard Hilbert LUTs.

Performance

Benchmarks confirm no regression:

  • fast_hilbert: 401 µs (256×256)
  • hilbert_2d: 971 µs
  • hilbert_curve: 2.77 ms

Maintains 2.4× speed advantage over nearest competitor.

Note on Liu Variants

Liu's other variants (Liu1-4) require >4 states and cannot be efficiently implemented with the 4-state LUT approach. Moore succeeds because it uses the same 4-state system with different transitions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support Hilbert derivatives.</issue_title>
<issue_description>How hard would it be to get the performance gains of fast_hilbert, but also be able to create Xian Liu's variants?

https://www.sciencedirect.com/science/article/abs/pii/S0096300302008081?via%3Dihub

Looks like hilbert_2d does this.

https://crates.io/crates/hilbert_2d

I wonder if the variants provide significant performance differences regarding the use of the curve as a spatial index?

</issue_description>

Comments on the Issue (you are @copilot in this section)

@becheran Not sure yet. Just had a brief look on the Moore type. I would assume that it is not too hard to re-use the LUT idea and generate another for the Moore type. Performance wise I don't see how there would be a difference. @becheran @hallahan I managed to implement the moore variant using the LUT logic I use to compote the hilber curve. It was a bit more challenging than I thought because there was a hidden first state for the moore curve which is not directly repeated for higher order/more bits.

The other LIU variants use more than 4 states and won't fit into the 4 state LUT idea that I use in the fast_hilbert crate.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 11, 2025 21:25
- Added xy2h_moore() and h2xy_moore() functions for Moore curve transformations
- Refactored xy2h() and h2xy() to use internal helper functions (xy2h_lut3 and h2xy_lut3)
- Updated UnsignedBase trait with additional constants (ONE, TWO, THREE, SIXTY_THREE, BITS) and PartialEq bound
- Removed redundant SEVEN and SIXTY_THREE constants from Unsigned trait implementations
- Added comprehensive tests for Moore curve functions
- Added panic documentation for Moore functions
- Updated README to document Moore curve support
- All tests pass and code is clippy-clean

Co-authored-by: becheran <22472855+becheran@users.noreply.github.com>
- Removed unnecessary where clause from xy2h_moore function
- Kept type annotation on shift operation as required by compiler

Co-authored-by: becheran <22472855+becheran@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for Hilbert derivatives and variants Add Moore curve support with efficient LUT implementation Dec 11, 2025
Copilot AI requested a review from becheran December 11, 2025 21:37
@becheran becheran marked this pull request as ready for review March 7, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Hilbert derivatives.

2 participants