fractals-0.1.0.0: A collection of useful fractal curve encoders

Copyright(c) 2015 Stephen Dekker <steve.dekk@gmail.com>
LicenseBSD3
Maintainersteve.dekk@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.SpaceFillingCurve.Hilbert.Integer.Internal

Contents

Description

This modules contains the implementation of Butz's Hilbert curve encoding algorithm. Of these, the hilbert and hilbertInverse function are exposed through the Data.SpaceFillingCurve.Hilbert.Integer module.

Synopsis

Encoding and decoding the Hilbert curve

hilbert :: (Bits a, Bits b, Num b) => Int -> [a] -> b Source

Given the number of bits required to represent the largest value in the given input list (which represents a point in an N-dimensional Cartesian space), returns the Hilbert index of the point.

hilbertInverse :: (Num a, Bits a, Bits b) => Int -> Int -> a -> [b] Source

Given the number of bits required to represent the largest value in the output vector, the number of dimensions in the output space and the Hilbert index of the output point, returns a list of values representing the point in Cartesian space.

Internal helper functions for the Hilbert transformations

bitAt :: (Bits a, Bits b) => a -> Int -> b Source

Returns the value of the given bit in the source bit string. Note that if the bit was set, the returned value will be of the output type with only the first bit set.

trailingSetBits :: (Bits a, Num b) => a -> b Source

Counts the number of trailing set bits in the given bit string.

mask :: Num a => Int -> a Source

Creates a bit mask extending the range of bits from [0, width - 1].

rotR :: (Num a, Bits a) => Int -> a -> Int -> a Source

Performs a windowed right rotate by i within a window from bit 0 to bit width on a number x.

rotL :: (Num a, Bits a) => Int -> a -> Int -> a Source

Performs a windowed left rotate by i within a window from bit 0 to bit width on a number x.

grayCode :: Bits a => a -> a Source

Returns the i-th binary-reflected Gray code.

grayCodeInverse :: Bits a => a -> a Source

Returns the enumeration index of a given binary-reflected Gray code, inverting the Gray code transform.

entryPoint :: (Num a, Bits a) => a -> a Source

Returns the i-th element in the sequence of entry points.

direction :: (Num a, Bits a) => Int -> a -> Int Source

Given the dimensionality of the Hilbert curve and an index i, returns the i-th element in the sequence of directions.

transform :: (Num a, Bits a) => Int -> a -> Int -> a -> a Source

Given a dimensionality, an entry point, a direction and a Gray code representing a canonical, unrotated sub-hypercube path we wish to transform, returns the path rotated so that it is correctly oriented within its quadrant.

transformInverse :: (Num a, Bits a) => Int -> a -> Int -> a -> a Source

Given a dimensionality, an entry point, a direction and the Gray code representing the rotated sub-hypercube path in a particular quadrant, returns the path rotated and transformed back into its canonical form.

pivot :: (Bits a, Bits b) => Int -> a -> [Int] -> [b] Source

Given a position, i, a bit-array l and a list of positions to test, returns a list containing either the value (2^i) or 0 depending on whether the bits in l at the positions in the input list are set or not.