Add @total_ordering to classes with __lt__
This commit is contained in:
parent
8ea6439d3b
commit
56da965344
@ -268,30 +268,6 @@ class Transform(object):
|
||||
"""
|
||||
return self.__affine[index]
|
||||
|
||||
def __lt__(self, other):
|
||||
"""Transform instances are comparable:
|
||||
>>> t1 = Identity.scale(2, 3).translate(4, 6)
|
||||
>>> t2 = Identity.translate(8, 18).scale(2, 3)
|
||||
>>> t1 == t2
|
||||
1
|
||||
>>>
|
||||
|
||||
But beware of floating point rounding errors:
|
||||
>>> t1 = Identity.scale(0.2, 0.3).translate(0.4, 0.6)
|
||||
>>> t2 = Identity.translate(0.08, 0.18).scale(0.2, 0.3)
|
||||
>>> t1
|
||||
<Transform [0.2 0.0 0.0 0.3 0.08 0.18]>
|
||||
>>> t2
|
||||
<Transform [0.2 0.0 0.0 0.3 0.08 0.18]>
|
||||
>>> t1 == t2
|
||||
0
|
||||
>>>
|
||||
"""
|
||||
xx1, xy1, yx1, yy1, dx1, dy1 = self.__affine
|
||||
xx2, xy2, yx2, yy2, dx2, dy2 = other
|
||||
return (xx1, xy1, yx1, yy1, dx1, dy1) < \
|
||||
(xx2, xy2, yx2, yy2, dx2, dy2)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
def __eq__(self, other):
|
||||
|
@ -2,6 +2,7 @@ from __future__ import print_function, division
|
||||
from fontTools.misc.py23 import *
|
||||
from fontTools.misc.textTools import safeEval, readHex
|
||||
from . import DefaultTable
|
||||
from functools import total_ordering
|
||||
import sys
|
||||
import struct
|
||||
import array
|
||||
@ -97,6 +98,7 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
|
||||
self.tables.append(table)
|
||||
|
||||
|
||||
@total_ordering
|
||||
class CmapSubtable(object):
|
||||
|
||||
def __init__(self, format):
|
||||
|
@ -3,6 +3,7 @@ from fontTools.misc.py23 import *
|
||||
from fontTools.misc import sstruct
|
||||
from fontTools.misc.textTools import safeEval
|
||||
from . import DefaultTable
|
||||
from functools import total_ordering
|
||||
import struct
|
||||
|
||||
nameRecordFormat = """
|
||||
@ -86,8 +87,9 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
|
||||
if langID is None or namerecord.langID == langID:
|
||||
return namerecord
|
||||
return None # not found
|
||||
|
||||
|
||||
|
||||
@total_ordering
|
||||
class NameRecord(object):
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
|
Loading…
x
Reference in New Issue
Block a user