{-|
Module      : H3.Vertexes

Vertex mode allows encoding the topological vertexes of H3 cells.
-}
module H3.Vertexes
  ( cellToVertex
  , cellToVertexes 
  , vertexToLatLng
  , isValidVertex
  ) where

import H3.Internal.H3Api 
  ( LatLng
  , H3ErrorCodes
  , H3Index
  , c2hs_cellToVertex
  , c2hs_vertexToLatLng
  )
import H3.Internal.FFI 
  ( hsCellToVertexes 
  , isValidVertex
  )
import H3.Internal.Utils (toEither)

-- | Returns the index for the specified cell vertex and vertex number. 
--   Valid vertex numbers are between 0 and 5 (inclusive) for hexagonal cells, 
--   and 0 and 4 (inclusive) for pentagonal cells.
cellToVertex :: H3Index -- ^ origin
             -> Int     -- ^ vertexNum
             -> Either H3ErrorCodes H3Index
cellToVertex :: H3Index -> Int -> Either H3ErrorCodes H3Index
cellToVertex H3Index
origin = (H3Error, H3Index) -> Either H3ErrorCodes H3Index
forall a. (H3Error, a) -> Either H3ErrorCodes a
toEither ((H3Error, H3Index) -> Either H3ErrorCodes H3Index)
-> (Int -> (H3Error, H3Index))
-> Int
-> Either H3ErrorCodes H3Index
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> Int -> (H3Error, H3Index)
c2hs_cellToVertex H3Index
origin 

-- | Returns the latitude and longitude coordinates of the given vertex.
vertexToLatLng :: H3Index -> Either H3ErrorCodes LatLng
vertexToLatLng :: H3Index -> Either H3ErrorCodes LatLng
vertexToLatLng = (H3Error, LatLng) -> Either H3ErrorCodes LatLng
forall a. (H3Error, a) -> Either H3ErrorCodes a
toEither ((H3Error, LatLng) -> Either H3ErrorCodes LatLng)
-> (H3Index -> (H3Error, LatLng))
-> H3Index
-> Either H3ErrorCodes LatLng
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> (H3Error, LatLng)
c2hs_vertexToLatLng 

-- | Returns the indexes for all vertexes of the given cell index.
--   The length of the returned list is 6. 
--   If the given cell index represents a pentagon, 
--   one member of the list will be set to 0.
cellToVertexes :: H3Index -> Either H3ErrorCodes [H3Index]
cellToVertexes :: H3Index -> Either H3ErrorCodes [H3Index]
cellToVertexes = (H3Error, [H3Index]) -> Either H3ErrorCodes [H3Index]
forall a. (H3Error, a) -> Either H3ErrorCodes a
toEither ((H3Error, [H3Index]) -> Either H3ErrorCodes [H3Index])
-> (H3Index -> (H3Error, [H3Index]))
-> H3Index
-> Either H3ErrorCodes [H3Index]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. H3Index -> (H3Error, [H3Index])
hsCellToVertexes