Snap.swift
Snap.swift copied to clipboard
Custom threshold
Allow passing a custom error threshold
Take a look into this https://en.wikipedia.org/wiki/Binary_space_partitioning , http://game-ai.gatech.edu/sites/default/files/documents/assignments/bsp.html
Also having this issue, CoreGraphics seems to render non-deterministic when it comes to anti aliasing, at least I get pixel values off +/- 1 or 2 with the exact same code.
Currently I use a custom compare operation via CIImage that might be a starting point, although it doesn't seem to be particularly fast: https://gist.github.com/ralfebert/4c69b264cd374c91d28ba6b54ab1062f
mmm thanks for the code @ralfebert, I'll take a deeper look into this, seems that it's a little slow but I think we can speed it up a little, I'll try to hack something and come back with the results, thanks again!!
The quickest way seems to be just to compare the bytes manually:
let d1 = referenceImageContext.data!
let d2 = imageContext.data!
for i in 0..<referenceImageSizeBytes {
let b1 = d1.load(fromByteOffset: i, as: UInt8.self)
let b2 = d2.load(fromByteOffset: i, as: UInt8.self)
if b1 != b2 {
let diff = abs(Int(b1) - Int(b2))
if diff > tolerance {
throw CompareError.notEquals
}
}
}
Doesn't seem to be particularly slow...