Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample :: _ -> _ -> Crossings producing incorrect result #337

Open
bacchanalia opened this issue Apr 8, 2019 · 1 comment
Open

sample :: _ -> _ -> Crossings producing incorrect result #337

bacchanalia opened this issue Apr 8, 2019 · 1 comment

Comments

@bacchanalia
Copy link

l1/r1 are equivalent to l0/r0 except the straight segments get converted to cubic segments by B.union. They draw and fill correctly, so I think it's a problem with (sample :: _ -> _ -> Crossings) rather than a problem with B.union.

import Diagrams.Prelude
import qualified Diagrams.TwoD.Path.Boolean as B

l0, r0 :: Located (Trail V2 Double)
l0 = square 1
r0 = square 1 # translateX 2
[l1, r1] = pathTrails $ B.union Winding $ toPath [l0,r0]

main = do
  putStrLn $ "r0/l0: " ++ show (sample r0 (atStart l0)) -- Expected: 0, Actual:  0
  putStrLn $ "r1/l0: " ++ show (sample r1 (atStart l1)) -- Expected: 0, Actual: -1
@bacchanalia
Copy link
Author

bacchanalia commented Apr 8, 2019

One problem is that filter (liftA2 (&&) (>=0) (<=1)) in trailCrossings from Diagrams.TwoD.Path should be filter (liftA2 (&&) (>=(-eps)) (<=(1+eps)), but there is still another problem because given

[p] = pathTrails $ B.union Winding (square 2)
crossingYIsMinus1 = trailCrossings (p2 (-2, -1)) p
crossingYIsPlus1  = trailCrossings (p2 (-2,  1)) p

crossingYIsMinus1 now produces the expected result, but crossingYIsPlus1 still does not.

edit: The param is also compared to 0 or 1 in signFromDerivAt. Loosening those comparisons fixes the example, but might possibly break other things. It requires further consideration.

bacchanalia pushed a commit to bacchanalia/diagrams-lib that referenced this issue Apr 8, 2019
This is an attempted fix for issue diagrams#337. While it gets rid of some
instances where test falsely returns a zero value, it is possible it may
introduce some instances where test falsely returns a non-zero value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant