Hi. Beginner here.
https://github.com/lhuanyu/SwiftClipper
I am trying out Swift Clipper and when clipping arrays of CGPoint, I get the error message ClipperError(message: "Error: PolyTree struct is needed for open path clipping.")
Problem is, I cannot instantiate PolyTree class because there is no init() inside of it.
https://github.com/lhuanyu/SwiftClipper/blob/master/Sources/SwiftClipper/PolyNode.swift
Does this mean it is best I copy the whole library source code to my project so I can at least add an init() so I can instantiate it?
This is a simple method I am using to loop through each CGPoint array and union them.
func cb(_ e: [[CGPoint]]) -> [CGPoint] {
var t: [CGPoint] = []
if !e.isEmpty && e.count > 1 {
t = e[0]
var paths = Paths()
let c = Clipper()
for o in (1..<e.count) {
do {
paths.removeAll()
c.clear()
c.addPath(t, .subject, false)
c.addPath(e[o], .subject, false)
try c.execute(clipType: .union, solution: &paths)
t = paths.first ?? []
} catch {
print(error)
}
}
}
return t
}
Thoughts? Is this the only way to instantiate? By copying the source files to my project and add the init constructor there?
Or, is there a hack to forcefully add an init constructor of a lib? (Though I do not think this is possible)