JuliaGeometry / DelaunayTriangulation.jl

Delaunay triangulations and Voronoi tessellations in two dimensions.
https://juliageometry.github.io/DelaunayTriangulation.jl/
MIT License
62 stars 5 forks source link

Invalid `convex_hull` when points are repeated #109

Closed asinghvi17 closed 2 months ago

asinghvi17 commented 4 months ago

Consider the following MWE:

using CairoMakie, DelaunayTriangulation
data = rand(Point2f, 10)
Makie.convert_arguments(::Makie.PointBased, ch::DelaunayTriangulation.ConvexHull) = (Makie.Point.(view(ch.points, ch.vertices)),) # just to make plotting easier

f, a1, p1 = lines(convex_hull(data); axis = (; title = "points")) # this is fine
a2, p2 = lines(f[1, 2], convex_hull(vcat(data, data)); axis = (; title = "vcat(points, points)")) # this is NOT fine

iTerm2 fNCt8V

asinghvi17 commented 4 months ago

For context, I was looking at depending on DelaunayTriangulation.jl in GeometryOps for some triangulation tasks. All geographic polygons must have polygon[begin] == polygon[end], so this comes up quite often when taking the convex hull of a set of polygons.

DanielVandH commented 4 months ago

Hm. I didn't really intend to support duplicate points anywhere - in fact, I thought this function also would throw a DuplicatePointsError like triangulate does. I'm open to supporting it though. Can you check if it works if you add

unique!(i -> get_point(points, i), insertion_order)

in convex_hull! after insertion_order = lexicographic_order(points)?

asinghvi17 commented 4 months ago

Yep, that works! I can perform that check locally, but it would make sense to place that here as well. It could also be controlled by a keyword argument if that's desired for performance.

DanielVandH commented 4 months ago

Probably don't need to bother with a keyword, I don't think it'll slow things down too much. If you're able to, would you mind making a PR with that change in the convex_hull! function? A simple test that convex_hull(points) == convex_hull(vcat(points, points)) (or something like that, not sure if == works on ConvexHull or if I never implemented it yet) would probably suffice.

asinghvi17 commented 4 months ago

Will get a PR up by tomorrow!

DanielVandH commented 2 months ago

Is this something you still need @asinghvi17?

asinghvi17 commented 2 months ago

Yes! Sorry, I lost track of this and forgot to push the PR.

DanielVandH commented 2 months ago

No worries, there's no rush. I just happened to remember about it today so thought I'd check in. Thanks.

DanielVandH commented 2 months ago

Should now be fixed once v1.0.4 is released