Skip to content

Instantly share code, notes, and snippets.

@georgefst
Last active March 12, 2020 19:47
Show Gist options
  • 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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" height="443.1492" stroke-opacity="1" viewBox="0.0 0.0 1000.0 443.14920659942845" font-size="1" width="1000.0000" xmlns:xlink="http://www.w3.org/1999/xlink" stroke="rgb(0,0,0)" version="1.1"><defs></defs><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,255)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 565.5983,209.9128 c 0.0000,-38.6439 -31.3271,-69.9709 -69.9709 -69.9709c -38.6439,-0.0000 -69.9709,31.3271 -69.9709 69.9709c -0.0000,38.6439 31.3271,69.9709 69.9709 69.9709c 38.6439,0.0000 69.9709,-31.3271 69.9709 -69.9709Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,255)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 991.2548,209.9128 c 0.0000,-38.6439 -31.3271,-69.9709 -69.9709 -69.9709c -38.6439,-0.0000 -69.9709,31.3271 -69.9709 69.9709c -0.0000,38.6439 31.3271,69.9709 69.9709 69.9709c 38.6439,0.0000 69.9709,-31.3271 69.9709 -69.9709Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,255)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 139.9419,373.1783 c 0.0000,-38.6439 -31.3271,-69.9709 -69.9709 -69.9709c -38.6439,-0.0000 -69.9709,31.3271 -69.9709 69.9709c -0.0000,38.6439 31.3271,69.9709 69.9709 69.9709c 38.6439,0.0000 69.9709,-31.3271 69.9709 -69.9709Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 983.2654,161.2932 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 882.6260,161.2932 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 979.7669,161.2932 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 879.1274,161.2932 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 916.4442,206.5775 c -100.0934,-70.9738 -98.4724,-206.5775 4.8397 -206.5775c 103.3121,-0.0000 104.9331,135.6037 4.8397 206.5775"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 555.7543,159.4442 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 879.0420,161.3817 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 909.3305,205.1431 c -11.9767,-98.5774 -395.4057,-98.6007 -407.5807 -0.0700"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 882.5393,258.4425 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 552.2569,260.3803 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 501.7499,214.7524 c 12.1749,98.5272 395.6040,98.5027 407.5807 -0.0700"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 557.6089,161.2932 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 456.9695,161.2932 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 554.1104,161.2932 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 453.4710,161.2932 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 490.7877,206.5775 c -100.0934,-70.9738 -98.4724,-206.5775 4.8397 -206.5775c 103.3121,-0.0000 104.9331,135.6037 4.8397 206.5775"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(255,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 864.9677,226.5620 c 0.0000,-6.4406 -5.2212,-11.6618 -11.6618 -11.6618c -6.4406,-0.0000 -11.6618,5.2212 -11.6618 11.6618c -0.0000,6.4406 5.2212,11.6618 11.6618 11.6618c 6.4406,0.0000 11.6618,-5.2212 11.6618 -11.6618Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,128,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 147.8556,367.2274 c 0.0000,-4.5085 -3.6548,-8.1633 -8.1633 -8.1633c -4.5085,-0.0000 -8.1633,3.6548 -8.1633 8.1633c -0.0000,4.5085 3.6548,8.1633 8.1633 8.1633c 4.5085,0.0000 8.1633,-3.6548 8.1633 -8.1633Z"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 82.3126,373.1145 c 13.9592,-1.3153 240.1017,-22.9112 419.1457 -58.2454c 178.0177,-35.1324 394.1812,-100.6998 407.5107 -104.7581"/></g><g stroke-linejoin="miter" stroke-opacity="1.0" fill-opacity="0.0" stroke="rgb(0,0,0)" stroke-width="2.6627781179795766" fill="rgb(0,0,0)" stroke-linecap="butt" stroke-miterlimit="10.0"><path d="M 82.8036,372.7099 c 23.1930,-9.2771 383.4010,-153.3627 405.8967 -162.3540"/></g></svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment