Hello! Encountered runtime error "Prelude.maximum: empty list"

18 views
Skip to first unread message

ilmars....@gmail.com

unread,
Feb 23, 2025, 8:03:58 PMFeb 23
to diagrams-discuss
Did I do something wrong? Here is the code (apologies for the mess):

-------------
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}

import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
import qualified Diagrams.TwoD.Path.Boolean as B

vector1, vector2, vector3 :: V2 Double
vector1 = unitX # rotate (tau / 12 @@ rad)
vector2 = unitX # rotate (tau / 12 + tau / 3 @@ rad)
vector3 = unitX # rotate (tau / 12 - tau / 3 @@ rad)

center1, center2, center3 :: P2 Double
center1 = origin .+^ vector1
center2 = origin .+^ vector2
center3 = origin .+^ vector3

border, path1, path2, path3 :: Path V2 Double
border = square 6 # scaleY 1.1
path1 = circle (sqrt 3) # moveTo center1
path2 = circle (sqrt 3) # moveTo center2
path3 = circle (sqrt 3) # moveTo center3

intersectionABC, negationABC, onlyA, onlyB, onlyC, onlyABnotC, onlyACnotB :: Diagram B
intersectionABC = fc green (strokePath (B.intersection Winding (B.intersection Winding path1 path2) path3))
negationABC = fc red (strokePath (B.difference Winding border (B.union Winding (path1 <> path2 <> path3))))
onlyA = fc orange (strokePath (B.difference Winding (reversePath path1) (B.union Winding (path2 <> path3))))
onlyB = fc yellow (strokePath (B.difference Winding path2 (B.union Winding (path1 <> path3))))
onlyC = fc purple (strokePath (B.difference Winding path3 (B.union Winding (path1 <> path2))))
onlyABnotC = fc blue (strokePath (B.difference Winding (B.intersection Winding path1 path2) path3))
onlyACnotB = fc blue (strokePath (B.difference Winding (B.intersection Winding path1 path3) path2))
--- onlyACnotB causes, it seems, the runtime error "Prelude.maximum: empty list"

main = mainWith (negationABC <> intersectionABC <> onlyA <> onlyB <> onlyC <> onlyABnotC <> onlyACnotB)

Brent Yorgey

unread,
Feb 25, 2025, 6:52:45 AMFeb 25
to ilmars....@gmail.com, diagrams-discuss
Hello!  No, you definitely didn't do something wrong.  I played around with it a little bit and it looks like the intersection (B.intersection Winding path1 path3) is empty, but it definitely shouldn't be. Seems like a bug in the path intersection code.  Would you mind creating an issue at https://github.com/diagrams/diagrams-contrib/issues ?

-Brent

--
You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diagrams-discu...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/diagrams-discuss/c5d9ada4-0a5a-4718-8779-19061fc018e5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages