JuliaGeometry / Triangulate.jl

Julia Wrapper for the Triangle Mesh Generator
MIT License
38 stars 11 forks source link

Make segmentmarkerlist optional #3

Closed rschwarz closed 4 years ago

rschwarz commented 4 years ago

In the docstring for TriangulateIO, it says:

    """
    An array of segment markers. Optional on input. If not set then
    segment markers on output default to zero.
    """
    segmentmarkerlist :: Array{Cint,1}

So I thought that I could supply only segmentlist, without segmentmarkerlist. But this actually fails when converting to CTriangulateIO.

I've added a (failing) test, and tried to change the behavior, to match the documentation. But it's still failing and I'm not sure how, because the test output only tells me that there was an ERROR.

I guess this managing of default values would be easiest to implement in an external constructor, but the TriangulateIO struct is explictly mutable, so it's difficult to check the invariant (if segmentlist is given, segmentmarkerlist must also be given).

rschwarz commented 4 years ago

Turns out that it was failing because I passed the wrong flags to Triange (no convex hull segments).

j-fu commented 4 years ago

Hi, thanks! I am just checking: it is sufficient to do

 ctio.numberofsegments=size(tio.segmentlist,2)
    if ctio.numberofsegments>0
        ctio.segmentlist=pointer(tio.segmentlist)
        if size(tio.segmentmarkerlist,1)>0
            @assert size(tio.segmentmarkerlist,1)==ctio.numberofsegments
            ctio.segmentmarkerlist=pointer(tio.segmentmarkerlist)
        end
    end

as triangle itself handles the case of missing markers (and I want to stay as close to it as possible).

If you don't want to modify your pull request I could modify this, preferably with together with another example.

rschwarz commented 4 years ago

Yes, that also works, and I pushed it now.

That's the change I tried initially, but the tests failed and I did not immediatly figure out how to get more output from the tests.