Skip to content

Instantly share code, notes, and snippets.

@georgefst
Last active March 12, 2020 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgefst/d4735b27422adbdf7ae3cf1dbd1bb195 to your computer and use it in GitHub Desktop.
Save georgefst/d4735b27422adbdf7ae3cf1dbd1bb195 to your computer and use it in GitHub Desktop.
Diagrams intersection bug

A demonstration of this bug.

The resulting diagram should show all intersection points between an edge and the boundaries of its nodes. As you can see, some are missing. Changing r at line 26 to 7 results in different missed intersections. Most other values of r result in all intersections being found.

vmap and es were originally generated by diagrams-graphviz.

#!/usr/bin/env cabal
{- cabal:
build-depends: base,containers,diagrams-lib,diagrams-svg
-}
module Main where
import Data.Map (Map,(!))
import qualified Data.Map as Map
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
main :: IO ()
main = mainWith graph
graph :: Diagram B
graph = mconcat edgeArrows <> (mconcat nodeTrails # lc blue)
where
nodeTrails = map stroke $ Map.elems nodes
edgeArrows = map (\(v1,v2,p) -> edgeArrow p (nodes ! v1) (nodes ! v2)) es
nodes = node <$> vmap
node :: P2 Double -> Located (Trail V2 Double)
node p = (circle r `at` translate (V2 r 0) p)
where r = 6
edgeArrow :: Located (Trail V2 Double) -> Located (Trail V2 Double) -> Located (Trail V2 Double) -> Diagram B
edgeArrow tr t1 t2 = stroke tr <> mconcat is1 <> mconcat is2
where
is1 = map (\p -> circle 0.7 # moveTo p # lc green) $ intersectPoints tr t1
is2 = map (\p -> circle 1.0 # moveTo p # lc red ) $ intersectPoints tr t2
vmap :: Map Int (Point V2 Double)
vmap =
Map.fromList
[
( 2
, P ( V2 73.0 14.0 )
)
,
( 3
, P ( V2 36.5 14.0 )
)
,
( 1
, P ( V2 0.0 0.0 )
)
]
es :: [(Int, Int, Located (Trail V2 Double))]
es =
[
( 1
, 3
, Trail
( lineFromSegments
[ bézier3 ( V2 1.9888 0.795509 ) ( V2 32.876599999999996 13.150839000000001 ) ( V2 34.8056 13.921839 ) ]
) `at` P ( V2 1.1004 4.0161e-2 )
)
,
( 1
, 2
, Trail
( lineFromSegments
[ bézier3 ( V2 1.197 0.11278329999999999 ) ( V2 20.5887 1.9646333 ) ( V2 35.9417 4.9945333 )
, bézier3 ( V2 15.265 3.012600000000001 ) ( V2 33.801 8.635 ) ( V2 34.944 8.983 )
]
) `at` P ( V2 1.0583 5.4667e-3 )
)
,
( 3
, 3
, Trail
( lineFromSegments
[ bézier3
( V2 ( -8.583000000000002 ) 6.086 )
( V2 ( -8.444000000000003 ) 17.714 ) ( V2 0.41499999999999915 17.714 )
, bézier3 ( V2 8.859000000000002 0.0 )
( V2 8.997999999999998 ( -11.628 ) )
( V2 0.41499999999999915 ( -17.714 ) )
]
) `at` P ( V2 36.085 14.286 )
)
,
( 3
, 2
, Trail
( lineFromSegments
[ bézier3
( V2 1.044000000000004 ( -8.4487 ) )
( V2 33.922999999999995 ( -8.4466 ) ) ( V2 34.949999999999996 5.999999999998451e-3 )
]
) `at` P ( V2 37.025 13.585 )
)
,
( 2
, 3
, Trail
( lineFromSegments
[ bézier3
( V2 ( -1.027000000000001 ) 8.452999999999998 )
( V2 ( -33.90599999999999 ) 8.455 )
( V2 ( -34.949999999999996 ) 5.999999999998451e-3 )
]
) `at` P ( V2 71.975 14.409 )
)
,
( 2
, 2
, Trail
( lineFromSegments
[ bézier3
( V2 ( -8.582999999999998 ) 6.086 )
( V2 ( -8.443999999999988 ) 17.714 ) ( V2 0.41500000000000625 17.714 )
, bézier3 ( V2 8.858999999999995 0.0 )
( V2 8.998000000000005 ( -11.628 ) )
( V2 0.41500000000000625 ( -17.714 ) )
]
) `at` P ( V2 72.585 14.286 )
)
]
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment