clipper-lib
clipper-lib copied to clipboard
Execute breaks closed shapes
i'm using two functions to cut close or open shapes
// this one opens curve all the time, so i have to close it manually
const boolean_area = (type, path_a, path_b) => {
// to make sure that the path is closed (just copying the first point and appending at the end)
close_paths(path_a)
close_paths(path_b)
const {Clipper, PolyType, Paths, ClipType} = clipper_lib
const result = new Paths()
const params = Clipper.ioPreserveCollinear | Clipper.ioStrictlySimple
const clipper = new Clipper(params)
clipper.AddPaths(path_a, PolyType.ptSubject, true)
clipper.AddPaths(path_b, PolyType.ptClip, true)
clipper.Execute(ClipType[type], result)
close_paths(result)
return result
}
// this one breaks the subject curve at random places and i can't fix it easily
const boolean_line = (type, subject, clip) => {
const {JS, Clipper, ClipType, PolyTree, PolyType} = clipper_lib
const cleaned = JS.Lighten(subject, 0.01 * scale)
const result = new PolyTree()
const params = Clipper.ioPreserveCollinear | Clipper.ioStrictlySimple
const clipper = new Clipper(params)
clipper.AddPaths(cleaned, PolyType.ptSubject, false)
clipper.AddPaths(clip, PolyType.ptClip, true)
clipper.Execute(ClipType[type], result)
return Clipper.PolyTreeToPaths(result)
}
// this breaks the line at random locations too
const b = Clipper.SimplifyPolygons(a, PolyFillType.pftEvenOdd)
i'm using scale factor 4 and they both producing open paths at some random locations "clipper-lib": "^6.4.2",
Hello? Anybody alive here?