Skip to content

Commit

Permalink
Merge pull request #196 from diagrams/cat-sep
Browse files Browse the repository at this point in the history
add convenience synonyms [hv]sep for [hv]cat' (with & sep .~ x)
  • Loading branch information
fryguybob committed Jun 5, 2014
2 parents 84a3f48 + b9b2073 commit b0ad0bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ module Diagrams.TwoD
-- * Combinators
-- ** Combining multiple diagrams
, (===), (|||), atAngle
, hcat, hcat'
, vcat, vcat'
, hcat, hcat', hsep
, vcat, vcat', vsep

-- ** Spacing and envelopes
, strutX, strutY
Expand Down
25 changes: 20 additions & 5 deletions src/Diagrams/TwoD/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module Diagrams.TwoD.Combinators
(===), (|||), atAngle

-- * n-ary combinators
, hcat, hcat'
, vcat, vcat'
, hcat, hcat', hsep
, vcat, vcat', vsep

-- * Spacing/envelopes
, strutR2
Expand All @@ -37,6 +37,7 @@ module Diagrams.TwoD.Combinators

) where

import Control.Lens ((&), (.~))
import Data.AffineSpace
import Data.Colour
import Data.Default.Class
Expand Down Expand Up @@ -116,11 +117,18 @@ hcat = hcat' def

-- | A variant of 'hcat' taking an extra 'CatOpts' record to control
-- the spacing. See the 'cat'' documentation for a description of
-- the possibilities.
-- the possibilities. For the common case of setting just a
-- separation amount, see 'hsep'.
hcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2)
=> CatOpts R2 -> [a] -> a
hcat' = cat' unitX

-- | A convenient synonym for horizontal concatenation with
-- separation: @hsep s === hcat' (with & sep .~ s)@.
hsep :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2)
=> Scalar R2 -> [a] -> a
hsep s = hcat' (def & sep .~ s)

-- | Lay out a list of juxtaposable objects in a column from top to
-- bottom, so that their local origins lie along a single vertical
-- line, with successive envelopes tangent to one another.
Expand All @@ -137,12 +145,19 @@ vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2)
vcat = vcat' def

-- | A variant of 'vcat' taking an extra 'CatOpts' record to control
-- the spacing. See the 'cat'' documentation for a description of the
-- possibilities.
-- the spacing. See the 'cat'' documentation for a description of
-- the possibilities. For the common case of setting just a
-- separation amount, see 'vsep'.
vcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2)
=> CatOpts R2 -> [a] -> a
vcat' = cat' (negateV unitY)

-- | A convenient synonym for vertical concatenation with
-- separation: @vsep s === vcat' (with & sep .~ s)@.
vsep :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2)
=> Scalar R2 -> [a] -> a
vsep s = vcat' (def & sep .~ s)

-- | @strutR2 v@ is a two-dimensional diagram which produces no
-- output, but with respect to alignment, envelope, /and trace/ acts
-- like a 1-dimensional segment oriented along the vector @v@, with
Expand Down

0 comments on commit b0ad0bd

Please sign in to comment.