Add @total_ordering to classes with __lt__

This commit is contained in:
Behdad Esfahbod 2013-12-07 03:35:16 -05:00
parent 8ea6439d3b
commit 56da965344
3 changed files with 5 additions and 25 deletions

View File

@ -268,30 +268,6 @@ class Transform(object):
""" """
return self.__affine[index] 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): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __eq__(self, other): def __eq__(self, other):

View File

@ -2,6 +2,7 @@ from __future__ import print_function, division
from fontTools.misc.py23 import * from fontTools.misc.py23 import *
from fontTools.misc.textTools import safeEval, readHex from fontTools.misc.textTools import safeEval, readHex
from . import DefaultTable from . import DefaultTable
from functools import total_ordering
import sys import sys
import struct import struct
import array import array
@ -97,6 +98,7 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
self.tables.append(table) self.tables.append(table)
@total_ordering
class CmapSubtable(object): class CmapSubtable(object):
def __init__(self, format): def __init__(self, format):

View File

@ -3,6 +3,7 @@ from fontTools.misc.py23 import *
from fontTools.misc import sstruct from fontTools.misc import sstruct
from fontTools.misc.textTools import safeEval from fontTools.misc.textTools import safeEval
from . import DefaultTable from . import DefaultTable
from functools import total_ordering
import struct import struct
nameRecordFormat = """ nameRecordFormat = """
@ -88,6 +89,7 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
return None # not found return None # not found
@total_ordering
class NameRecord(object): class NameRecord(object):
def toXML(self, writer, ttFont): def toXML(self, writer, ttFont):