Closed swt30 closed 7 years ago
May be related to https://github.com/JuliaLang/julia/issues/17170
Actually I think it's https://github.com/JuliaLang/julia/issues/17908 because there are continue statements in these tests.
The PR fixes the 0.4 issues, but I have some tests returning different results or hanging on julia 0.5. This example causes my machine to hang on julia 0.5 but not julia 0.4:
using VoronoiDelaunay
function test()
tess = DelaunayTessellation()
push!(tess, Point(min_coord, min_coord))
push!(tess, Point(1.33, min_coord))
push!(tess, Point(1.66, max_coord))
push!(tess, Point(max_coord, max_coord))
end
test()
OK, it's because there's something in julia 0.5 which is resulting in incorrect triangulations. Here's random points added to a tessellation. v0.4 does not have this issue. Wonder what it could be?
If you would like to reproduce this, try running the following on julia 0.4 and 0.5. On 0.4 everything is fine; on 0.5 it will botch the triangulation and then hang after a few points.
using Plots
pyplot(show=true)
using VoronoiDelaunay
"Recipe to plot a Delaunay mesh"
@recipe function plot(tess::DelaunayTessellation2D)
seriestype := :path
legend := false
markershape := :circle
markersize := 3
grid := false
xlims := (1, 2)
ylims := (1, 2)
x, y = getplotxy(delaunayedges(tess))
end
"Generate a random point in the domain"
function Base.rand(::Type{Point2D})
x = min_coord + (max_coord - min_coord) * rand()
y = min_coord + (max_coord - min_coord) * rand()
Point2D(x, y)
end
function main()
# make the points that we are going to triangulate
srand(99)
N = 20
points = [rand(Point2D) for i=1:N]
# triangulate
tess = DelaunayTessellation(N)
for p in points
push!(tess, p)
plot(tess)
sleep(0.2)
end
end
main()
This is a very elusive bug. I have pinned it down to deep within the behaviour of push!
, more specifically in the _flip
functions. Some triangles are ending up with coincident points once _restoredelaunayhood!
is called, and this is ruining the tessellation. However, when I enter the method with the Gallium debugger, I get different results, which is confusing me to no end.
The problem turned out to be in lines like this:
setabc(ot2, geta(ot1), old_ot1_geom_b, geta(ot2))
It looks like there was some kind of weird inlining behaviour where geta(ot2)
was not evaluated first like you might expect, but instead was evaluated after ot2._a
had already changed. This caused the a and c points to become the same for some triangles. I worked around this by doing geta(ot2)
on the previous line instead.
I assume the behaviour disappeared when running the debugger because it disabled inlining or somehow changed the order of evaluation.
closed by mistake
ahh sorry. Its good that I closed it
I am getting test errors like this on 0.4:
and test failures like this on 0.5 (won't run on Travis until a new version of GeometricalPredicates is tagged):
This may be different manifestations of some kind of scoping bug in
@testset
s, given that the only change was that I wrapped the entire set of tests in@testset begin ... end
. I'm looking into it.