JuliaGeometry/Meshes.jl

intersection/clipping not working properly in the 2D case

Closed this issue · 3 comments

CNOT commented

I reported this earlier in issue #728 , however as it seems to be a distinct problem I'm opening a new issue for it. Here's a MWE showing the problem:

using Meshes
using CairoMakie
cg = Meshes.CartesianGrid((0.0, 0.0), (2.0, 1.0), (0.1, 0.1))
ps = Meshes.Point2[(0.0, 0.0), (1.0, 0.5), (1.0, 1.0), (2.0, 0.0)]
pol = Meshes.PolyArea(ps)
viz(pol,showfacets = true)
for i in faces(cg, 2)
    cl = i  pol # Same thing happens with clip(i,pol, SutherlandHodgman())
    if cl != nothing
        viz!(i,showfacets = true, alpha = 0.5, facetcolor = :red)
    end
end
Makie.current_figure()

mwe

The issue was fixed, and a patch release is on its way:

image

The Sutherland-Hodgman algorithm assumes a convex clipping geometry. We have to flip the order of arguments when the clipping geometry is not convex. A more performant and general solution requires an alternative clipping algorithm (e.g. Weiler-Atherton) as discussed in #578

CNOT commented

Great! Is there an expected timeline for the preferred clipping algorithms?