Fix off-by-one errors in the "FreeText must move several annotations" integration test

The x/y-coordinates are floats instead of integers like one might
expect. The current approach rounds both the old and the new
coordinates in order to do integer comparison. However, rounding each
coordinate individually causes too much loss of precision because,
depending on the decimal value, they are either rounded up or down
which causes intermittent off-by-one errors.

This commit fixes the problem by comparing coordinate differences
instead of the coordinates themselves. The precision loss is avoided
by subtracting the old from the new coordinate as-is and only rounding
the final result.
This commit is contained in:
Tim van der Meij 2023-09-17 14:54:46 +02:00
parent e37e7b6f39
commit 306cca930f
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -2254,12 +2254,12 @@ describe("FreeText Editor", () => {
return { x, y };
});
const oldPos = allPositions[i];
expect(Math.round(pos.x))
expect(Math.round(pos.x - oldPos.x))
.withContext(`In ${browserName}`)
.toEqual(Math.round(oldPos.x + 39));
expect(Math.round(pos.y))
.toEqual(39);
expect(Math.round(pos.y - oldPos.y))
.withContext(`In ${browserName}`)
.toEqual(Math.round(oldPos.y + 74));
.toEqual(74);
}
})
);