--------------------------------------------------------------------------------
-- |
-- Module      :  Data.PlaneGraph.AdjRep
-- Copyright   :  (C) Frank Staals
-- License     :  see the LICENSE file
-- Maintainer  :  Frank Staals
--
-- Data types that help encode/decode a planegraph as a JSON/YAML file.
--
--------------------------------------------------------------------------------
module Data.PlaneGraph.AdjRep( Gr(..)
                             , Vtx(..)
                             , Face(..)
                             ) where

import Data.PlanarGraph.AdjRep(Gr(..), Face(..))
import Data.Aeson
import Data.Geometry.Point
import GHC.Generics (Generic)

--------------------------------------------------------------------------------

-- | A vertex, represented by an id, location, its adjacencies, and its data.
data Vtx v e r = Vtx { Vtx v e r -> Int
id    :: Int
                     , Vtx v e r -> Point 2 r
loc   :: Point 2 r
                     , Vtx v e r -> [(Int, e)]
adj   :: [(Int,e)] -- ^ adjacent vertices + data on the
                                          -- edge. Adjacencies are given in
                                          -- arbitrary order
                     , Vtx v e r -> v
vData :: v
                     } deriving ((forall x. Vtx v e r -> Rep (Vtx v e r) x)
-> (forall x. Rep (Vtx v e r) x -> Vtx v e r)
-> Generic (Vtx v e r)
forall x. Rep (Vtx v e r) x -> Vtx v e r
forall x. Vtx v e r -> Rep (Vtx v e r) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall v e r x. Rep (Vtx v e r) x -> Vtx v e r
forall v e r x. Vtx v e r -> Rep (Vtx v e r) x
$cto :: forall v e r x. Rep (Vtx v e r) x -> Vtx v e r
$cfrom :: forall v e r x. Vtx v e r -> Rep (Vtx v e r) x
Generic, a -> Vtx v e b -> Vtx v e a
(a -> b) -> Vtx v e a -> Vtx v e b
(forall a b. (a -> b) -> Vtx v e a -> Vtx v e b)
-> (forall a b. a -> Vtx v e b -> Vtx v e a) -> Functor (Vtx v e)
forall a b. a -> Vtx v e b -> Vtx v e a
forall a b. (a -> b) -> Vtx v e a -> Vtx v e b
forall v e a b. a -> Vtx v e b -> Vtx v e a
forall v e a b. (a -> b) -> Vtx v e a -> Vtx v e b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Vtx v e b -> Vtx v e a
$c<$ :: forall v e a b. a -> Vtx v e b -> Vtx v e a
fmap :: (a -> b) -> Vtx v e a -> Vtx v e b
$cfmap :: forall v e a b. (a -> b) -> Vtx v e a -> Vtx v e b
Functor)

instance (ToJSON r,   ToJSON v, ToJSON e)     => ToJSON   (Vtx v e r) where
  toEncoding :: Vtx v e r -> Encoding
toEncoding = Options -> Vtx v e r -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding Options
defaultOptions
instance (FromJSON r, FromJSON v, FromJSON e) => FromJSON (Vtx v e r)