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

calculate arrow shaftScale using projection of ends onto shaft offset #125

Merged
merged 1 commit into from
Oct 10, 2013
Merged
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
10 changes: 5 additions & 5 deletions src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ spine tr tw hw size = tS <> shaft <> hS
-- | Calculate the amount required to scale a shaft trail so that an arrow with
-- head width hw and tail width tw has offset t.
shaftScale :: Trail R2 -> Double -> Double -> Double -> Double
shaftScale tr tw hw t = magnitude (end .-. start) / magnitude (trailOffset tr)
shaftScale tr tw hw t = (t - startOffset - endOffset) / magnitude (trailOffset tr)
where
tAngle = direction . startTangent $ (head $ trailSegments tr) :: Turn
hAngle = direction . endTangent $ (last $ trailSegments tr) :: Turn
start = origin .+^ (hw *^ fromDirection hAngle)
end = origin .+^ (t *^ unitX) .-^ (tw *^ fromDirection tAngle)
tSpine = normalized . startTangent $ (head $ trailSegments tr)
hSpine = normalized . endTangent $ (last $ trailSegments tr)
startOffset = hw *^ hSpine <.> normalized (trailOffset tr)
endOffset = tw *^ tSpine <.> normalized (trailOffset tr)

-- | @arrow len@ creates an arrow of length @len@ with default parameters.
arrow :: Renderable (Path R2) b => Double -> Diagram b R2
Expand Down