Embroidermodder / libembroidery

Library for reading/writing/manipulating machine and design embroidery files
https://www.libembroidery.org
zlib License
47 stars 14 forks source link

Error Compounding In Most Writers. #125

Closed tatarize closed 2 years ago

tatarize commented 6 years ago
while(stitches)
    {
        dx = stitches->stitch.xx * 10.0 - xx;
        dy = stitches->stitch.yy * 10.0 - yy;
        xx = stitches->stitch.xx * 10.0;
        yy = stitches->stitch.yy * 10.0;
        flags = stitches->stitch.flags;
        jefEncode(b, (char)roundDouble(dx), (char)roundDouble(dy), flags);
...

This mechanism doesn't work. The error is introduced during the rounding of the dx, dy and that isn't tracked. The values of xx, yy, need to be the needle position given the summation of the actual dx, dy values given.

It needs to have the value of xx, yy the sum of the dx, dy values. And to round at the calculation of dx, dy.

tatarize commented 6 years ago

For an extreme example, suppose you stitch 10000 times, each time you move +.333, +.333. It's not enough to move the needle a tenth of a millimeter so it should stitch 3 times in the same spot, then move over and down a tenth of a millimeter, and then stitch there three times. However, it actually stitches 10000 times in the same spot. It should have gone 30 millimeters, it went 0.

tatarize commented 6 years ago
        while(stitches) {
            x = stitches->stitch.xx * 10.0;
            y - stitches->stitch.yy * 10.0;
            dx = roundDouble(x - xx); //Or whatever rounding ops are needed.
            dy = roundDouble(y - yy);
            xx += dx;
            yy += dy;
            flags = stitches->stitch.flags;
            blahEncode(b, (char)dx, (char)dy, flags);

This mechanism would fix it. Do the conversion from global to local, find the change, do the rounding. Then implement xx, yy as the sum of the rounded values. You also don't need to keep converting from mm to tenths.

tatarize commented 6 years ago

See, inkstitch/inkstitch#231 for discussions of the bugs in the wild. With the exception of .dst it will affect most of the writers. Exp, Jef, Hus at a minimum.

robin-swift commented 2 years ago

fixed in commit e5d5f1f59ce