fix Vector division

This commit is contained in:
justvanrossum 2021-02-03 20:24:04 +01:00
parent 45201f68a6
commit f416a5cb17
2 changed files with 14 additions and 3 deletions

View File

@ -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):

View File

@ -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]