ATSketchKit
ATSketchKit copied to clipboard
Fix the problem of recognition when using different device resolution
The unistroke recognition gives different results depending on the device used. It seems related to the resolution.
This is because you are printing out the point coordinates before they are resampled, scaled, rotated, etc... You want the sample array to be the same size as the template and at same scale.
In recognizedPath:
// just before doing the best template loop
self.printTemplateSource(sample)
Added a simplified printout to the same file:
func printTemplateSource(_ points: [CGPoint]) {
var sourceCode = "\nnewTemplate.points = ["
for point in points {
sourceCode += "CGPoint(x:\(point.x), y:\(point.y)),\n"
}
sourceCode += "]"
NSLog("\(sourceCode)")
}
Also, distance function had a bug, here's what it should be:
func distance(_ point1: CGPoint, point2: CGPoint) -> CGFloat {
let deltaX = point2.x - point1.x
let deltaY = point2.y - point1.y
return sqrt(deltaX * deltaX + deltaY * deltaY)
}
Thanks again, do you mind opening a PR?