Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Rosenbluth committed Mar 3, 2014
1 parent f78be72 commit 0cf4726
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module Diagrams.TwoD
, arrowShaft
, headSize
, tailSize
, bothSize
, headGap
, tailGap
, gap
Expand Down
16 changes: 15 additions & 1 deletion src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module Diagrams.TwoD.Arrow
, arrowShaft
, headSize
, tailSize
, bothSize
, headGap
, tailGap
, gap
Expand Down Expand Up @@ -149,7 +150,7 @@ straightShaft = trailFromOffsets [unitX]
instance Default ArrowOpts where
def = ArrowOpts
{ _arrowHead = dart
, _arrowTail = noTail
, _arrowTail = lineTail
, _arrowShaft = trailFromOffsets [unitX]
, _headSize = 0.3
, _tailSize = 0.3
Expand Down Expand Up @@ -179,6 +180,19 @@ headSize :: Lens' ArrowOpts Double
-- | Radius of a circumcircle around the tail.
tailSize :: Lens' ArrowOpts Double

bothSize :: Traversal' ArrowOpts Double
bothSize f opts =
(\h t -> opts & headSize .~ h & tailSize .~ toTailSize opts t)
<$> f (opts ^. headSize) <*> f (opts ^. tailSize)

toTailSize :: ArrowOpts -> Double -> Double
toTailSize opts s = hw / tw
where
(h, j) = (opts^.arrowHead) s (widthOfJoint $ shaftSty opts)
(t, k) = (opts^.arrowTail) 1 (widthOfJoint $ shaftSty opts)
hw = xWidth h + xWidth j
tw = xWidth t + xWidth k

-- | Distance to leave between the head and the target point.
headGap :: Lens' ArrowOpts Double

Expand Down
4 changes: 4 additions & 0 deletions src/Diagrams/TwoD/Arrowheads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Diagrams.TwoD.Arrowheads
, spike'
, thorn'
, missile'
, lineTail
, noTail
, quill
, block
Expand Down Expand Up @@ -293,6 +294,9 @@ arrowtailQuill theta =aTail

-- Standard tails ---------------------------------------------------------

lineTail :: ArrowHT
lineTail l w = (square 1 # scaleX l # scaleY w # alignR, mempty)

noTail :: ArrowHT
noTail _ _ = (mempty, mempty)

Expand Down

1 comment on commit 0cf4726

@jeffreyrosenbluth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as long as the arrowHead and arrowTail opts are set before calling bothSize

Please sign in to comment.