|
morton-arithmetic 0.1.0
Fast Morton (Z-order) codes with O(1) arithmetic
|
A Morton (Z-order) code interleaving Dim unsigned coordinates of Bits bits each.
More...
#include <morton.hpp>
Public Types | |
| using | code_type = detail::uint_for_t< Dim *Bits > |
| using | coord_type = detail::uint_for_t< Bits > |
Public Member Functions | |
| MORTON_HD constexpr | Morton () noexcept |
| MORTON_HD constexpr code_type | code () const noexcept |
| MORTON_HD constexpr coord_type | get (unsigned d) const |
| Decode coordinate of a single axis. | |
| MORTON_HD constexpr std::array< coord_type, Dim > | decode () const |
| Decode all coordinates. | |
| MORTON_HD constexpr void | set (unsigned d, coord_type value) |
| Replace one axis' coordinate (other axes untouched). Wraps mod 2^Bits. | |
| MORTON_HD constexpr void | add (unsigned d, coord_type k) |
Add k to axis d (wraps). O(1), branchless. | |
| MORTON_HD constexpr void | sub (unsigned d, coord_type k) |
Subtract k from axis d (wraps). O(1), branchless. | |
| MORTON_HD constexpr void | inc (unsigned d) |
Increment axis d by one. O(1). | |
| MORTON_HD constexpr void | dec (unsigned d) |
Decrement axis d by one. O(1). | |
| MORTON_HD constexpr Morton | neighbor (unsigned d, int dir) const |
Morton code of the neighbour one step along ± axis d (wraps). | |
| MORTON_HD constexpr void | add_sat (unsigned d, coord_type k) |
Add k to axis d, clamping at coord_max instead of wrapping. | |
| MORTON_HD constexpr void | sub_sat (unsigned d, coord_type k) |
Subtract k from axis d, clamping at 0 instead of wrapping. | |
| MORTON_HD constexpr bool | try_add (unsigned d, coord_type k) |
Add k to axis d only if it does not overflow past coord_max. | |
| MORTON_HD constexpr bool | try_sub (unsigned d, coord_type k) |
Subtract k from axis d only if it does not underflow past 0. | |
| MORTON_HD constexpr std::array< Morton, 2 *Dim > | face_neighbors () const |
| The 2*Dim von Neumann (face) neighbours, ordered {axis0-, axis0+, axis1-, axis1+, ...}. | |
| MORTON_HD constexpr std::array< Morton, detail::pow3(Dim) - 1 > | all_neighbors () const |
| The 3^Dim - 1 Moore neighbours (all cells differing by -1/0/+1 on each axis, excluding self), in odometer order. | |
| MORTON_HD constexpr Morton | ancestor (unsigned level) const |
Ancestor cell origin at the given level (clears the low level*Dim bits). | |
| MORTON_HD constexpr unsigned | child_index (unsigned level) const |
| Index (0 . | |
| MORTON_HD constexpr Morton | child (unsigned level, unsigned octant) const |
The octant-th child origin of a cell that is an ancestor at level (i.e. | |
| MORTON_HD constexpr Morton & | operator++ () noexcept |
| MORTON_HD constexpr Morton | operator++ (int) noexcept |
| MORTON_HD constexpr Morton & | operator-- () noexcept |
| MORTON_HD constexpr Morton | operator-- (int) noexcept |
Static Public Member Functions | |
| static MORTON_HD constexpr Morton | from_code (code_type raw) noexcept |
| Wrap a raw, already-interleaved code value. | |
| template<typename... Cs, typename = std::enable_if_t<sizeof...(Cs) == Dim>> | |
| static MORTON_HD constexpr Morton | encode (Cs... coords) |
Encode Dim coordinates into a Morton code. | |
| static MORTON_HD constexpr Morton | encode (const std::array< coord_type, Dim > &c) |
| Encode from an array of coordinates. | |
| static MORTON_HD constexpr code_type | deposit (coord_type x, unsigned d) |
| static MORTON_HD constexpr coord_type | extract (code_type c, unsigned d) |
| static MORTON_HD constexpr code_type | axis_mask (unsigned d) |
Mask of bits belonging to axis d. | |
Static Public Attributes | |
| static constexpr unsigned | dimensions = Dim |
| static constexpr unsigned | bits_per_axis = Bits |
| static constexpr unsigned | code_bits = Dim * Bits |
| static constexpr code_type | field_mask |
| Mask of all valid code bits (handles code_bits == width without UB). | |
| static constexpr coord_type | coord_max |
| Largest representable coordinate value per axis. | |
| static constexpr unsigned | octants = unsigned(1) << Dim |
A Morton (Z-order) code interleaving Dim unsigned coordinates of Bits bits each.
The whole code occupies Dim * Bits bits and is stored in the smallest unsigned integer that fits.
| using morton::Morton< Dim, Bits >::code_type = detail::uint_for_t<Dim * Bits> |
| using morton::Morton< Dim, Bits >::coord_type = detail::uint_for_t<Bits> |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
Wrap a raw, already-interleaved code value.
|
inlinestaticconstexpr |
Encode Dim coordinates into a Morton code.
|
inlinestaticconstexpr |
Encode from an array of coordinates.
|
inlineconstexpr |
Decode coordinate of a single axis.
|
inlineconstexpr |
Decode all coordinates.
|
inlineconstexpr |
Replace one axis' coordinate (other axes untouched). Wraps mod 2^Bits.
|
inlineconstexpr |
Add k to axis d (wraps). O(1), branchless.
|
inlineconstexpr |
Subtract k from axis d (wraps). O(1), branchless.
Increment axis d by one. O(1).
Decrement axis d by one. O(1).
|
inlineconstexpr |
Morton code of the neighbour one step along ± axis d (wraps).
|
inlineconstexpr |
Add k to axis d, clamping at coord_max instead of wrapping.
|
inlineconstexpr |
Subtract k from axis d, clamping at 0 instead of wrapping.
|
inlineconstexpr |
Add k to axis d only if it does not overflow past coord_max.
Returns false (and leaves the code unchanged) if it would.
|
inlineconstexpr |
Subtract k from axis d only if it does not underflow past 0.
|
inlineconstexpr |
The 2*Dim von Neumann (face) neighbours, ordered {axis0-, axis0+, axis1-, axis1+, ...}.
Wraps at the grid edge.
|
inlineconstexpr |
The 3^Dim - 1 Moore neighbours (all cells differing by -1/0/+1 on each axis, excluding self), in odometer order.
Wraps at the grid edge.
|
inlineconstexpr |
Ancestor cell origin at the given level (clears the low level*Dim bits).
level 0 is *this.
|
inlineconstexpr |
Index (0 .
. 2^Dim-1) of this cell within its parent at level+1, i.e. the Dim interleaved bits just above the level boundary.
|
inlineconstexpr |
The octant-th child origin of a cell that is an ancestor at level (i.e.
set the Dim bits at position (level-1)*Dim). Requires level >= 1.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Mask of bits belonging to axis d.
|
staticconstexpr |
Mask of all valid code bits (handles code_bits == width without UB).
|
staticconstexpr |
Largest representable coordinate value per axis.