replicad icon indicating copy to clipboard operation
replicad copied to clipboard

Error more gracefully in set operations

Open andrewkrippner opened this issue 11 months ago • 1 comments

In general, geometrical errors are very difficult to troubleshoot. Is there a way to throw more informative messages?

In addition, are there better ways to handle the cases where errors are thrown? For instance, I am trying to filter a set of edges together in:

body = body.fillet(0.5, (e) => e.inDirection('Z'))

This is erroring out I assume because some of my edges are already tangent on both sides, so there is no fillet that can be added. I would much prefer if that single edge error was caught and the rest of the operation was allowed to continue.

andrewkrippner avatar Mar 01 '24 05:03 andrewkrippner

I was able to address this with a try-catch in a loop. It doesn't seem the most efficient but this does the job I needed.

export const safeFillet = (
    body: Solid,
    edgeFinder: EdgeFinder,
    radius: number,
) => {
    let newBody = body
    edgeFinder.find(body).forEach((edge) => {
        try {
            newBody = newBody.fillet((r) => {
                if (r.isEqual(edge)) {
                    return radius
                }
                return 0
            })
        } catch {}
    })
    return newBody
}

andrewkrippner avatar Apr 18 '24 15:04 andrewkrippner