Skip to content

Commit

Permalink
Don't emit last segment of a loop if it is linear
Browse files Browse the repository at this point in the history
See diagrams/diagrams-cairo#38.  This wasn't actually causing any
observable problems in the SVG backend output, but this seems a
better/more robust way to do things in any case.
  • Loading branch information
Brent Yorgey committed Jan 17, 2014
1 parent 7ffe01a commit 7ed42dc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Graphics/Rendering/SVG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ renderPath trs = S.path ! A.d makePath
makePath = mkPath $ mapM_ renderTrail (op Path trs)

renderTrail :: Located (Trail R2) -> S.Path
renderTrail (viewLoc -> (unp2 -> (x,y), t)) = flip withLine t $ \l -> do
m x y
mapM_ renderSeg (lineSegments l)
if isLoop t then z else return ()
renderTrail (viewLoc -> (unp2 -> (x,y), t)) = m x y >> withTrail renderLine renderLoop t
where
renderLine = mapM_ renderSeg . lineSegments
renderLoop lp = do
case loopSegments lp of
-- let 'z' handle the last segment if it is linear
(segs, Linear _) -> mapM_ renderSeg segs

-- otherwise we have to emit it explicitly
_ -> mapM_ renderSeg (lineSegments . cutLoop $ lp)
z

renderSeg :: Segment Closed R2 -> S.Path
renderSeg (Linear (OffsetClosed (unr2 -> (x,0)))) = hr x
Expand Down

0 comments on commit 7ed42dc

Please sign in to comment.