-
Notifications
You must be signed in to change notification settings - Fork 9
Fix bug of polygon calculation for voronoiplots (#234) #235
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
Conversation
|
If you don't mind, can you also check if this fixes #223? |
I had some ideas to try and improve this function but, rather than letting this fix get in the way of me waiting till I might eventually have time to even begin looking into it, this is a great help! I appreciate it. |
|
Alright, I figured as much but might've been a nice side-effect! Can you also add a test for your #234 please? |
Will do the test tomorrow, not sure where to put it. Should I put it as a new testset inside https://github.com/JuliaGeometry/DelaunayTriangulation.jl/blob/main/test/voronoi/voronoi.jl? |
Yeah, there's good. And for https://github.com/JuliaGeometry/DelaunayTriangulation.jl/blob/main/test/interfaces/points.jl would be good. I think these tests are sufficient @testset "allfinite" begin
# All finite points
@test allfinite([[2.0, 3.5], [1.7, 23.3], [-1.0, 0.0]])
@test allfinite([(2.0, 3.5), (1.7, 23.3), (-1.0, 0.0)])
@test allfinite([2.0 1.7 -1.0; 3.5 23.3 0.0])
@test allfinite(((2.0, 3.5), (1.7, 23.3), (-1.0, 0.0)))
# With Inf
@test !allfinite([[2.0, 3.5], [Inf, 23.3], [-1.0, 0.0]])
@test !allfinite([(2.0, 3.5), (Inf, 23.3), (-1.0, 0.0)])
@test !allfinite([2.0 Inf -1.0; 3.5 23.3 0.0])
@test !allfinite(((2.0, 3.5), (Inf, 23.3), (-1.0, 0.0)))
# With NaN
@test !allfinite([[2.0, 3.5], [1.7, NaN], [-1.0, 0.0]])
@test !allfinite([(2.0, 3.5), (1.7, NaN), (-1.0, 0.0)])
@test !allfinite([2.0 1.7 NaN; 3.5 23.3 0.0])
@test !allfinite(((2.0, 3.5), (1.7, NaN), (-1.0, 0.0)))
# With both Inf and NaN
@test !allfinite([[2.0, 3.5], [Inf, 23.3], [NaN, 0.0]])
# Edge cases
@test allfinite(Vector{Vector{Float64}}()) # vacuous truth
@test allfinite(Matrix{Float64}(undef, 2, 0)) # vacuous truth
@test allfinite([[1.0, 2.0]])
@test !allfinite([[Inf, 2.0]])
# First point non-finite
@test !allfinite([[Inf, 1.0], [2.0, 3.0]])
@test !allfinite([[NaN, 1.0], [2.0, 3.0]])
# Last point non-finite
@test !allfinite([[1.0, 2.0], [3.0, 4.0], [5.0, Inf]])
@test !allfinite([[1.0, 2.0], [3.0, 4.0], [NaN, 6.0]])
end |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
+ Coverage 94.81% 94.87% +0.06%
==========================================
Files 102 102
Lines 10356 10370 +14
==========================================
+ Hits 9819 9839 +20
+ Misses 537 531 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Can you test with |
I don't think is the way to go here, as this is failing for n > 4 (regardless of whether I run the code pre- or postfix -- also this is not calling fail for n > 3 prefix, but pass postfix.
I changed the tests, such that they compare the correct polygon coordinates with the polygon coordinates from |
|
Your voronoi call isn't the same as the one that voronoiplot uses (it has some clipping it used when it gets the polygon coordinates, that's the difference you're seeing). I'll try and take a look at it myself soon since that might be a bit simpler. |
|
I'm also happy if you just want to do a reference test. I do that here for example. You just need to add |
Yes, will do. Should I replace the current tests or just keep them?
I think so too 👍
Prior to this patch you just get an error message, but I'll show you the images post patch. |
Just replace the tests with an appropriate reference test, it's fine. Keep the |
|
Thanks! |


This should fix: #234
I added the internal function
_grow_polygon_outside_of_box, which is essentiallygrow_polygon_outside_of_box, but takes a type (e.g.::Float64) as additional input.The original function
grow_polygon_outside_of_boxis now a wrapper for the new internal function. It runs the internal function with::Float64(this should have the same behavior as before) and if this fails (i.e. if it returnsnew_pointswith values that areInf, it runs the internal function again witht,pandqbeing of type::BigFloat.This ensures higher precision and fixed the issue. Creating the wrapper and running the Float64 version first ensures that performance does not decrease from this fix.
I almost entirely copied the docstring of the original function for the internal function. Not sure if you want to keep it like that? Also let me know if you have a better idea of fixing this! :)