From 7ed42dc13d215feea39e8d053fa120e75de8192c Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Fri, 17 Jan 2014 11:39:20 -0500 Subject: [PATCH] Don't emit last segment of a loop if it is linear 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. --- src/Graphics/Rendering/SVG.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Graphics/Rendering/SVG.hs b/src/Graphics/Rendering/SVG.hs index 983d002..fffd103 100644 --- a/src/Graphics/Rendering/SVG.hs +++ b/src/Graphics/Rendering/SVG.hs @@ -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