Skip to content

Commit

Permalink
handle zero case, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Rosenbluth committed Mar 4, 2014
1 parent 8ce0b10 commit 4007bdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ headSize :: Lens' ArrowOpts Double
-- | Radius of a circumcircle around the tail.
tailSize :: Lens' ArrowOpts Double

-- | Set the size of both the head and tail. The @headSize@ is set to the
-- given value and the @tailSize@ is set so that it is the same width as
-- the head. Both @arrowHead@ and @arrowTail@ should be set before using
-- bothSize.
bothSize :: Traversal' ArrowOpts Double
bothSize f opts =
(\h t -> opts & headSize .~ h & tailSize .~ toTailSize opts t)
<$> f (opts ^. headSize) <*> f (opts ^. tailSize)

-- Calculate the tailSize needed so that the head and tail are the same width.
-- If either is zero, revert to the default size. This is needed for example
-- in the noHead arrow head case.
toTailSize :: ArrowOpts -> Double -> Double
toTailSize opts s = hw / tw
toTailSize opts s = if (hw > 0) && (tw > 0) then hw / tw else 0.3
where
(h, j) = (opts^.arrowHead) s (widthOfJoint $ shaftSty opts)
(t, k) = (opts^.arrowTail) 1 (widthOfJoint $ shaftSty opts)
Expand All @@ -199,6 +206,7 @@ headGap :: Lens' ArrowOpts Double
-- | Distance to leave between the starting point and the tail.
tailGap :: Lens' ArrowOpts Double

-- | Set both the @headGap@ and @tailGap@ simultaneously.
gap :: Traversal' ArrowOpts Double
gap f opts = (\h t -> opts & headGap .~ h & tailGap .~ t) <$> f (opts ^. headGap) <*> f (opts ^. tailGap)

Expand Down
3 changes: 2 additions & 1 deletion src/Diagrams/TwoD/Arrowheads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ arrowheadMissile :: Angle -> ArrowHT
arrowheadMissile theta = smoothArrowhead $ arrowheadDart theta

-- Standard heads ---------------------------------------------------------
-- | A line the same width as the shaft.
lineHead :: ArrowHT
lineHead l w = (square 1 # scaleX l # scaleY w # alignL, mempty)

Expand Down Expand Up @@ -297,7 +298,7 @@ arrowtailQuill theta =aTail
[ v0, n1, n2, v0, n3, n4, v0 ])

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

-- | A line the same width as the shaft.
lineTail :: ArrowHT
lineTail l w = (square 1 # scaleX l # scaleY w # alignR, mempty)

Expand Down

0 comments on commit 4007bdd

Please sign in to comment.