{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Diagrams.Core.Envelope
(
Envelope(..)
, appEnvelope
, onEnvelope
, mkEnvelope
, pointEnvelope
, Enveloped(..)
, diameter
, radius
, extent
, size
, envelopeVMay
, envelopeV
, envelopePMay
, envelopeP
, envelopeSMay
, envelopeS
, OrderedField
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative ((<$>))
#endif
import Control.Lens (Rewrapped, Wrapped (..), iso, mapped,
op, over, (&), (.~), _Wrapping')
import Data.Functor.Rep
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import Data.Semigroup
import qualified Data.Set as S
import Diagrams.Core.HasOrigin
import Diagrams.Core.Points
import Diagrams.Core.Transform
import Diagrams.Core.V
import Linear.Metric
import Linear.Vector
newtype Envelope v n = Envelope (Maybe (v n -> Max n))
instance Wrapped (Envelope v n) where
type Unwrapped (Envelope v n) = Maybe (v n -> Max n)
_Wrapped' :: p (Unwrapped (Envelope v n)) (f (Unwrapped (Envelope v n)))
-> p (Envelope v n) (f (Envelope v n))
_Wrapped' = (Envelope v n -> Maybe (v n -> Max n))
-> (Maybe (v n -> Max n) -> Envelope v n)
-> Iso
(Envelope v n)
(Envelope v n)
(Maybe (v n -> Max n))
(Maybe (v n -> Max n))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Envelope Maybe (v n -> Max n)
e) -> Maybe (v n -> Max n)
e) Maybe (v n -> Max n) -> Envelope v n
forall (v :: * -> *) n. Maybe (v n -> Max n) -> Envelope v n
Envelope
instance Rewrapped (Envelope v n) (Envelope v' n')
appEnvelope :: Envelope v n -> Maybe (v n -> n)
appEnvelope :: Envelope v n -> Maybe (v n -> n)
appEnvelope (Envelope Maybe (v n -> Max n)
e) = (Max n -> n
forall a. Max a -> a
getMax (Max n -> n) -> (v n -> Max n) -> v n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((v n -> Max n) -> v n -> n)
-> Maybe (v n -> Max n) -> Maybe (v n -> n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (v n -> Max n)
e
onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
onEnvelope (v n -> n) -> v n -> n
t = ASetter (Envelope v n) (Envelope v n) (v n -> Max n) (v n -> Max n)
-> ((v n -> Max n) -> v n -> Max n) -> Envelope v n -> Envelope v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Unwrapped (Envelope v n) -> Envelope v n)
-> Iso' (Envelope v n) (Unwrapped (Envelope v n))
forall s. Wrapped s => (Unwrapped s -> s) -> Iso' s (Unwrapped s)
_Wrapping' Unwrapped (Envelope v n) -> Envelope v n
forall (v :: * -> *) n. Maybe (v n -> Max n) -> Envelope v n
Envelope ((Maybe (v n -> Max n) -> Identity (Maybe (v n -> Max n)))
-> Envelope v n -> Identity (Envelope v n))
-> (((v n -> Max n) -> Identity (v n -> Max n))
-> Maybe (v n -> Max n) -> Identity (Maybe (v n -> Max n)))
-> ASetter
(Envelope v n) (Envelope v n) (v n -> Max n) (v n -> Max n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((v n -> Max n) -> Identity (v n -> Max n))
-> Maybe (v n -> Max n) -> Identity (Maybe (v n -> Max n))
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped) ((n -> Max n
forall a. a -> Max a
Max (n -> Max n) -> (v n -> n) -> v n -> Max n
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((v n -> n) -> v n -> Max n)
-> ((v n -> Max n) -> v n -> n) -> (v n -> Max n) -> v n -> Max n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v n -> n) -> v n -> n
t ((v n -> n) -> v n -> n)
-> ((v n -> Max n) -> v n -> n) -> (v n -> Max n) -> v n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Max n -> n
forall a. Max a -> a
getMax (Max n -> n) -> (v n -> Max n) -> v n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
.))
mkEnvelope :: (v n -> n) -> Envelope v n
mkEnvelope :: (v n -> n) -> Envelope v n
mkEnvelope = Maybe (v n -> Max n) -> Envelope v n
forall (v :: * -> *) n. Maybe (v n -> Max n) -> Envelope v n
Envelope (Maybe (v n -> Max n) -> Envelope v n)
-> ((v n -> n) -> Maybe (v n -> Max n))
-> (v n -> n)
-> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v n -> Max n) -> Maybe (v n -> Max n)
forall a. a -> Maybe a
Just ((v n -> Max n) -> Maybe (v n -> Max n))
-> ((v n -> n) -> v n -> Max n)
-> (v n -> n)
-> Maybe (v n -> Max n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> Max n
forall a. a -> Max a
Max (n -> Max n) -> (v n -> n) -> v n -> Max n
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
pointEnvelope :: (Fractional n, Metric v) => Point v n -> Envelope v n
pointEnvelope :: Point v n -> Envelope v n
pointEnvelope Point v n
p = Point v n -> Envelope v n -> Envelope v n
forall (v :: * -> *) n t.
(InSpace v n t, HasOrigin t) =>
Point v n -> t -> t
moveTo Point v n
p ((v n -> n) -> Envelope v n
forall (v :: * -> *) n. (v n -> n) -> Envelope v n
mkEnvelope ((v n -> n) -> Envelope v n) -> (v n -> n) -> Envelope v n
forall a b. (a -> b) -> a -> b
$ n -> v n -> n
forall a b. a -> b -> a
const n
0)
deriving instance Ord n => Semigroup (Envelope v n)
deriving instance Ord n => Monoid (Envelope v n)
type instance V (Envelope v n) = v
type instance N (Envelope v n) = n
instance Show (Envelope v n) where
show :: Envelope v n -> String
show Envelope v n
_ = String
"<envelope>"
instance (Metric v, Fractional n) => HasOrigin (Envelope v n) where
moveOriginTo :: Point (V (Envelope v n)) (N (Envelope v n))
-> Envelope v n -> Envelope v n
moveOriginTo (P V (Envelope v n) (N (Envelope v n))
u) = ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
forall (v :: * -> *) n.
((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
onEnvelope (((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n)
-> ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
forall a b. (a -> b) -> a -> b
$ \v n -> n
oldEnv v n
v -> v n -> n
oldEnv v n
v n -> n -> n
forall a. Num a => a -> a -> a
- ((v n
V (Envelope v n) (N (Envelope v n))
u v n -> n -> v n
forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ (v n
v v n -> v n -> n
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` v n
v)) v n -> v n -> n
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` v n
v)
instance (Metric v, Floating n) => Transformable (Envelope v n) where
transform :: Transformation (V (Envelope v n)) (N (Envelope v n))
-> Envelope v n -> Envelope v n
transform Transformation (V (Envelope v n)) (N (Envelope v n))
t = Point (V (Envelope v n)) (N (Envelope v n))
-> Envelope v n -> Envelope v n
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo (v n -> Point v n
forall (f :: * -> *) a. f a -> Point f a
P (v n -> Point v n)
-> (Transformation v n -> v n) -> Transformation v n -> Point v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated (v n -> v n)
-> (Transformation v n -> v n) -> Transformation v n -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transformation v n -> v n
forall (v :: * -> *) n. Transformation v n -> v n
transl (Transformation v n -> Point v n)
-> Transformation v n -> Point v n
forall a b. (a -> b) -> a -> b
$ Transformation v n
Transformation (V (Envelope v n)) (N (Envelope v n))
t) (Envelope v n -> Envelope v n)
-> (Envelope v n -> Envelope v n) -> Envelope v n -> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
forall (v :: * -> *) n.
((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
onEnvelope (v n -> n) -> v n -> n
g
where
g :: (v n -> n) -> v n -> n
g v n -> n
f v n
v = v n -> n
f v n
v' n -> n -> n
forall a. Fractional a => a -> a -> a
/ (v n
v' v n -> v n -> n
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` v n
vi)
where
v' :: v n
v' = v n -> v n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n) -> v n -> v n
forall a b. (a -> b) -> a -> b
$ (v n :-: v n) -> v n -> v n
forall u v. (u :-: v) -> u -> v
lapp (Transformation v n -> v n :-: v n
forall (v :: * -> *) n. Transformation v n -> v n :-: v n
transp Transformation v n
Transformation (V (Envelope v n)) (N (Envelope v n))
t) v n
v
vi :: v n
vi = Transformation v n -> v n -> v n
forall (v :: * -> *) n. Transformation v n -> v n -> v n
apply (Transformation v n -> Transformation v n
forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv Transformation v n
Transformation (V (Envelope v n)) (N (Envelope v n))
t) v n
v
type OrderedField s = (Floating s, Ord s)
class (Metric (V a), OrderedField (N a)) => Enveloped a where
getEnvelope :: a -> Envelope (V a) (N a)
instance (Metric v, OrderedField n) => Enveloped (Envelope v n) where
getEnvelope :: Envelope v n -> Envelope (V (Envelope v n)) (N (Envelope v n))
getEnvelope = Envelope v n -> Envelope (V (Envelope v n)) (N (Envelope v n))
forall a. a -> a
id
instance (OrderedField n, Metric v) => Enveloped (Point v n) where
getEnvelope :: Point v n -> Envelope (V (Point v n)) (N (Point v n))
getEnvelope Point v n
p = Point v n -> Envelope v n -> Envelope v n
forall (v :: * -> *) n t.
(InSpace v n t, HasOrigin t) =>
Point v n -> t -> t
moveTo Point v n
p (Envelope v n -> Envelope v n)
-> ((v n -> n) -> Envelope v n) -> (v n -> n) -> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v n -> n) -> Envelope v n
forall (v :: * -> *) n. (v n -> n) -> Envelope v n
mkEnvelope ((v n -> n) -> Envelope v n) -> (v n -> n) -> Envelope v n
forall a b. (a -> b) -> a -> b
$ n -> v n -> n
forall a b. a -> b -> a
const n
0
instance Enveloped t => Enveloped (TransInv t) where
getEnvelope :: TransInv t -> Envelope (V (TransInv t)) (N (TransInv t))
getEnvelope = t -> Envelope (V t) (N t)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope (t -> Envelope (V t) (N t))
-> (TransInv t -> t) -> TransInv t -> Envelope (V t) (N t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (TransInv t) -> TransInv t)
-> TransInv t -> Unwrapped (TransInv t)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (TransInv t) -> TransInv t
forall t. t -> TransInv t
TransInv
instance (Enveloped a, Enveloped b, V a ~ V b, N a ~ N b) => Enveloped (a,b) where
getEnvelope :: (a, b) -> Envelope (V (a, b)) (N (a, b))
getEnvelope (a
x,b
y) = a -> Envelope (V a) (N a)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope a
x Envelope (V b) (N b)
-> Envelope (V b) (N b) -> Envelope (V b) (N b)
forall a. Semigroup a => a -> a -> a
<> b -> Envelope (V b) (N b)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope b
y
instance Enveloped b => Enveloped [b] where
getEnvelope :: [b] -> Envelope (V [b]) (N [b])
getEnvelope = [Envelope (V b) (N b)] -> Envelope (V b) (N b)
forall a. Monoid a => [a] -> a
mconcat ([Envelope (V b) (N b)] -> Envelope (V b) (N b))
-> ([b] -> [Envelope (V b) (N b)]) -> [b] -> Envelope (V b) (N b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Envelope (V b) (N b)) -> [b] -> [Envelope (V b) (N b)]
forall a b. (a -> b) -> [a] -> [b]
map b -> Envelope (V b) (N b)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope
instance Enveloped b => Enveloped (M.Map k b) where
getEnvelope :: Map k b -> Envelope (V (Map k b)) (N (Map k b))
getEnvelope = [Envelope (V b) (N b)] -> Envelope (V b) (N b)
forall a. Monoid a => [a] -> a
mconcat ([Envelope (V b) (N b)] -> Envelope (V b) (N b))
-> (Map k b -> [Envelope (V b) (N b)])
-> Map k b
-> Envelope (V b) (N b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Envelope (V b) (N b)) -> [b] -> [Envelope (V b) (N b)]
forall a b. (a -> b) -> [a] -> [b]
map b -> Envelope (V b) (N b)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope ([b] -> [Envelope (V b) (N b)])
-> (Map k b -> [b]) -> Map k b -> [Envelope (V b) (N b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k b -> [b]
forall k a. Map k a -> [a]
M.elems
instance Enveloped b => Enveloped (S.Set b) where
getEnvelope :: Set b -> Envelope (V (Set b)) (N (Set b))
getEnvelope = [Envelope (V b) (N b)] -> Envelope (V b) (N b)
forall a. Monoid a => [a] -> a
mconcat ([Envelope (V b) (N b)] -> Envelope (V b) (N b))
-> (Set b -> [Envelope (V b) (N b)])
-> Set b
-> Envelope (V b) (N b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Envelope (V b) (N b)) -> [b] -> [Envelope (V b) (N b)]
forall a b. (a -> b) -> [a] -> [b]
map b -> Envelope (V b) (N b)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope ([b] -> [Envelope (V b) (N b)])
-> (Set b -> [b]) -> Set b -> [Envelope (V b) (N b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set b -> [b]
forall a. Set a -> [a]
S.elems
envelopeVMay :: Enveloped a => Vn a -> a -> Maybe (Vn a)
envelopeVMay :: Vn a -> a -> Maybe (Vn a)
envelopeVMay Vn a
v = ((Vn a -> N a) -> Vn a) -> Maybe (Vn a -> N a) -> Maybe (Vn a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((N a -> Vn a -> Vn a
forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ Vn a
v) (N a -> Vn a) -> ((Vn a -> N a) -> N a) -> (Vn a -> N a) -> Vn a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Vn a -> N a) -> Vn a -> N a
forall a b. (a -> b) -> a -> b
$ Vn a
v)) (Maybe (Vn a -> N a) -> Maybe (Vn a))
-> (a -> Maybe (Vn a -> N a)) -> a -> Maybe (Vn a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Envelope (V a) (N a) -> Maybe (Vn a -> N a)
forall (v :: * -> *) n. Envelope v n -> Maybe (v n -> n)
appEnvelope (Envelope (V a) (N a) -> Maybe (Vn a -> N a))
-> (a -> Envelope (V a) (N a)) -> a -> Maybe (Vn a -> N a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Envelope (V a) (N a)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope
envelopeV :: Enveloped a => Vn a -> a -> Vn a
envelopeV :: Vn a -> a -> Vn a
envelopeV Vn a
v = Vn a -> Maybe (Vn a) -> Vn a
forall a. a -> Maybe a -> a
fromMaybe Vn a
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero (Maybe (Vn a) -> Vn a) -> (a -> Maybe (Vn a)) -> a -> Vn a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vn a -> a -> Maybe (Vn a)
forall a. Enveloped a => Vn a -> a -> Maybe (Vn a)
envelopeVMay Vn a
v
envelopePMay :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe (Point v n)
envelopePMay :: v n -> a -> Maybe (Point v n)
envelopePMay v n
v = (v n -> Point v n) -> Maybe (v n) -> Maybe (Point v n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap v n -> Point v n
forall (f :: * -> *) a. f a -> Point f a
P (Maybe (v n) -> Maybe (Point v n))
-> (a -> Maybe (v n)) -> a -> Maybe (Point v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vn a -> a -> Maybe (Vn a)
forall a. Enveloped a => Vn a -> a -> Maybe (Vn a)
envelopeVMay v n
Vn a
v
envelopeP :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n
envelopeP :: v n -> a -> Point v n
envelopeP v n
v = v n -> Point v n
forall (f :: * -> *) a. f a -> Point f a
P (v n -> Point v n) -> (a -> v n) -> a -> Point v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vn a -> a -> Vn a
forall a. Enveloped a => Vn a -> a -> Vn a
envelopeV v n
Vn a
v
envelopeSMay :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe n
envelopeSMay :: v n -> a -> Maybe n
envelopeSMay v n
v = ((v n -> n) -> n) -> Maybe (v n -> n) -> Maybe n
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((n -> n -> n
forall a. Num a => a -> a -> a
* v n -> n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> a
norm v n
v) (n -> n) -> ((v n -> n) -> n) -> (v n -> n) -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((v n -> n) -> v n -> n
forall a b. (a -> b) -> a -> b
$ v n
v)) (Maybe (v n -> n) -> Maybe n)
-> (a -> Maybe (v n -> n)) -> a -> Maybe n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Envelope v n -> Maybe (v n -> n)
forall (v :: * -> *) n. Envelope v n -> Maybe (v n -> n)
appEnvelope (Envelope v n -> Maybe (v n -> n))
-> (a -> Envelope v n) -> a -> Maybe (v n -> n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Envelope v n
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope
envelopeS :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n
envelopeS :: v n -> a -> n
envelopeS v n
v = n -> Maybe n -> n
forall a. a -> Maybe a -> a
fromMaybe n
0 (Maybe n -> n) -> (a -> Maybe n) -> a -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v n -> a -> Maybe n
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> Maybe n
envelopeSMay v n
v
diameter :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n
diameter :: v n -> a -> n
diameter v n
v a
a = n -> ((n, n) -> n) -> Maybe (n, n) -> n
forall b a. b -> (a -> b) -> Maybe a -> b
maybe n
0 (\(n
lo,n
hi) -> (n
hi n -> n -> n
forall a. Num a => a -> a -> a
- n
lo) n -> n -> n
forall a. Num a => a -> a -> a
* v n -> n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> a
norm v n
v) (v n -> a -> Maybe (n, n)
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> Maybe (n, n)
extent v n
v a
a)
radius :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n
radius :: v n -> a -> n
radius v n
v = (n
0.5n -> n -> n
forall a. Num a => a -> a -> a
*) (n -> n) -> (a -> n) -> a -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v n -> a -> n
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> n
diameter v n
v
extent :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe (n, n)
extent :: v n -> a -> Maybe (n, n)
extent v n
v a
a = (\v n -> n
f -> (-v n -> n
f (v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated v n
v), v n -> n
f v n
v)) ((v n -> n) -> (n, n)) -> Maybe (v n -> n) -> Maybe (n, n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Envelope v n -> Maybe (v n -> n)
forall (v :: * -> *) n. Envelope v n -> Maybe (v n -> n)
appEnvelope (Envelope v n -> Maybe (v n -> n))
-> (a -> Envelope v n) -> a -> Maybe (v n -> n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Envelope v n
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope (a -> Maybe (v n -> n)) -> a -> Maybe (v n -> n)
forall a b. (a -> b) -> a -> b
$ a
a)
size :: (V a ~ v, N a ~ n, Enveloped a, HasBasis v) => a -> v n
size :: a -> v n
size a
d = (Rep v -> n) -> v n
forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
tabulate ((Rep v -> n) -> v n) -> (Rep v -> n) -> v n
forall a b. (a -> b) -> a -> b
$ \(E l) -> v n -> a -> n
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> n
diameter (v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero v n -> (v n -> v n) -> v n
forall a b. a -> (a -> b) -> b
& (n -> Identity n) -> v n -> Identity (v n)
forall x. Lens' (v x) x
l ((n -> Identity n) -> v n -> Identity (v n)) -> n -> v n -> v n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ n
1) a
d