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

add convenience synonyms [hv]sep for [hv]cat' (with & sep .~ x) #196

Merged
merged 1 commit into from
Jun 5, 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
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