Skip to content

Commit

Permalink
heas size measured as width of head + joint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Apr 2, 2014
1 parent 9fc01b6 commit 1911ad3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 46 deletions.
69 changes: 24 additions & 45 deletions src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,45 +173,6 @@ arrowTail :: Lens' ArrowOpts ArrowHT
-- | The trail to use for the arrow shaft.
arrowShaft :: Lens' ArrowOpts (Trail R2)

-- -- | Radius of a circumcircle around the head.
-- headSize :: Lens' ArrowOpts Double

-- -- | Radius of a circumcircle around the tail.
-- tailSize :: Lens' ArrowOpts Double

-- -- | Width of the head.
-- headWidth :: Setter' ArrowOpts Double
-- headWidth f opts =
-- (\hd -> opts & headSize .~ g hd) <$> f (opts ^. headSize)
-- where
-- g w = w / (xWidth h + xWidth j)
-- (h, j) = (opts ^. arrowHead) 1 (widthOfJoint $ shaftSty opts)

-- -- | Width of the tail.
-- tailWidth :: Setter' ArrowOpts Double
-- tailWidth f opts =
-- (\tl -> opts & tailSize .~ g tl) <$> f (opts ^. tailSize)
-- where
-- g w = w / (xWidth t + xWidth j)
-- (t, j) = (opts ^. arrowTail) 1 (widthOfJoint $ shaftSty opts)

-- -- | Set both the @headWidth@ and @tailWidth@.
-- widths :: Traversal' ArrowOpts Double
-- widths f opts =
-- (\hd tl -> opts & headSize .~ gh hd & tailSize .~ gt tl)
-- <$> f (opts ^. headSize) <*> f (opts ^. tailSize)
-- where
-- gh w = w / (xWidth h + xWidth j)
-- (h, j) = (opts ^. arrowHead) 1 (widthOfJoint $ shaftSty opts)
-- gt w = w / (xWidth t + xWidth j')
-- (t, j') = (opts ^. arrowTail) 1 (widthOfJoint $ shaftSty opts)

-- -- | Set the size of both the head and tail.
-- sizes :: Traversal' ArrowOpts Double
-- sizes f opts =
-- (\h t -> opts & headSize .~ h & tailSize .~ t)
-- <$> f (opts ^. headSize) <*> f (opts ^. tailSize)

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

Expand Down Expand Up @@ -403,7 +364,7 @@ mkHead :: Renderable (Path R2) b => Double -> ArrowOpts -> (Diagram b R2, Double
mkHead size opts = ((j <> h) # moveOriginBy (jWidth *^ unit_X) # lw 0
, hWidth + jWidth)
where
(h', j') = (opts^.arrowHead) size (widthOfJoint $ shaftSty opts)
(h', j') = (opts^.arrowHead) (size / refHeadWidth opts) (widthOfJoint $ shaftSty opts)
hWidth = xWidth h'
jWidth = xWidth j'
h = stroke h' # applyStyle (headSty opts)
Expand All @@ -414,12 +375,22 @@ mkTail :: Renderable (Path R2) b => Double -> ArrowOpts -> (Diagram b R2, Double
mkTail size opts = ((t <> j) # moveOriginBy (jWidth *^ unitX) # lw 0
, tWidth + jWidth)
where
(t', j') = (opts^.arrowTail) size (widthOfJoint $ shaftSty opts)
(t', j') = (opts^.arrowTail) (size / refTailWidth opts) (widthOfJoint $ shaftSty opts)
tWidth = xWidth t'
jWidth = xWidth j'
t = stroke t' # applyStyle (tailSty opts)
j = stroke j' # applyStyle (colorJoint (opts^.shaftStyle))

-- The width of a head of with diameter 1 and its joint.
refHeadWidth :: ArrowOpts -> Double
refHeadWidth opts = xWidth h + xWidth j
where (h, j) = (opts ^. arrowHead) 1 (widthOfJoint $ shaftSty opts)

-- The width of a tail of with diameter 1 and its joint.
refTailWidth :: ArrowOpts -> Double
refTailWidth opts = xWidth t + xWidth j
where (t, j) = (opts ^. arrowTail) 1 (widthOfJoint $ shaftSty opts)

-- | Make a trail with the same angles and offset as an arrow with tail width
-- tw, head width hw and shaft of tr, such that the magnituted of the shaft
-- offset is size. Used for calculating the offset of an arrow.
Expand Down Expand Up @@ -475,10 +446,16 @@ arrow len = arrow' def len
arrow' :: Renderable (Path R2) b => ArrowOpts -> Double -> Diagram b R2
arrow' opts len = mkQD' (DelayedLeaf delayedArrow)

-- We set the envelope and trace of the arrow to empty.
-- XXX I'm not sure if this is the semantics we will end up
-- using, but I think it makes sense
mempty mempty mempty mempty
-- We must approximate the envelope and trace by just drawing the
-- arrow from the origin to (len,0) and using its envelope and
-- trace. That may not end up being exactly right (if the arrow
-- gets scaled, the shaft may get a bit longer or shorter, and so
-- on) but it's close enough.
--(getEnvelope approx) (getTrace approx) mempty mempty

-- Actually right now arrows have and empty envelope and trace.
mempty mempty mempty mempty

where

-- Once we learn the global transformation context (da) and the two scale
Expand All @@ -494,6 +471,8 @@ arrow' opts len = mkQD' (DelayedLeaf delayedArrow)
let (trans, globalSty) = option mempty untangle . fst $ da
in dArrow globalSty trans len g n

-- approx = dArrow mempty mempty len 0 0

-- Build an arrow and set its endpoints to the image under tr of origin and (len,0).
dArrow sty tr ln gToO nToO = (h' <> t' <> shaft)
# moveOriginBy (tWidth *^ (unit_X # rotate tAngle))
Expand Down
2 changes: 1 addition & 1 deletion src/Diagrams/TwoD/Arrowheads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ arrowtailQuill theta =aTail
-- Standard tails ---------------------------------------------------------
-- | A line the same width as the shaft.
lineTail :: ArrowHT
lineTail l w = (square 1 # scaleX l # scaleY w # alignR, mempty)
lineTail l w = (square 1 # scaleY w # scaleX l # alignR, mempty)

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

1 comment on commit 1911ad3

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

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

Arrow head and tail sizes are specified as the width of the head + its joint. That way we can recapture the behavior of the
traversals we lost in converting to units. In particular we solve the uarrow problem by setting the headSize and tailSize to the same value.

Unfortunately, we missed a few things when converting arrows to measure.

  • The joints are not working because they need to know the ultimate line width in output units.
  • Arrows have no envelope, we need the gToO and nToO in order to calculate this.

These problems can be seen in image below where I made the head and tail translucent to show that the joint is not working.
I Also need to add some horizontal strut to make the arrow show up due to it's lack of envelope.

http://i.imgur.com/iQH5c2o.png

Please sign in to comment.