From 1c9198e3f0c18bb0b8f627102eeb6ba60056cb9c Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 16 May 2017 10:34:37 +0100 Subject: [PATCH] [_g_l_y_f] add test for GlyphCoordinates' float precision loss issue (#964) --- Tests/ttLib/tables/_g_l_y_f_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/ttLib/tables/_g_l_y_f_test.py b/Tests/ttLib/tables/_g_l_y_f_test.py index 7bb300fc6..313a6e919 100644 --- a/Tests/ttLib/tables/_g_l_y_f_test.py +++ b/Tests/ttLib/tables/_g_l_y_f_test.py @@ -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)