From f416a5cb175d40e63ba5e0e482a1d01e25de285f Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Wed, 3 Feb 2021 20:24:04 +0100 Subject: [PATCH] fix Vector division --- Lib/fontTools/misc/arrayTools.py | 4 ++-- Tests/misc/arrayTools_test.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/misc/arrayTools.py b/Lib/fontTools/misc/arrayTools.py index 81b2418dc..e76ced7f8 100644 --- a/Lib/fontTools/misc/arrayTools.py +++ b/Lib/fontTools/misc/arrayTools.py @@ -313,9 +313,9 @@ class Vector(object): __rmul__ = __mul__ def __truediv__(self, other): - return Vector(self._scalarOp(other, operator.div), keep=True) + return Vector(self._scalarOp(other, operator.truediv), keep=True) def __itruediv__(self, other): - self.values = self._scalarOp(other, operator.div) + self.values = self._scalarOp(other, operator.truediv) return self def __pos__(self): diff --git a/Tests/misc/arrayTools_test.py b/Tests/misc/arrayTools_test.py index 127f153c8..73e0ab17e 100644 --- a/Tests/misc/arrayTools_test.py +++ b/Tests/misc/arrayTools_test.py @@ -1,7 +1,7 @@ from fontTools.misc.py23 import * from fontTools.misc.py23 import round3 from fontTools.misc.arrayTools import ( - calcBounds, calcIntBounds, updateBounds, pointInRect, pointsInRect, + Vector, calcBounds, calcIntBounds, updateBounds, pointInRect, pointsInRect, vectorLength, asInt16, normRect, scaleRect, offsetRect, insetRect, sectRect, unionRect, rectCenter, intRect) import math @@ -88,3 +88,14 @@ def test_rectCenter(): def test_intRect(): assert intRect((0.9, 2.9, 3.1, 4.1)) == (0, 2, 4, 5) + + +def test_Vector(): + v = Vector([100, 200]) + assert v == Vector([100, 200]) + assert v == [100, 200] + assert v + Vector([1, 2]) == [101, 202] + assert v - Vector([1, 2]) == [99, 198] + assert v * 2 == [200, 400] + assert v * 0.5 == [50, 100] + assert v / 2 == [50, 100]