{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DeriveTraversable          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeFamilies               #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Diagrams.Coordinates.Spherical
-- Copyright   :  (C) 2015 Christopher Chalmers
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  Christopher Chalmers
-- Stability   :  experimental
-- Portability :  non-portable
--
-- This module defines a polar coordinate data type. This type can be
-- used as an axis space for polar plots.
--
----------------------------------------------------------------------------
module Diagrams.Coordinates.Polar
  ( -- * Polar type
    Polar (..)
  , mkPolar, polar, unpolar, polarIso, polarV2

    -- * Polar functions
  , interpPolar

    -- * Classes
  , Radial (..), Circle (..)
  , HasX (..), HasY (..), HasR (..)

    -- * Basis elements
  , er, , etheta,

  ) where

import           Control.Applicative
import qualified Data.Foldable as F

import           Control.Lens
import           Control.Monad.Fix
import           Control.Monad.Zip
import           Data.Distributive
import           Data.Functor.Rep
import           Data.Typeable
import           GHC.Generics        (Generic1)

import           Diagrams.Angle
import           Diagrams.TwoD.Types

import           Linear.Affine
import           Linear.Metric
import           Linear.V3
import           Linear.Vector

import           Diagrams.Coordinates.Isomorphic
import Prelude


newtype Polar a = Polar (V2 a)
  deriving (Applicative Polar
Applicative Polar
-> (forall a b. Polar a -> (a -> Polar b) -> Polar b)
-> (forall a b. Polar a -> Polar b -> Polar b)
-> (forall a. a -> Polar a)
-> Monad Polar
forall a. a -> Polar a
forall a b. Polar a -> Polar b -> Polar b
forall a b. Polar a -> (a -> Polar b) -> Polar b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> Polar a
$creturn :: forall a. a -> Polar a
>> :: forall a b. Polar a -> Polar b -> Polar b
$c>> :: forall a b. Polar a -> Polar b -> Polar b
>>= :: forall a b. Polar a -> (a -> Polar b) -> Polar b
$c>>= :: forall a b. Polar a -> (a -> Polar b) -> Polar b
Monad, (forall a b. (a -> b) -> Polar a -> Polar b)
-> (forall a b. a -> Polar b -> Polar a) -> Functor Polar
forall a b. a -> Polar b -> Polar a
forall a b. (a -> b) -> Polar a -> Polar 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 -> Polar b -> Polar a
$c<$ :: forall a b. a -> Polar b -> Polar a
fmap :: forall a b. (a -> b) -> Polar a -> Polar b
$cfmap :: forall a b. (a -> b) -> Polar a -> Polar b
Functor, Typeable, Monad Polar
Monad Polar
-> (forall a. (a -> Polar a) -> Polar a) -> MonadFix Polar
forall a. (a -> Polar a) -> Polar a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: forall a. (a -> Polar a) -> Polar a
$cmfix :: forall a. (a -> Polar a) -> Polar a
MonadFix, Functor Polar
Functor Polar
-> (forall a. a -> Polar a)
-> (forall a b. Polar (a -> b) -> Polar a -> Polar b)
-> (forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c)
-> (forall a b. Polar a -> Polar b -> Polar b)
-> (forall a b. Polar a -> Polar b -> Polar a)
-> Applicative Polar
forall a. a -> Polar a
forall a b. Polar a -> Polar b -> Polar a
forall a b. Polar a -> Polar b -> Polar b
forall a b. Polar (a -> b) -> Polar a -> Polar b
forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. Polar a -> Polar b -> Polar a
$c<* :: forall a b. Polar a -> Polar b -> Polar a
*> :: forall a b. Polar a -> Polar b -> Polar b
$c*> :: forall a b. Polar a -> Polar b -> Polar b
liftA2 :: forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
$cliftA2 :: forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
<*> :: forall a b. Polar (a -> b) -> Polar a -> Polar b
$c<*> :: forall a b. Polar (a -> b) -> Polar a -> Polar b
pure :: forall a. a -> Polar a
$cpure :: forall a. a -> Polar a
Applicative, Functor Polar
Foldable Polar
Functor Polar
-> Foldable Polar
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Polar a -> f (Polar b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Polar (f a) -> f (Polar a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Polar a -> m (Polar b))
-> (forall (m :: * -> *) a. Monad m => Polar (m a) -> m (Polar a))
-> Traversable Polar
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 => Polar (m a) -> m (Polar a)
forall (f :: * -> *) a. Applicative f => Polar (f a) -> f (Polar a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Polar a -> m (Polar b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Polar a -> f (Polar b)
sequence :: forall (m :: * -> *) a. Monad m => Polar (m a) -> m (Polar a)
$csequence :: forall (m :: * -> *) a. Monad m => Polar (m a) -> m (Polar a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Polar a -> m (Polar b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Polar a -> m (Polar b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Polar (f a) -> f (Polar a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Polar (f a) -> f (Polar a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Polar a -> f (Polar b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Polar a -> f (Polar b)
Traversable,
            (forall a. Polar a -> Rep1 Polar a)
-> (forall a. Rep1 Polar a -> Polar a) -> Generic1 Polar
forall a. Rep1 Polar a -> Polar a
forall a. Polar a -> Rep1 Polar a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 Polar a -> Polar a
$cfrom1 :: forall a. Polar a -> Rep1 Polar a
Generic1, Monad Polar
Monad Polar
-> (forall a b. Polar a -> Polar b -> Polar (a, b))
-> (forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c)
-> (forall a b. Polar (a, b) -> (Polar a, Polar b))
-> MonadZip Polar
forall a b. Polar a -> Polar b -> Polar (a, b)
forall a b. Polar (a, b) -> (Polar a, Polar b)
forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
forall (m :: * -> *).
Monad m
-> (forall a b. m a -> m b -> m (a, b))
-> (forall a b c. (a -> b -> c) -> m a -> m b -> m c)
-> (forall a b. m (a, b) -> (m a, m b))
-> MonadZip m
munzip :: forall a b. Polar (a, b) -> (Polar a, Polar b)
$cmunzip :: forall a b. Polar (a, b) -> (Polar a, Polar b)
mzipWith :: forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
$cmzipWith :: forall a b c. (a -> b -> c) -> Polar a -> Polar b -> Polar c
mzip :: forall a b. Polar a -> Polar b -> Polar (a, b)
$cmzip :: forall a b. Polar a -> Polar b -> Polar (a, b)
MonadZip, (forall m. Monoid m => Polar m -> m)
-> (forall m a. Monoid m => (a -> m) -> Polar a -> m)
-> (forall m a. Monoid m => (a -> m) -> Polar a -> m)
-> (forall a b. (a -> b -> b) -> b -> Polar a -> b)
-> (forall a b. (a -> b -> b) -> b -> Polar a -> b)
-> (forall b a. (b -> a -> b) -> b -> Polar a -> b)
-> (forall b a. (b -> a -> b) -> b -> Polar a -> b)
-> (forall a. (a -> a -> a) -> Polar a -> a)
-> (forall a. (a -> a -> a) -> Polar a -> a)
-> (forall a. Polar a -> [a])
-> (forall a. Polar a -> Bool)
-> (forall a. Polar a -> Int)
-> (forall a. Eq a => a -> Polar a -> Bool)
-> (forall a. Ord a => Polar a -> a)
-> (forall a. Ord a => Polar a -> a)
-> (forall a. Num a => Polar a -> a)
-> (forall a. Num a => Polar a -> a)
-> Foldable Polar
forall a. Eq a => a -> Polar a -> Bool
forall a. Num a => Polar a -> a
forall a. Ord a => Polar a -> a
forall m. Monoid m => Polar m -> m
forall a. Polar a -> Bool
forall a. Polar a -> Int
forall a. Polar a -> [a]
forall a. (a -> a -> a) -> Polar a -> a
forall m a. Monoid m => (a -> m) -> Polar a -> m
forall b a. (b -> a -> b) -> b -> Polar a -> b
forall a b. (a -> b -> b) -> b -> Polar 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 => Polar a -> a
$cproduct :: forall a. Num a => Polar a -> a
sum :: forall a. Num a => Polar a -> a
$csum :: forall a. Num a => Polar a -> a
minimum :: forall a. Ord a => Polar a -> a
$cminimum :: forall a. Ord a => Polar a -> a
maximum :: forall a. Ord a => Polar a -> a
$cmaximum :: forall a. Ord a => Polar a -> a
elem :: forall a. Eq a => a -> Polar a -> Bool
$celem :: forall a. Eq a => a -> Polar a -> Bool
length :: forall a. Polar a -> Int
$clength :: forall a. Polar a -> Int
null :: forall a. Polar a -> Bool
$cnull :: forall a. Polar a -> Bool
toList :: forall a. Polar a -> [a]
$ctoList :: forall a. Polar a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Polar a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Polar a -> a
foldr1 :: forall a. (a -> a -> a) -> Polar a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Polar a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Polar a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Polar a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Polar a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Polar a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Polar a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Polar a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Polar a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Polar a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Polar a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Polar a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Polar a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Polar a -> m
fold :: forall m. Monoid m => Polar m -> m
$cfold :: forall m. Monoid m => Polar m -> m
F.Foldable)

makeWrapped ''Polar

-- can't make reasonable Additive instance

instance Distributive Polar where
  distribute :: forall (f :: * -> *) a. Functor f => f (Polar a) -> Polar (f a)
distribute f (Polar a)
f = V2 (f a) -> Polar (f a)
forall a. V2 a -> Polar a
Polar (V2 (f a) -> Polar (f a)) -> V2 (f a) -> Polar (f a)
forall a b. (a -> b) -> a -> b
$ f a -> f a -> V2 (f a)
forall a. a -> a -> V2 a
V2 ((Polar a -> a) -> f (Polar a) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Polar (V2 a
x a
_)) -> a
x) f (Polar a)
f)
                            ((Polar a -> a) -> f (Polar a) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Polar (V2 a
_ a
y)) -> a
y) f (Polar a)
f)

instance Representable Polar where
  type Rep Polar = E Polar
  tabulate :: forall a. (Rep Polar -> a) -> Polar a
tabulate Rep Polar -> a
f     = V2 a -> Polar a
forall a. V2 a -> Polar a
Polar (V2 a -> Polar a) -> V2 a -> Polar a
forall a b. (a -> b) -> a -> b
$ a -> a -> V2 a
forall a. a -> a -> V2 a
V2 (Rep Polar -> a
f Rep Polar
forall (v :: * -> *). Radial v => E v
er) (Rep Polar -> a
f Rep Polar
forall (v :: * -> *). Circle v => E v
)
  index :: forall a. Polar a -> Rep Polar -> a
index Polar a
xs (E forall x. Lens' (Polar x) x
l) = Getting a (Polar a) a -> Polar a -> a
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting a (Polar a) a
forall x. Lens' (Polar x) x
l Polar a
xs

instance Circle Polar where
  _azimuth :: forall a. Lens' (Polar a) (Angle a)
_azimuth = (V2 a -> f (V2 a)) -> Polar a -> f (Polar a)
forall a. Iso' (Polar a) (V2 a)
polarWrapper ((V2 a -> f (V2 a)) -> Polar a -> f (Polar a))
-> ((Angle a -> f (Angle a)) -> V2 a -> f (V2 a))
-> (Angle a -> f (Angle a))
-> Polar a
-> f (Polar a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f a) -> V2 a -> f (V2 a)
forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y ((a -> f a) -> V2 a -> f (V2 a))
-> ((Angle a -> f (Angle a)) -> a -> f a)
-> (Angle a -> f (Angle a))
-> V2 a
-> f (V2 a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso (Angle a) (Angle a) a a -> Iso a a (Angle a) (Angle a)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso (Angle a) (Angle a) a a
forall n. Iso' (Angle n) n
rad
  _polar :: forall a. Lens' (Polar a) (Polar a)
_polar   = (Polar a -> f (Polar a)) -> Polar a -> f (Polar a)
forall a. a -> a
id

instance HasR Polar where
  _r :: forall n. RealFloat n => Lens' (Polar n) n
_r = (V2 n -> f (V2 n)) -> Polar n -> f (Polar n)
forall a. Iso' (Polar a) (V2 a)
polarWrapper ((V2 n -> f (V2 n)) -> Polar n -> f (Polar n))
-> ((n -> f n) -> V2 n -> f (V2 n))
-> (n -> f n)
-> Polar n
-> f (Polar n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> f n) -> V2 n -> f (V2 n)
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x

-- | Construct a 'Polar' from a magnitude and an 'Angle'.
mkPolar :: n -> Angle n -> Polar n
mkPolar :: forall n. n -> Angle n -> Polar n
mkPolar n
r Angle n
θ = V2 n -> Polar n
forall a. V2 a -> Polar a
Polar (V2 n -> Polar n) -> V2 n -> Polar n
forall a b. (a -> b) -> a -> b
$ n -> n -> V2 n
forall a. a -> a -> V2 a
V2 n
r (Angle n
θAngle n -> Getting n (Angle n) n -> n
forall s a. s -> Getting a s a -> a
^.Getting n (Angle n) n
forall n. Iso' (Angle n) n
rad)

-- | Construct a 'Polar' from a magnitude and 'Angle' tuple.
polar :: (n, Angle n) -> Polar n
polar :: forall n. (n, Angle n) -> Polar n
polar = (n -> Angle n -> Polar n) -> (n, Angle n) -> Polar n
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry n -> Angle n -> Polar n
forall n. n -> Angle n -> Polar n
mkPolar

-- | Turn a 'Polar' back into a magnitude and 'Angle' tuple.
unpolar :: Polar n -> (n, Angle n)
unpolar :: forall n. Polar n -> (n, Angle n)
unpolar (Polar (V2 n
r n
θ)) = (n
r, n
θ n -> AReview (Angle n) n -> Angle n
forall b a. b -> AReview a b -> a
@@ AReview (Angle n) n
forall n. Iso' (Angle n) n
rad)

-- | 'Iso'' between 'Polar' and its tuple form.
polarIso :: Iso' (Polar n) (n, Angle n)
polarIso :: forall n. Iso' (Polar n) (n, Angle n)
polarIso = (Polar n -> (n, Angle n))
-> ((n, Angle n) -> Polar n)
-> Iso (Polar n) (Polar n) (n, Angle n) (n, Angle n)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Polar n -> (n, Angle n)
forall n. Polar n -> (n, Angle n)
unpolar (n, Angle n) -> Polar n
forall n. (n, Angle n) -> Polar n
polar

-- | Numerical 'Iso'' between 'Polar' and 'R2'.
polarV2 :: RealFloat n => Iso' (Polar n) (V2 n)
polarV2 :: forall n. RealFloat n => Iso' (Polar n) (V2 n)
polarV2 = (Polar n -> V2 n)
-> (V2 n -> Polar n) -> Iso (Polar n) (Polar n) (V2 n) (V2 n)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Polar (V2 n
r n
θ)) -> n -> n -> V2 n
forall a. a -> a -> V2 a
V2 (n
r n -> n -> n
forall a. Num a => a -> a -> a
* n -> n
forall a. Floating a => a -> a
cos n
θ) (n
r n -> n -> n
forall a. Num a => a -> a -> a
* n -> n
forall a. Floating a => a -> a
sin n
θ))
              (\v :: V2 n
v@(V2 n
x n
y)       -> V2 n -> Polar n
forall a. V2 a -> Polar a
Polar (V2 n -> Polar n) -> V2 n -> Polar n
forall a b. (a -> b) -> a -> b
$ n -> n -> V2 n
forall a. a -> a -> V2 a
V2 (V2 n -> n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> a
norm V2 n
v) (n -> n -> n
forall a. RealFloat a => a -> a -> a
atan2 n
y n
x))

-- internal iso for instances
polarWrapper :: Iso' (Polar a) (V2 a)
polarWrapper :: forall a. Iso' (Polar a) (V2 a)
polarWrapper = (Polar a -> V2 a)
-> (V2 a -> Polar a) -> Iso (Polar a) (Polar a) (V2 a) (V2 a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Polar V2 a
v) -> V2 a
v) V2 a -> Polar a
forall a. V2 a -> Polar a
Polar

-- | Polar interpolation between two polar coordinates.
interpPolar :: Num n => n -> Polar n -> Polar n -> Polar n
interpPolar :: forall n. Num n => n -> Polar n -> Polar n -> Polar n
interpPolar n
t (Polar V2 n
a) (Polar V2 n
b) = V2 n -> Polar n
forall a. V2 a -> Polar a
Polar (n -> V2 n -> V2 n -> V2 n
forall (f :: * -> *) a.
(Additive f, Num a) =>
a -> f a -> f a -> f a
lerp n
t V2 n
a V2 n
b)


-- | Space which has a radial length basis. For Polar and Cylindrical this is
--   the radius of the circle in the xy-plane. For Spherical this is the
--   distance from the origin.
class Radial t where
  _radial :: Lens' (t a) a

instance Radial Polar where
  _radial :: forall x. Lens' (Polar x) x
_radial = (V2 a -> f (V2 a)) -> Polar a -> f (Polar a)
forall a. Iso' (Polar a) (V2 a)
polarWrapper ((V2 a -> f (V2 a)) -> Polar a -> f (Polar a))
-> ((a -> f a) -> V2 a -> f (V2 a))
-> (a -> f a)
-> Polar a
-> f (Polar a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f a) -> V2 a -> f (V2 a)
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x

-- | Space which has a radial and angular basis.
class Radial t => Circle t where
  _azimuth :: Lens' (t a) (Angle a)
  _polar   :: Lens' (t a) (Polar a)

er :: Radial v => E v
er :: forall (v :: * -> *). Radial v => E v
er = (forall x. Lens' (v x) x) -> E v
forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall x. Lens' (v x) x
forall (t :: * -> *) a. Radial t => Lens' (t a) a
_radial

, etheta :: Circle v => E v
eθ :: forall (v :: * -> *). Circle v => E v
     = (forall x. Lens' (v x) x) -> E v
forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E ((Polar x -> f (Polar x)) -> v x -> f (v x)
forall (t :: * -> *) a. Circle t => Lens' (t a) (Polar a)
_polar ((Polar x -> f (Polar x)) -> v x -> f (v x))
-> ((x -> f x) -> Polar x -> f (Polar x))
-> (x -> f x)
-> v x
-> f (v x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (V2 x -> f (V2 x)) -> Polar x -> f (Polar x)
forall a. Iso' (Polar a) (V2 a)
polarWrapper ((V2 x -> f (V2 x)) -> Polar x -> f (Polar x))
-> ((x -> f x) -> V2 x -> f (V2 x))
-> (x -> f x)
-> Polar x
-> f (Polar x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (x -> f x) -> V2 x -> f (V2 x)
forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y)
etheta :: forall (v :: * -> *). Circle v => E v
etheta = E v
forall (v :: * -> *). Circle v => E v


-- | Coordinate with at least one dimension where the x coordinate can be
--   retrieved numerically. Note this differs slightly from 'R1' which requires
--   a lens for all values. This allows instances for different coordinates
--   such as 'Polar', where the x coordinate can only be retrieved numerically.
class HasX t where
  x_ :: RealFloat n => Lens' (t n) n

instance HasX v => HasX (Point v) where
  x_ :: forall n. RealFloat n => Lens' (Point v n) n
x_ = (v n -> f (v n)) -> Point v n -> f (Point v n)
forall (f :: * -> *) a. Iso' (Point f a) (f a)
_Point ((v n -> f (v n)) -> Point v n -> f (Point v n))
-> ((n -> f n) -> v n -> f (v n))
-> (n -> f n)
-> Point v n
-> f (Point v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> f n) -> v n -> f (v n)
forall (t :: * -> *) n. (HasX t, RealFloat n) => Lens' (t n) n
x_

instance HasX V2    where x_ :: forall n. RealFloat n => Lens' (V2 n) n
x_ = (n -> f n) -> V2 n -> f (V2 n)
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x
instance HasX V3    where x_ :: forall n. RealFloat n => Lens' (V3 n) n
x_ = (n -> f n) -> V3 n -> f (V3 n)
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x
instance HasX Polar where x_ :: forall n. RealFloat n => Lens' (Polar n) n
x_ = (V2 n -> f (V2 n)) -> Polar n -> f (Polar n)
forall n. RealFloat n => Iso' (Polar n) (V2 n)
polarV2 ((V2 n -> f (V2 n)) -> Polar n -> f (Polar n))
-> ((n -> f n) -> V2 n -> f (V2 n))
-> (n -> f n)
-> Polar n
-> f (Polar n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> f n) -> V2 n -> f (V2 n)
forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x

-- | Coordinate with at least two dimensions where the x and y coordinates can be
--   retreived numerically.
class HasX t => HasY t where
  y_ :: RealFloat n => Lens' (t n) n
  y_ = (V2 n -> f (V2 n)) -> t n -> f (t n)
forall (t :: * -> *) n. (HasY t, RealFloat n) => Lens' (t n) (V2 n)
xy_ ((V2 n -> f (V2 n)) -> t n -> f (t n))
-> ((n -> f n) -> V2 n -> f (V2 n)) -> (n -> f n) -> t n -> f (t n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> f n) -> V2 n -> f (V2 n)
forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y

  xy_ :: RealFloat n => Lens' (t n) (V2 n)

instance HasY v => HasY (Point v) where
  xy_ :: forall n. RealFloat n => Lens' (Point v n) (V2 n)
xy_ = (v n -> f (v n)) -> Point v n -> f (Point v n)
forall (g :: * -> *) a. Lens' (Point g a) (g a)
lensP ((v n -> f (v n)) -> Point v n -> f (Point v n))
-> ((V2 n -> f (V2 n)) -> v n -> f (v n))
-> (V2 n -> f (V2 n))
-> Point v n
-> f (Point v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (V2 n -> f (V2 n)) -> v n -> f (v n)
forall (t :: * -> *) n. (HasY t, RealFloat n) => Lens' (t n) (V2 n)
xy_

instance HasY V2    where xy_ :: forall n. RealFloat n => Lens' (V2 n) (V2 n)
xy_ = (V2 n -> f (V2 n)) -> V2 n -> f (V2 n)
forall (t :: * -> *) a. R2 t => Lens' (t a) (V2 a)
_xy
instance HasY V3    where xy_ :: forall n. RealFloat n => Lens' (V3 n) (V2 n)
xy_ = (V2 n -> f (V2 n)) -> V3 n -> f (V3 n)
forall (t :: * -> *) a. R2 t => Lens' (t a) (V2 a)
_xy
instance HasY Polar where xy_ :: forall n. RealFloat n => Lens' (Polar n) (V2 n)
xy_ = (V2 n -> f (V2 n)) -> Polar n -> f (Polar n)
forall n. RealFloat n => Iso' (Polar n) (V2 n)
polarV2

-- | Does not satify lens laws.
instance RealFloat n => PointLike V2 n (Polar n) where
  pointLike :: Iso' (Point V2 n) (Polar n)
pointLike = p (V2 n) (f (V2 n)) -> p (Point V2 n) (f (Point V2 n))
forall (f :: * -> *) a. Iso' (Point f a) (f a)
_Point (p (V2 n) (f (V2 n)) -> p (Point V2 n) (f (Point V2 n)))
-> (p (Polar n) (f (Polar n)) -> p (V2 n) (f (V2 n)))
-> p (Polar n) (f (Polar n))
-> p (Point V2 n) (f (Point V2 n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso (Polar n) (Polar n) (V2 n) (V2 n)
-> Iso (V2 n) (V2 n) (Polar n) (Polar n)
forall s t a b. AnIso s t a b -> Iso b a t s
from AnIso (Polar n) (Polar n) (V2 n) (V2 n)
forall n. RealFloat n => Iso' (Polar n) (V2 n)
polarV2
  {-# INLINE pointLike #-}