module Geometry.Face where

import RIO

data Face a = Face
  { forall a. Face a -> a
faceA :: a
  , forall a. Face a -> a
faceB :: a
  , forall a. Face a -> a
faceC :: a
  } deriving (Face a -> Face a -> Bool
forall a. Eq a => Face a -> Face a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Face a -> Face a -> Bool
$c/= :: forall a. Eq a => Face a -> Face a -> Bool
== :: Face a -> Face a -> Bool
$c== :: forall a. Eq a => Face a -> Face a -> Bool
Eq, Face a -> Face a -> Bool
Face a -> Face a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Face a)
forall a. Ord a => Face a -> Face a -> Bool
forall a. Ord a => Face a -> Face a -> Ordering
forall a. Ord a => Face a -> Face a -> Face a
min :: Face a -> Face a -> Face a
$cmin :: forall a. Ord a => Face a -> Face a -> Face a
max :: Face a -> Face a -> Face a
$cmax :: forall a. Ord a => Face a -> Face a -> Face a
>= :: Face a -> Face a -> Bool
$c>= :: forall a. Ord a => Face a -> Face a -> Bool
> :: Face a -> Face a -> Bool
$c> :: forall a. Ord a => Face a -> Face a -> Bool
<= :: Face a -> Face a -> Bool
$c<= :: forall a. Ord a => Face a -> Face a -> Bool
< :: Face a -> Face a -> Bool
$c< :: forall a. Ord a => Face a -> Face a -> Bool
compare :: Face a -> Face a -> Ordering
$ccompare :: forall a. Ord a => Face a -> Face a -> Ordering
Ord, Int -> Face a -> ShowS
forall a. Show a => Int -> Face a -> ShowS
forall a. Show a => [Face a] -> ShowS
forall a. Show a => Face a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Face a] -> ShowS
$cshowList :: forall a. Show a => [Face a] -> ShowS
show :: Face a -> String
$cshow :: forall a. Show a => Face a -> String
showsPrec :: Int -> Face a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Face a -> ShowS
Show, forall a b. a -> Face b -> Face a
forall a b. (a -> b) -> Face a -> Face b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Face b -> Face a
$c<$ :: forall a b. a -> Face b -> Face a
fmap :: forall a b. (a -> b) -> Face a -> Face b
$cfmap :: forall a b. (a -> b) -> Face a -> Face b
Functor, forall a. Eq a => a -> Face a -> Bool
forall a. Num a => Face a -> a
forall a. Ord a => Face a -> a
forall m. Monoid m => Face m -> m
forall a. Face a -> Bool
forall a. Face a -> Int
forall a. Face a -> [a]
forall a. (a -> a -> a) -> Face a -> a
forall m a. Monoid m => (a -> m) -> Face a -> m
forall b a. (b -> a -> b) -> b -> Face a -> b
forall a b. (a -> b -> b) -> b -> Face a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Face a -> a
$cproduct :: forall a. Num a => Face a -> a
sum :: forall a. Num a => Face a -> a
$csum :: forall a. Num a => Face a -> a
minimum :: forall a. Ord a => Face a -> a
$cminimum :: forall a. Ord a => Face a -> a
maximum :: forall a. Ord a => Face a -> a
$cmaximum :: forall a. Ord a => Face a -> a
elem :: forall a. Eq a => a -> Face a -> Bool
$celem :: forall a. Eq a => a -> Face a -> Bool
length :: forall a. Face a -> Int
$clength :: forall a. Face a -> Int
null :: forall a. Face a -> Bool
$cnull :: forall a. Face a -> Bool
toList :: forall a. Face a -> [a]
$ctoList :: forall a. Face a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Face a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Face a -> a
foldr1 :: forall a. (a -> a -> a) -> Face a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Face a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Face a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Face a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Face a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Face a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Face a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Face a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Face a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Face a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Face a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Face a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Face a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Face a -> m
fold :: forall m. Monoid m => Face m -> m
$cfold :: forall m. Monoid m => Face m -> m
Foldable, Functor Face
Foldable Face
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Face (m a) -> m (Face a)
forall (f :: * -> *) a. Applicative f => Face (f a) -> f (Face a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Face a -> m (Face b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Face a -> f (Face b)
sequence :: forall (m :: * -> *) a. Monad m => Face (m a) -> m (Face a)
$csequence :: forall (m :: * -> *) a. Monad m => Face (m a) -> m (Face a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Face a -> m (Face b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Face a -> m (Face b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Face (f a) -> f (Face a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Face (f a) -> f (Face a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Face a -> f (Face b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Face a -> f (Face b)
Traversable)

{-# INLINEABLE facesR #-}
facesR :: [a] -> Maybe [Face a]
facesR :: forall a. [a] -> Maybe [Face a]
facesR [a]
xs = forall {a}. Maybe [Face a] -> [a] -> Maybe [Face a]
go (forall a. a -> Maybe a
Just []) [a]
xs
  where
    go :: Maybe [Face a] -> [a] -> Maybe [Face a]
go Maybe [Face a]
acc = \case
      [] ->
        Maybe [Face a]
acc
      [a
_one] ->
        forall a. Maybe a
Nothing
      [a
_one, a
_two] ->
        forall a. Maybe a
Nothing
      a
faceA : a
faceB : a
faceC : [a]
next ->
        case Maybe [Face a]
acc of
          Maybe [Face a]
Nothing ->
            Maybe [Face a] -> [a] -> Maybe [Face a]
go (forall a. a -> Maybe a
Just [Face{a
faceC :: a
faceB :: a
faceA :: a
$sel:faceC:Face :: a
$sel:faceB:Face :: a
$sel:faceA:Face :: a
..}]) [a]
next
          Just [Face a]
old ->
            Maybe [Face a] -> [a] -> Maybe [Face a]
go (forall a. a -> Maybe a
Just (Face{a
faceC :: a
faceB :: a
faceA :: a
$sel:faceC:Face :: a
$sel:faceB:Face :: a
$sel:faceA:Face :: a
..} forall a. a -> [a] -> [a]
: [Face a]
old)) [a]
next