[_g_l_y_f] add test for GlyphCoordinates' float precision loss issue (#964)

This commit is contained in:
Cosimo Lupo 2017-05-16 10:34:37 +01:00
parent 4fd719159a
commit 1c9198e3f0
No known key found for this signature in database
GPG Key ID: B61AAAD0B53A6419

View File

@ -143,3 +143,13 @@ class GlyphCoordinatesTest(object):
assert bool(g) == True
g = GlyphCoordinates([(0,.5), (0,0)])
assert bool(g) == True
def test_double_precision_float(self):
# https://github.com/fonttools/fonttools/issues/963
afloat = 242.50000000000003
g = GlyphCoordinates([(afloat, 0)])
g.toInt()
# this would return 242 if the internal array.array typecode is 'f',
# since the Python float is truncated to a C float.
# when using typecode 'd' it should return the correct value 243
assert g[0][0] == round(afloat)