Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagram b v n to QDiagram b v n Any #219

Merged
merged 1 commit into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Diagrams/Backend/CmdLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,23 @@ class ToResult d where

-- | A diagram can always produce a diagram when given @()@ as an argument.
-- This is our base case.
instance ToResult (Diagram b v n) where
type Args (Diagram b v n) = ()
type ResultOf (Diagram b v n) = Diagram b v n
instance ToResult (QDiagram b v n Any) where
type Args (QDiagram b v n Any) = ()
type ResultOf (QDiagram b v n Any) = QDiagram b v n Any

toResult d _ = d

-- | A list of diagrams can produce pages.
instance ToResult [Diagram b v n] where
type Args [Diagram b v n] = ()
type ResultOf [Diagram b v n] = [Diagram b v n]
instance ToResult [QDiagram b v n Any] where
type Args [QDiagram b v n Any] = ()
type ResultOf [QDiagram b v n Any] = [QDiagram b v n Any]

toResult ds _ = ds

-- | A list of named diagrams can give the multi-diagram interface.
instance ToResult [(String, Diagram b v n)] where
type Args [(String,Diagram b v n)] = ()
type ResultOf [(String,Diagram b v n)] = [(String,Diagram b v n)]
instance ToResult [(String, QDiagram b v n Any)] where
type Args [(String,QDiagram b v n Any)] = ()
type ResultOf [(String,QDiagram b v n Any)] = [(String,QDiagram b v n Any)]

toResult ds _ = ds

Expand Down Expand Up @@ -487,11 +487,11 @@ instance Mainable d => Mainable (IO d) where
-- specifying the name of the diagram that should be rendered. The list of
-- available diagrams may also be printed by passing the option @--list@.
--
-- Typically a backend can write its @[(String,Diagram b v n)]@ instance as
-- Typically a backend can write its @[(String,QDiagram b v n Any)]@ instance as
--
-- @
-- instance Mainable [(String,Diagram b v n)] where
-- type MainOpts [(String,Diagram b v n)] = (DiagramOpts, DiagramMultiOpts)
-- instance Mainable [(String,QDiagram b v n Any)] where
-- type MainOpts [(String,QDiagram b v n Any)] = (DiagramOpts, DiagramMultiOpts)
-- mainRender = defaultMultiMainRender
-- @
--
Expand Down Expand Up @@ -529,7 +529,7 @@ showDiaList ds = do
-- be output for each second (unit time) of animation.
--
-- This function requires a lens into the structure that the particular backend
-- uses for it's diagram base case. If @MainOpts (Diagram b v n) ~ DiagramOpts@
-- uses for it's diagram base case. If @MainOpts (QDiagram b v n Any) ~ DiagramOpts@
-- then this lens will simply be 'output'. For a backend supporting looping
-- it will most likely be @_1 . output@. This lens is required because the
-- implementation works by modifying the output field and running the base @mainRender@.
Expand All @@ -545,7 +545,7 @@ showDiaList ds = do
-- opt-in to this form or provide a different instance that makes more sense.

defaultAnimMainRender ::
(opts -> Diagram b v n -> IO ())
(opts -> QDiagram b v n Any -> IO ())
-> (Lens' opts FilePath) -- ^ A lens into the output path.
-> (opts ,DiagramAnimOpts)
-> Animation b v n
Expand Down
4 changes: 2 additions & 2 deletions src/Diagrams/ThreeD/Camera.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ instance Num n => Renderable (Camera l n) NullBackend where
-- chosen to match a 50mm camera on 35mm film. Note that Cameras take
-- up no space in the Diagram.
mm50Camera :: (Typeable n, Floating n, Ord n, Renderable (Camera PerspectiveLens n) b)
=> Diagram b V3 n
=> QDiagram b V3 n Any
mm50Camera = facing_ZCamera mm50

-- | 'facing_ZCamera l' is a camera at the origin facing along the
-- negative Z axis, with its up-axis coincident with the positive Y
-- axis, with the projection defined by l.
facing_ZCamera :: (Floating n, Ord n, Typeable n, CameraLens l, Renderable (Camera l n) b) =>
l n -> Diagram b V3 n
l n -> QDiagram b V3 n Any
facing_ZCamera l = mkQD (Prim $ Camera origin unit_Z unitY l)
mempty mempty mempty (Query . const . Any $ False)
{-# ANN facing_ZCamera ("HLint: ignore Use camelCase" :: String) #-}
Expand Down
4 changes: 2 additions & 2 deletions src/Diagrams/ThreeD/Light.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ instance Fractional n => Transformable (ParallelLight n) where
-- takes up no space.
pointLight :: (Typeable n, Num n, Ord n, Renderable (PointLight n) b)
=> Colour Double -- ^ The color of the light
-> Diagram b V3 n
-> QDiagram b V3 n Any
pointLight c = mkQD (Prim $ PointLight origin c) mempty mempty mempty
(Query . const . Any $ False)

-- | Construct a Diagram with a single ParallelLight, which takes up no space.
parallelLight :: (Typeable n, OrderedField n, Renderable (ParallelLight n) b)
=> Direction V3 n -- ^ The direction in which the light travels.
-> Colour Double -- ^ The color of the light.
-> Diagram b V3 n
-> QDiagram b V3 n Any
parallelLight d c = mkQD (Prim $ ParallelLight (fromDirection d) c)
mempty mempty mempty (Query . const . Any $ False)
10 changes: 5 additions & 5 deletions src/Diagrams/ThreeD/Shapes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ instance Fractional n => Renderable (Ellipsoid n) NullBackend where
render _ _ = mempty

-- | A sphere of radius 1 with its center at the origin.
sphere :: (Typeable n, OrderedField n, Renderable (Ellipsoid n) b) => Diagram b V3 n
sphere :: (Typeable n, OrderedField n, Renderable (Ellipsoid n) b) => QDiagram b V3 n Any
sphere = mkQD (Prim $ Ellipsoid mempty)
(mkEnvelope sphereEnv)
(mkTrace sphereTrace)
Expand Down Expand Up @@ -81,7 +81,7 @@ instance Fractional n => Renderable (Box n) NullBackend where

-- | A cube with side length 1, in the positive octant, with one
-- vertex at the origin.
cube :: (Typeable n, OrderedField n, Renderable (Box n) b) => Diagram b V3 n
cube :: (Typeable n, OrderedField n, Renderable (Box n) b) => QDiagram b V3 n Any
cube = mkQD (Prim $ Box mempty)
(mkEnvelope boxEnv)
(mkTrace boxTrace)
Expand Down Expand Up @@ -119,7 +119,7 @@ instance Fractional n => Renderable (Frustum n) NullBackend where
-- | A frustum of a right circular cone. It has height 1 oriented
-- along the positive z axis, and radii r0 and r1 at Z=0 and Z=1.
-- 'cone' and 'cylinder' are special cases.
frustum :: (TypeableFloat n, Renderable (Frustum n) b) => n -> n -> Diagram b V3 n
frustum :: (TypeableFloat n, Renderable (Frustum n) b) => n -> n -> QDiagram b V3 n Any
frustum r0 r1 = mkQD (Prim $ Frustum r0 r1 mempty)
(mkEnvelope frEnv)
(mkTrace frTrace)
Expand Down Expand Up @@ -161,10 +161,10 @@ frustum r0 r1 = mkQD (Prim $ Frustum r0 r1 mempty)

-- | A cone with its base centered on the origin, with radius 1 at the
-- base, height 1, and it's apex on the positive Z axis.
cone :: (TypeableFloat n, Renderable (Frustum n) b) => Diagram b V3 n
cone :: (TypeableFloat n, Renderable (Frustum n) b) => QDiagram b V3 n Any
cone = frustum 1 0

-- | A circular cylinder of radius 1 with one end cap centered on the
-- origin, and extending to Z=1.
cylinder :: (TypeableFloat n, Renderable (Frustum n) b) => Diagram b V3 n
cylinder :: (TypeableFloat n, Renderable (Frustum n) b) => QDiagram b V3 n Any
cylinder = frustum 1 1
36 changes: 18 additions & 18 deletions src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ widthOfJoint sStyle gToO nToO =
-- and move the origin to the attachment point. Return the diagram
-- and its width.
mkHead :: (DataFloat n, Renderable (Path V2 n) b) =>
n -> ArrowOpts n -> n -> n -> (Diagram b V2 n, n)
n -> ArrowOpts n -> n -> n -> (QDiagram b V2 n Any, n)
mkHead sz opts gToO nToO = ( (j <> h) # moveOriginBy (jWidth *^ unit_X) # lwO 0
, hWidth + jWidth)
where
Expand All @@ -303,7 +303,7 @@ mkHead sz opts gToO nToO = ( (j <> h) # moveOriginBy (jWidth *^ unit_X) # lwO 0

-- | Just like mkHead only the attachment point is on the right.
mkTail :: (DataFloat n, Renderable (Path V2 n) b) =>
n -> ArrowOpts n -> n -> n -> (Diagram b V2 n, n)
n -> ArrowOpts n -> n -> n -> (QDiagram b V2 n Any, n)
mkTail sz opts gToO nToO = ((t <> j) # moveOriginBy (jWidth *^ unitX) # lwO 0
, tWidth + jWidth)
where
Expand Down Expand Up @@ -369,14 +369,14 @@ arrowEnv opts len = getEnvelope horizShaft
-- | @arrow len@ creates an arrow of length @len@ with default
-- parameters, starting at the origin and ending at the point
-- @(len,0)@.
arrow :: (DataFloat n, Renderable (Path V2 n) b) => n -> Diagram b V2 n
arrow :: (DataFloat n, Renderable (Path V2 n) b) => n -> QDiagram b V2 n Any
arrow = arrow' def

-- | @arrow' opts len@ creates an arrow of length @len@ using the
-- given options, starting at the origin and ending at the point
-- @(len,0)@. In particular, it scales the given 'arrowShaft' so
-- that the entire arrow has length @len@.
arrow' :: (DataFloat n, Renderable (Path V2 n) b) => ArrowOpts n -> n -> Diagram b V2 n
arrow' :: (DataFloat n, Renderable (Path V2 n) b) => ArrowOpts n -> n -> QDiagram b V2 n Any
arrow' opts len = mkQD' (DelayedLeaf delayedArrow)

-- Currently we approximate the envelope of an arrow by using the
Expand Down Expand Up @@ -465,7 +465,7 @@ arrow' opts len = mkQD' (DelayedLeaf delayedArrow)

-- | @arrowBetween s e@ creates an arrow pointing from @s@ to @e@
-- with default parameters.
arrowBetween :: (DataFloat n, Renderable (Path V2 n) b) => Point V2 n -> Point V2 n -> Diagram b V2 n
arrowBetween :: (DataFloat n, Renderable (Path V2 n) b) => Point V2 n -> Point V2 n -> QDiagram b V2 n Any
arrowBetween = arrowBetween' def

-- | @arrowBetween' opts s e@ creates an arrow pointing from @s@ to
Expand All @@ -474,17 +474,17 @@ arrowBetween = arrowBetween' def
-- tail, and gaps into account.
arrowBetween'
:: (DataFloat n, Renderable (Path V2 n) b) =>
ArrowOpts n -> Point V2 n -> Point V2 n -> Diagram b V2 n
ArrowOpts n -> Point V2 n -> Point V2 n -> QDiagram b V2 n Any
arrowBetween' opts s e = arrowAt' opts s (e .-. s)

-- | Create an arrow starting at s with length and direction determined by
-- the vector v.
arrowAt :: (DataFloat n, Renderable (Path V2 n) b) => Point V2 n -> V2 n -> Diagram b V2 n
arrowAt :: (DataFloat n, Renderable (Path V2 n) b) => Point V2 n -> V2 n -> QDiagram b V2 n Any
arrowAt = arrowAt' def

arrowAt'
:: (DataFloat n, Renderable (Path V2 n) b) =>
ArrowOpts n -> Point V2 n -> V2 n -> Diagram b V2 n
ArrowOpts n -> Point V2 n -> V2 n -> QDiagram b V2 n Any
arrowAt' opts s v = arrow' opts len
# rotate dir # moveTo s
where
Expand All @@ -494,27 +494,27 @@ arrowAt' opts s v = arrow' opts len
-- | @arrowV v@ creates an arrow with the direction and norm of
-- the vector @v@ (with its tail at the origin), using default
-- parameters.
arrowV :: (DataFloat n, Renderable (Path V2 n) b) => V2 n -> Diagram b V2 n
arrowV :: (DataFloat n, Renderable (Path V2 n) b) => V2 n -> QDiagram b V2 n Any
arrowV = arrowV' def

-- | @arrowV' v@ creates an arrow with the direction and norm of
-- the vector @v@ (with its tail at the origin).
arrowV'
:: (DataFloat n, Renderable (Path V2 n) b)
=> ArrowOpts n -> V2 n -> Diagram b V2 n
=> ArrowOpts n -> V2 n -> QDiagram b V2 n Any
arrowV' opts = arrowAt' opts origin

-- | Turn a located trail into a default arrow by putting an
-- arrowhead at the end of the trail.
arrowFromLocatedTrail
:: (Renderable (Path V2 n) b, RealFloat n, Data n)
=> Located (Trail V2 n) -> Diagram b V2 n
=> Located (Trail V2 n) -> QDiagram b V2 n Any
arrowFromLocatedTrail = arrowFromLocatedTrail' def

-- | Turn a located trail into an arrow using the given options.
arrowFromLocatedTrail'
:: (Renderable (Path V2 n) b, RealFloat n, Data n)
=> ArrowOpts n -> Located (Trail V2 n) -> Diagram b V2 n
=> ArrowOpts n -> Located (Trail V2 n) -> QDiagram b V2 n Any
arrowFromLocatedTrail' opts trail = arrowBetween' opts' start end
where
opts' = opts & arrowShaft .~ unLoc trail
Expand All @@ -524,13 +524,13 @@ arrowFromLocatedTrail' opts trail = arrowBetween' opts' start end
-- | Connect two diagrams with a straight arrow.
connect
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> n1 -> n2 -> Diagram b V2 n -> Diagram b V2 n
=> n1 -> n2 -> QDiagram b V2 n Any -> QDiagram b V2 n Any
connect = connect' def

-- | Connect two diagrams with an arbitrary arrow.
connect'
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> ArrowOpts n -> n1 -> n2 -> Diagram b V2 n -> Diagram b V2 n
=> ArrowOpts n -> n1 -> n2 -> QDiagram b V2 n Any -> QDiagram b V2 n Any
connect' opts n1 n2 =
withName n1 $ \sub1 ->
withName n2 $ \sub2 ->
Expand All @@ -542,13 +542,13 @@ connect' opts n1 n2 =
connectPerim
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> n1 -> n2 -> Angle n -> Angle n
-> Diagram b V2 n -> Diagram b V2 n
-> QDiagram b V2 n Any -> QDiagram b V2 n Any
connectPerim = connectPerim' def

connectPerim'
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> ArrowOpts n -> n1 -> n2 -> Angle n -> Angle n
-> Diagram b V2 n -> Diagram b V2 n
-> QDiagram b V2 n Any -> QDiagram b V2 n Any
connectPerim' opts n1 n2 a1 a2 =
withName n1 $ \sub1 ->
withName n2 $ \sub2 ->
Expand All @@ -563,12 +563,12 @@ connectPerim' opts n1 n2 a1 a2 =
-- to find the intersection points.
connectOutside
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> n1 -> n2 -> Diagram b V2 n -> Diagram b V2 n
=> n1 -> n2 -> QDiagram b V2 n Any -> QDiagram b V2 n Any
connectOutside = connectOutside' def

connectOutside'
:: (DataFloat n, Renderable (Path V2 n) b, IsName n1, IsName n2)
=> ArrowOpts n -> n1 -> n2 -> Diagram b V2 n -> Diagram b V2 n
=> ArrowOpts n -> n1 -> n2 -> QDiagram b V2 n Any -> QDiagram b V2 n Any
connectOutside' opts n1 n2 =
withName n1 $ \b1 ->
withName n2 $ \b2 ->
Expand Down
4 changes: 2 additions & 2 deletions src/Diagrams/TwoD/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ boundingRect = (`boxFit` rect 1 1) . boundingBox

-- | \"Set the background color\" of a diagram. That is, place a
-- diagram atop a bounding rectangle of the given color.
bg :: (DataFloat n, Renderable (Path V2 n) b) => Colour Double -> Diagram b V2 n -> Diagram b V2 n
bg :: (DataFloat n, Renderable (Path V2 n) b) => Colour Double -> QDiagram b V2 n Any -> QDiagram b V2 n Any
bg c d = d <> boundingRect d # lineWidth (Output 0) # fc c

-- | Similar to 'bg' but makes the colored background rectangle larger than
-- the diagram. The first parameter is used to set how far the background
-- extends beyond the diagram.
bgFrame :: (DataFloat n, Renderable (Path V2 n) b)
=> n -> Colour Double -> Diagram b V2 n -> Diagram b V2 n
=> n -> Colour Double -> QDiagram b V2 n Any -> QDiagram b V2 n Any
bgFrame f c d = d <> boundingRect (frame f d) # lineWidth (Output 0) # fc c

4 changes: 2 additions & 2 deletions src/Diagrams/TwoD/Image.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ instance Fractional n => HasOrigin (DImage n a) where

-- | Make a 'DImage' into a 'Diagram'.
image :: (TypeableFloat n, Typeable a, Renderable (DImage n a) b)
=> DImage n a -> Diagram b V2 n
=> DImage n a -> QDiagram b V2 n Any
image img
= mkQD (Prim img)
(getEnvelope r)
Expand Down Expand Up @@ -123,7 +123,7 @@ uncheckedImageRef path w h = DImage (ImageRef path) w h mempty

-- | Crate a diagram from raw raster data.
rasterDia :: (TypeableFloat n, Renderable (DImage n Embedded) b)
=> (Int -> Int -> AlphaColour Double) -> Int -> Int -> Diagram b V2 n
=> (Int -> Int -> AlphaColour Double) -> Int -> Int -> QDiagram b V2 n Any
rasterDia f w h = image $ raster f w h

-- | Create an image "from scratch" by specifying the pixel data
Expand Down
Loading