module H3.Traversal
( gridDisk
, gridDiskUnsafe
, gridDiskDistances
, gridDiskDistancesSafe
, gridDiskDistancesUnsafe
, gridRingUnsafe
, gridPathCells
, gridDistance
, cellToLocalIj
, localIjToCell
) where
import Data.Int (Int64)
import H3.Internal.H3Api
( H3ErrorCodes
, H3Index
, CoordIJ
, c2hs_gridDistance
, c2hs_cellToLocalIj
, c2hs_localIjToCell
)
import H3.Internal.FFI
( hsGridDisk
, hsGridDiskUnsafe
, hsGridDiskDistances
, hsGridDiskDistancesSafe
, hsGridDiskDistancesUnsafe
, hsGridRingUnsafe
, hsGridPathCells
)
import H3.Internal.Utils (toEither)
gridDisk :: H3Index
-> Int
-> Either H3ErrorCodes [H3Index]
gridDisk :: H3Index -> Int -> Either H3ErrorCodes [H3Index]
gridDisk H3Index
origin = (Word32, [H3Index]) -> Either H3ErrorCodes [H3Index]
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, [H3Index]) -> Either H3ErrorCodes [H3Index])
-> (Int -> (Word32, [H3Index]))
-> Int
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, [H3Index])
hsGridDisk H3Index
origin
gridDiskUnsafe :: H3Index
-> Int
-> Either H3ErrorCodes [H3Index]
gridDiskUnsafe :: H3Index -> Int -> Either H3ErrorCodes [H3Index]
gridDiskUnsafe H3Index
origin = (Word32, [H3Index]) -> Either H3ErrorCodes [H3Index]
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, [H3Index]) -> Either H3ErrorCodes [H3Index])
-> (Int -> (Word32, [H3Index]))
-> Int
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, [H3Index])
hsGridDiskUnsafe H3Index
origin
gridDiskDistances :: H3Index
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistances :: H3Index -> Int -> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistances H3Index
origin = (Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int])
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int]))
-> (Int -> (Word32, ([H3Index], [Int])))
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, ([H3Index], [Int]))
hsGridDiskDistances H3Index
origin
gridDiskDistancesSafe :: H3Index
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistancesSafe :: H3Index -> Int -> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistancesSafe H3Index
origin = (Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int])
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int]))
-> (Int -> (Word32, ([H3Index], [Int])))
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, ([H3Index], [Int]))
hsGridDiskDistancesSafe H3Index
origin
gridDiskDistancesUnsafe :: H3Index
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistancesUnsafe :: H3Index -> Int -> Either H3ErrorCodes ([H3Index], [Int])
gridDiskDistancesUnsafe H3Index
origin = (Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int])
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, ([H3Index], [Int]))
-> Either H3ErrorCodes ([H3Index], [Int]))
-> (Int -> (Word32, ([H3Index], [Int])))
-> Int
-> Either H3ErrorCodes ([H3Index], [Int])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, ([H3Index], [Int]))
hsGridDiskDistancesUnsafe H3Index
origin
gridRingUnsafe :: H3Index
-> Int
-> Either H3ErrorCodes [H3Index]
gridRingUnsafe :: H3Index -> Int -> Either H3ErrorCodes [H3Index]
gridRingUnsafe H3Index
h3index = ([H3Index] -> [H3Index])
-> Either H3ErrorCodes [H3Index] -> Either H3ErrorCodes [H3Index]
forall a b.
(a -> b) -> Either H3ErrorCodes a -> Either H3ErrorCodes b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((H3Index -> Bool) -> [H3Index] -> [H3Index]
forall a. (a -> Bool) -> [a] -> [a]
filter (H3Index -> H3Index -> Bool
forall a. Eq a => a -> a -> Bool
/= H3Index
0)) (Either H3ErrorCodes [H3Index] -> Either H3ErrorCodes [H3Index])
-> (Int -> Either H3ErrorCodes [H3Index])
-> Int
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word32, [H3Index]) -> Either H3ErrorCodes [H3Index]
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, [H3Index]) -> Either H3ErrorCodes [H3Index])
-> (Int -> (Word32, [H3Index]))
-> Int
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (Word32, [H3Index])
hsGridRingUnsafe H3Index
h3index
gridPathCells :: H3Index
-> H3Index
-> Either H3ErrorCodes [H3Index]
gridPathCells :: H3Index -> H3Index -> Either H3ErrorCodes [H3Index]
gridPathCells H3Index
h3index = (Word32, [H3Index]) -> Either H3ErrorCodes [H3Index]
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, [H3Index]) -> Either H3ErrorCodes [H3Index])
-> (H3Index -> (Word32, [H3Index]))
-> H3Index
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> H3Index -> (Word32, [H3Index])
hsGridPathCells H3Index
h3index
gridDistance :: H3Index
-> H3Index
-> Either H3ErrorCodes Int64
gridDistance :: H3Index -> H3Index -> Either H3ErrorCodes Int64
gridDistance H3Index
origin = (Word32, Int64) -> Either H3ErrorCodes Int64
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, Int64) -> Either H3ErrorCodes Int64)
-> (H3Index -> (Word32, Int64))
-> H3Index
-> Either H3ErrorCodes Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> H3Index -> (Word32, Int64)
c2hs_gridDistance H3Index
origin
cellToLocalIj :: H3Index
-> H3Index
-> Either H3ErrorCodes CoordIJ
cellToLocalIj :: H3Index -> H3Index -> Either H3ErrorCodes CoordIJ
cellToLocalIj H3Index
origin H3Index
h3 = (Word32, CoordIJ) -> Either H3ErrorCodes CoordIJ
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, CoordIJ) -> Either H3ErrorCodes CoordIJ)
-> (Word32, CoordIJ) -> Either H3ErrorCodes CoordIJ
forall a b. (a -> b) -> a -> b
$ H3Index -> H3Index -> Word32 -> (Word32, CoordIJ)
c2hs_cellToLocalIj H3Index
origin H3Index
h3 Word32
0
localIjToCell :: H3Index
-> CoordIJ
-> Either H3ErrorCodes H3Index
localIjToCell :: H3Index -> CoordIJ -> Either H3ErrorCodes H3Index
localIjToCell H3Index
origin CoordIJ
ij = (Word32, H3Index) -> Either H3ErrorCodes H3Index
forall a. (Word32, a) -> Either H3ErrorCodes a
toEither ((Word32, H3Index) -> Either H3ErrorCodes H3Index)
-> (Word32, H3Index) -> Either H3ErrorCodes H3Index
forall a b. (a -> b) -> a -> b
$ H3Index -> CoordIJ -> Word32 -> (Word32, H3Index)
c2hs_localIjToCell H3Index
origin CoordIJ
ij Word32
0