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

DelaunayTriangulation.DivideAndConquer sometimes loops forever/gets stuck #28

Open
patrickt opened this issue Sep 10, 2019 · 9 comments

Comments

@patrickt
Copy link

I’ve been working on a little project that uses hgeometry, and so far I’m loving the library. In using it, however, I’ve found some circumstances where the divide-and-conquer algorithm for Delaunay triangulation loops infinitely, such as when given these points:

Point2 [217.44781269876754,249.24741543498274] :+ 'a'
Point2 [237.91428506927295,105.8082929316906] :+ 'b'
Point2 [51.46936876163245,193.21960885915342] :+ 'c'
Point2 [172.55365082143922,2.8346743864823387] :+ 'd'
Point2 [250.55083565080437,93.13205719006257] :+ ‘e’

To reproduce:

  • git clone [email protected]:patrickt/voronoid.git
  • git checkout a2d95e00f4774b19b03c640442d7c52d3f871c49
  • cabal new-build
  • cabal new-run

Approximately 75% of the time, this will loop infinitely (or at least for a very long time). If it doesn’t, run it a few times.

I ran some profiling tests, and it appears to be stuck in Data.Geometry.Ball.disk. I’m new to the codebase so I wasn’t able to debug any further. For the time being I’m using the Naive module, which is good enough for my purposes, but I figured you’d want a bug report.

voronoid.prof.txt

@patrickt patrickt changed the title DelaunayTriangulation.DivideAndConquer DelaunayTriangulation.DivideAndConquer sometimes loops forever/gets stuck Sep 10, 2019
@noinia
Copy link
Owner

noinia commented Sep 11, 2019

Thanks for the kind words and the report. I'll try to figure out what is happening exactly!

@glittershark
Copy link

glittershark commented Jan 19, 2020

Not sure if we necessarily need other test cases, but just in case it helps this also reproduces the issue:

[ Point2 [38.5,3.5] :+ 0
, Point2 [67.0,33.0] :+ 1
, Point2 [46.0,45.5] :+ 2
, Point2 [55.5,42.0] :+ 3
, Point2 [36.0,25.0] :+ 4
, Point2 [76.5,12.0] :+ 5
, Point2 [29.0,26.5] :+ 6
, Point2 [55.0,10.5] :+ 7
]

@glittershark
Copy link

Actually maybe it would be useful to look at my example, since I've actually seen that hang 100% of the time

glittershark added a commit to glittershark/xanthous that referenced this issue Jan 19, 2020
Per noinia/hgeometry#28, occasionally
DelaunayTriangulation.DivideAndConquer loops infinitely - in this case,
I was able to consistently use the seed 127624940715530481, to generate
a dungeon which had the following room centroids:

    [ Point2 [38.5,3.5] :+ 0
    , Point2 [67.0,33.0] :+ 1
    , Point2 [46.0,45.5] :+ 2
    , Point2 [55.5,42.0] :+ 3
    , Point2 [36.0,25.0] :+ 4
    , Point2 [76.5,12.0] :+ 5
    , Point2 [29.0,26.5] :+ 6
    , Point2 [55.0,10.5] :+ 7
    ]

and cause delaunay triangulation to loop indefinitely (or at least
longer than I cared to wait for). Given the size of our graphs switching
to naive generation should be fine performance-wise, and avoids the
infinite loop.
@noinia
Copy link
Owner

noinia commented Jan 19, 2020

Thanks for reporting the specific testcase! What "real number type" (i.e. type 'r') are you using? If you are using Doubles or Floats you may want to try Rational numbers instead; some of the geometric predicates used don't go that well with floating point numbers (see also the README).

@glittershark
Copy link

they're Doubles.

@glittershark
Copy link

I don't necessarily need the exact right answers in this case - an approximation is fine - though I would like them within a reasonable amount of time 😄

@patrickt
Copy link
Author

Aha, interesting! I’ll try Rational and see if that helps.

@lemmih
Copy link
Collaborator

lemmih commented Aug 5, 2020

@patrickt Did the problem go away when you used Rationals?

@noinia
Copy link
Owner

noinia commented Aug 18, 2020

Just as a heads-up; I've been working on an implementation of an O(n log n) time algorithm to compute the convex hull in R^3 (see hgeometry-devel). That then will also give easy O(n log n) time algorithms for delaunay triangulation and Voronoi diagrams (in R^2). This could then be an alternative to the current implementation.

In trying to deal with all sorts of degeneracies in the 3D CH properly this all has turned into some sort of yak-shaving project.... causing me to implement some stuff on symbolic computation, and reimmplement some geometric primitives. I'm hoping I'm close to the end of the tunnel for that one now though :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants