instancer: fixes addressing Evan's comments

- changed getCoordWidth method to use all if-stmt, ordered by ret value (0, 1, 2).
- added more info to TypeError message in getCoordWidth method.
- in round/scaleDeltas, chained if statements in one line to avoid writing the loop twice.
This commit is contained in:
Cosimo Lupo 2019-06-17 15:18:54 +01:00
parent a45af5d8db
commit d21aa29824
No known key found for this signature in database
GPG Key ID: 20D4A261E4A0E642

View File

@ -451,39 +451,38 @@ class TupleVariation(object):
firstDelta = next((c for c in self.coordinates if c is not None), None) firstDelta = next((c for c in self.coordinates if c is not None), None)
if firstDelta is None: if firstDelta is None:
return 0 # empty or has no impact return 0 # empty or has no impact
if type(firstDelta) in (int, float):
return 1
if type(firstDelta) is tuple and len(firstDelta) == 2: if type(firstDelta) is tuple and len(firstDelta) == 2:
return 2 return 2
elif type(firstDelta) in (int, float): raise TypeError(
return 1 "invalid type of delta; expected (int or float) number, or "
else: "Tuple[number, number]: %r" % firstDelta
raise TypeError("invalid type of delta: %s" % type(firstDelta)) )
def scaleDeltas(self, scalar): def scaleDeltas(self, scalar):
if scalar == 1.0: if scalar == 1.0:
return # no change return # no change
coordWidth = self.getCoordWidth() coordWidth = self.getCoordWidth()
if coordWidth == 2: self.coordinates = [
self.coordinates = [ None
(d[0] * scalar, d[1] * scalar) if d is not None else None if d is None
for d in self.coordinates else d * scalar
] if coordWidth == 1
elif coordWidth == 1: else (d[0] * scalar, d[1] * scalar)
self.coordinates = [ for d in self.coordinates
d * scalar if d is not None else None ]
for d in self.coordinates
]
def roundDeltas(self): def roundDeltas(self):
coordWidth = self.getCoordWidth() coordWidth = self.getCoordWidth()
if coordWidth == 2: self.coordinates = [
self.coordinates = [ None
(otRound(d[0]), otRound(d[1])) if d is not None else None if d is None
for d in self.coordinates else otRound(d)
] if coordWidth == 1
elif coordWidth == 1: else (otRound(d[0]), otRound(d[1]))
self.coordinates = [ for d in self.coordinates
otRound(d) if d is not None else None for d in self.coordinates ]
]
def calcInferredDeltas(self, origCoords, endPts): def calcInferredDeltas(self, origCoords, endPts):
from fontTools.varLib.iup import iup_delta from fontTools.varLib.iup import iup_delta