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

Generalise vertical- and horizontal concatenation beyond the diagrams use case #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions diagrams-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Library
containers >= 0.4.2 && < 0.6,
unordered-containers >= 0.2 && < 0.3,
semigroups >= 0.8.4 && < 0.19,
numbered-semigroups >= 0.1 && < 0.2,
monoid-extras >= 0.3 && < 0.5,
dual-tree >= 0.2 && < 0.3,
lens >= 4.0 && < 4.16,
Expand Down
25 changes: 24 additions & 1 deletion src/Diagrams/Core/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}
-- We have some orphan Action instances here, but since Action is a multi-param
Expand Down Expand Up @@ -132,13 +133,14 @@ module Diagrams.Core.Types
import Control.Arrow (first, second, (***))
import Control.Lens (Lens', Prism', Rewrapped,
Wrapped (..), iso, lens, over,
prism', view, (^.), _Wrapped,
prism', view, (^.), (.~), _Wrapped,
_Wrapping)
import Control.Monad (mplus)
import Data.List (isSuffixOf)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, listToMaybe)
import Data.Semigroup
import Data.Semigroup.Numbered (SemigroupNo(..))
import qualified Data.Traversable as T
import Data.Tree
import Data.Typeable
Expand All @@ -164,6 +166,10 @@ import Diagrams.Core.V
import Linear.Affine
import Linear.Metric
import Linear.Vector
import Linear.V1 (R1, _x)
import Linear.V2 (R2, _y)
import Linear.V3 (R3, _z)
import Linear.V4 (R4, _w)

-- XXX TODO: add lots of actual diagrams to illustrate the
-- documentation! Haddock supports \<\<inline image urls\>\>.
Expand Down Expand Up @@ -492,6 +498,23 @@ instance (Metric v, OrderedField n, Semigroup m)
-- swap order so that primitives of d2 come first, i.e. will be
-- rendered first, i.e. will be on the bottom.

-- | Lay out diagrams side-by-side. Cf. <http://hackage.haskell.org/package/diagrams-lib/docs/Diagrams-TwoD-Combinators.html#v:-124--124--124- |||>.
instance (Metric v, R1 v, OrderedField n, Semigroup m, Monoid m)
=> SemigroupNo 0 (QDiagram b v n m) where
sappendN _ d₀ d₁ = d₀ <> juxtapose (_x.~1 $ zero) d₀ d₁
-- | Stack diagrams vertically. Cf. <http://hackage.haskell.org/package/diagrams-lib/docs/Diagrams-TwoD-Combinators.html#v:-61--61--61- ===>.
instance (Metric v, R2 v, OrderedField n, Semigroup m, Monoid m)
=> SemigroupNo 1 (QDiagram b v n m) where
sappendN _ d₀ d₁ = d₀ <> juxtapose (_y.~1 $ zero) d₀ d₁
-- | Stack 3D-diagrams in z-direction.
instance (Metric v, R3 v, OrderedField n, Semigroup m, Monoid m)
=> SemigroupNo 2 (QDiagram b v n m) where
sappendN _ d₀ d₁ = d₀ <> juxtapose (_z.~1 $ zero) d₀ d₁
-- | Anybody in for a game of Brockian Ultra-Cricket?
instance (Metric v, R4 v, OrderedField n, Semigroup m, Monoid m)
=> SemigroupNo 3 (QDiagram b v n m) where
sappendN _ d₀ d₁ = d₀ <> juxtapose (_w.~1 $ zero) d₀ d₁

-- | A convenient synonym for 'mappend' on diagrams, designed to be
-- used infix (to help remember which diagram goes on top of which
-- when combining them, namely, the first on top of the second).
Expand Down