Hi!
I'm using Skia PathOps to process paths. Most of the times, it works just great, but I have noticed that sometimes the result is not what I expect.
I watched the excellent video about the PathOps [1], and according to that there are cases where floating point inaccuracy can give wrong results. I wonder if that is the case here or is this something that the algorithms should be able to handle?
Also, are there any ways to avoid these kind of errors? Can the paths be preprocessed somehow to prevent this?
Here are my paths and the result for kDifference_PathOp. I was expecting to get one subpath, but instead I get two. Also, I didn't expect the positive y points of the path1 to be clipped away (37.7109375, 1.3515625 and 37.203125, 0.9609375). I also get wrong results for a union, intersection and XOR with these paths. I'm running this on 64-bit Mac OS X with SkScalar defined as 32-bit float.
SkPath path1;
path1.moveTo(39.9375, -5.8359375);
path1.lineTo(40.625, -5.7890625);
path1.lineTo(37.7109375, 1.3515625);
path1.lineTo(37.203125, 0.9609375);
path1.close();
SkPath path2;
path2.moveTo(37.52734375, -1.44140625);
path2.cubicTo(37.8736991882324, -1.69921875, 38.1640625, -2.140625, 38.3984375, -2.765625);
path2.lineTo(38.640625, -2.609375);
path2.cubicTo(38.53125, -1.89583337306976, 38.0664443969727, -0.154893040657043, 38.0664443969727, -0.154893040657043);
path2.cubicTo(38.0664443969727, -0.154893040657043, 37.1809883117676, -1.18359375, 37.52734375, -1.44140625);
path2.close();
SkPath result;
Op(path1, path2, kDifference_PathOp, &result);
-- The result:
M 38.6537, -2.64481
L 38.6537, -2.64481 ; 39.9375, -5.83594
L 39.9375, -5.83594 ; 40.625, -5.78906
L 40.625, -5.78906 ; 39.3321, -2.62091
C 39.3321, -2.62091 ; 39.3353, -2.62884 ; 38.6505, -2.63681 ; 38.6537, -2.64481
Close back to 38.6537, -2.64481
M 38.6397, -2.60997
L 38.6397, -2.60997 ; 37.7943, -0.508542
C 37.7943, -0.508542 ; 37.9357, -0.306823 ; 38.0664, -0.154893 ; 38.0664, -0.154893
C 38.0664, -0.154893 ; 38.0664, -0.154893 ; 38.5312, -1.89583 ; 38.6406, -2.60938
L 38.6406, -2.60938 ; 38.6397, -2.60997
Close back to 38.6397, -2.60997
BR,
Kari