1*e1fe3e4aSElliott Hughesfrom fontTools.pens.areaPen import AreaPen 2*e1fe3e4aSElliott Hughesimport unittest 3*e1fe3e4aSElliott Hughes 4*e1fe3e4aSElliott Hughesprecision = 6 5*e1fe3e4aSElliott Hughes 6*e1fe3e4aSElliott Hughes 7*e1fe3e4aSElliott Hughesdef draw1_(pen): 8*e1fe3e4aSElliott Hughes pen.moveTo((254, 360)) 9*e1fe3e4aSElliott Hughes pen.lineTo((771, 367)) 10*e1fe3e4aSElliott Hughes pen.curveTo((800, 393), (808, 399), (819, 412)) 11*e1fe3e4aSElliott Hughes pen.curveTo((818, 388), (774, 138), (489, 145)) 12*e1fe3e4aSElliott Hughes pen.curveTo((188, 145), (200, 398), (200, 421)) 13*e1fe3e4aSElliott Hughes pen.curveTo((209, 409), (220, 394), (254, 360)) 14*e1fe3e4aSElliott Hughes pen.closePath() 15*e1fe3e4aSElliott Hughes 16*e1fe3e4aSElliott Hughes 17*e1fe3e4aSElliott Hughesdef draw2_(pen): 18*e1fe3e4aSElliott Hughes pen.moveTo((254, 360)) 19*e1fe3e4aSElliott Hughes pen.curveTo((220, 394), (209, 409), (200, 421)) 20*e1fe3e4aSElliott Hughes pen.curveTo((200, 398), (188, 145), (489, 145)) 21*e1fe3e4aSElliott Hughes pen.curveTo((774, 138), (818, 388), (819, 412)) 22*e1fe3e4aSElliott Hughes pen.curveTo((808, 399), (800, 393), (771, 367)) 23*e1fe3e4aSElliott Hughes pen.closePath() 24*e1fe3e4aSElliott Hughes 25*e1fe3e4aSElliott Hughes 26*e1fe3e4aSElliott Hughesdef draw3_(pen): 27*e1fe3e4aSElliott Hughes pen.moveTo((771, 367)) 28*e1fe3e4aSElliott Hughes pen.curveTo((800, 393), (808, 399), (819, 412)) 29*e1fe3e4aSElliott Hughes pen.curveTo((818, 388), (774, 138), (489, 145)) 30*e1fe3e4aSElliott Hughes pen.curveTo((188, 145), (200, 398), (200, 421)) 31*e1fe3e4aSElliott Hughes pen.curveTo((209, 409), (220, 394), (254, 360)) 32*e1fe3e4aSElliott Hughes pen.closePath() 33*e1fe3e4aSElliott Hughes 34*e1fe3e4aSElliott Hughes 35*e1fe3e4aSElliott Hughesdef draw4_(pen): 36*e1fe3e4aSElliott Hughes pen.moveTo((771, 367)) 37*e1fe3e4aSElliott Hughes pen.lineTo((254, 360)) 38*e1fe3e4aSElliott Hughes pen.curveTo((220, 394), (209, 409), (200, 421)) 39*e1fe3e4aSElliott Hughes pen.curveTo((200, 398), (188, 145), (489, 145)) 40*e1fe3e4aSElliott Hughes pen.curveTo((774, 138), (818, 388), (819, 412)) 41*e1fe3e4aSElliott Hughes pen.curveTo((808, 399), (800, 393), (771, 367)) 42*e1fe3e4aSElliott Hughes pen.closePath() 43*e1fe3e4aSElliott Hughes 44*e1fe3e4aSElliott Hughes 45*e1fe3e4aSElliott Hughesdef draw5_(pen): 46*e1fe3e4aSElliott Hughes pen.moveTo((254, 360)) 47*e1fe3e4aSElliott Hughes pen.lineTo((771, 367)) 48*e1fe3e4aSElliott Hughes pen.qCurveTo((793, 386), (802, 394)) 49*e1fe3e4aSElliott Hughes pen.qCurveTo((811, 402), (819, 412)) 50*e1fe3e4aSElliott Hughes pen.qCurveTo((819, 406), (814, 383.5)) 51*e1fe3e4aSElliott Hughes pen.qCurveTo((809, 361), (796, 330.5)) 52*e1fe3e4aSElliott Hughes pen.qCurveTo((783, 300), (760.5, 266.5)) 53*e1fe3e4aSElliott Hughes pen.qCurveTo((738, 233), (701, 205.5)) 54*e1fe3e4aSElliott Hughes pen.qCurveTo((664, 178), (612, 160.5)) 55*e1fe3e4aSElliott Hughes pen.qCurveTo((560, 143), (489, 145)) 56*e1fe3e4aSElliott Hughes pen.qCurveTo((414, 145), (363, 164)) 57*e1fe3e4aSElliott Hughes pen.qCurveTo((312, 183), (280, 211.5)) 58*e1fe3e4aSElliott Hughes pen.qCurveTo((248, 240), (231.5, 274.5)) 59*e1fe3e4aSElliott Hughes pen.qCurveTo((215, 309), (208, 339.5)) 60*e1fe3e4aSElliott Hughes pen.qCurveTo((201, 370), (200.5, 392.5)) 61*e1fe3e4aSElliott Hughes pen.qCurveTo((200, 415), (200, 421)) 62*e1fe3e4aSElliott Hughes pen.qCurveTo((207, 412), (217.5, 399)) 63*e1fe3e4aSElliott Hughes pen.qCurveTo((228, 386), (254, 360)) 64*e1fe3e4aSElliott Hughes pen.closePath() 65*e1fe3e4aSElliott Hughes 66*e1fe3e4aSElliott Hughes 67*e1fe3e4aSElliott Hughesdef draw6_(pen): 68*e1fe3e4aSElliott Hughes pen.moveTo((254, 360)) 69*e1fe3e4aSElliott Hughes pen.qCurveTo((228, 386), (217.5, 399)) 70*e1fe3e4aSElliott Hughes pen.qCurveTo((207, 412), (200, 421)) 71*e1fe3e4aSElliott Hughes pen.qCurveTo((200, 415), (200.5, 392.5)) 72*e1fe3e4aSElliott Hughes pen.qCurveTo((201, 370), (208, 339.5)) 73*e1fe3e4aSElliott Hughes pen.qCurveTo((215, 309), (231.5, 274.5)) 74*e1fe3e4aSElliott Hughes pen.qCurveTo((248, 240), (280, 211.5)) 75*e1fe3e4aSElliott Hughes pen.qCurveTo((312, 183), (363, 164)) 76*e1fe3e4aSElliott Hughes pen.qCurveTo((414, 145), (489, 145)) 77*e1fe3e4aSElliott Hughes pen.qCurveTo((560, 143), (612, 160.5)) 78*e1fe3e4aSElliott Hughes pen.qCurveTo((664, 178), (701, 205.5)) 79*e1fe3e4aSElliott Hughes pen.qCurveTo((738, 233), (760.5, 266.5)) 80*e1fe3e4aSElliott Hughes pen.qCurveTo((783, 300), (796, 330.5)) 81*e1fe3e4aSElliott Hughes pen.qCurveTo((809, 361), (814, 383.5)) 82*e1fe3e4aSElliott Hughes pen.qCurveTo((819, 406), (819, 412)) 83*e1fe3e4aSElliott Hughes pen.qCurveTo((811, 402), (802, 394)) 84*e1fe3e4aSElliott Hughes pen.qCurveTo((793, 386), (771, 367)) 85*e1fe3e4aSElliott Hughes pen.closePath() 86*e1fe3e4aSElliott Hughes 87*e1fe3e4aSElliott Hughes 88*e1fe3e4aSElliott Hughesdef draw7_(pen): 89*e1fe3e4aSElliott Hughes pen.moveTo((771, 367)) 90*e1fe3e4aSElliott Hughes pen.qCurveTo((793, 386), (802, 394)) 91*e1fe3e4aSElliott Hughes pen.qCurveTo((811, 402), (819, 412)) 92*e1fe3e4aSElliott Hughes pen.qCurveTo((819, 406), (814, 383.5)) 93*e1fe3e4aSElliott Hughes pen.qCurveTo((809, 361), (796, 330.5)) 94*e1fe3e4aSElliott Hughes pen.qCurveTo((783, 300), (760.5, 266.5)) 95*e1fe3e4aSElliott Hughes pen.qCurveTo((738, 233), (701, 205.5)) 96*e1fe3e4aSElliott Hughes pen.qCurveTo((664, 178), (612, 160.5)) 97*e1fe3e4aSElliott Hughes pen.qCurveTo((560, 143), (489, 145)) 98*e1fe3e4aSElliott Hughes pen.qCurveTo((414, 145), (363, 164)) 99*e1fe3e4aSElliott Hughes pen.qCurveTo((312, 183), (280, 211.5)) 100*e1fe3e4aSElliott Hughes pen.qCurveTo((248, 240), (231.5, 274.5)) 101*e1fe3e4aSElliott Hughes pen.qCurveTo((215, 309), (208, 339.5)) 102*e1fe3e4aSElliott Hughes pen.qCurveTo((201, 370), (200.5, 392.5)) 103*e1fe3e4aSElliott Hughes pen.qCurveTo((200, 415), (200, 421)) 104*e1fe3e4aSElliott Hughes pen.qCurveTo((207, 412), (217.5, 399)) 105*e1fe3e4aSElliott Hughes pen.qCurveTo((228, 386), (254, 360)) 106*e1fe3e4aSElliott Hughes pen.closePath() 107*e1fe3e4aSElliott Hughes 108*e1fe3e4aSElliott Hughes 109*e1fe3e4aSElliott Hughesdef draw8_(pen): 110*e1fe3e4aSElliott Hughes pen.moveTo((771, 367)) 111*e1fe3e4aSElliott Hughes pen.lineTo((254, 360)) 112*e1fe3e4aSElliott Hughes pen.qCurveTo((228, 386), (217.5, 399)) 113*e1fe3e4aSElliott Hughes pen.qCurveTo((207, 412), (200, 421)) 114*e1fe3e4aSElliott Hughes pen.qCurveTo((200, 415), (200.5, 392.5)) 115*e1fe3e4aSElliott Hughes pen.qCurveTo((201, 370), (208, 339.5)) 116*e1fe3e4aSElliott Hughes pen.qCurveTo((215, 309), (231.5, 274.5)) 117*e1fe3e4aSElliott Hughes pen.qCurveTo((248, 240), (280, 211.5)) 118*e1fe3e4aSElliott Hughes pen.qCurveTo((312, 183), (363, 164)) 119*e1fe3e4aSElliott Hughes pen.qCurveTo((414, 145), (489, 145)) 120*e1fe3e4aSElliott Hughes pen.qCurveTo((560, 143), (612, 160.5)) 121*e1fe3e4aSElliott Hughes pen.qCurveTo((664, 178), (701, 205.5)) 122*e1fe3e4aSElliott Hughes pen.qCurveTo((738, 233), (760.5, 266.5)) 123*e1fe3e4aSElliott Hughes pen.qCurveTo((783, 300), (796, 330.5)) 124*e1fe3e4aSElliott Hughes pen.qCurveTo((809, 361), (814, 383.5)) 125*e1fe3e4aSElliott Hughes pen.qCurveTo((819, 406), (819, 412)) 126*e1fe3e4aSElliott Hughes pen.qCurveTo((811, 402), (802, 394)) 127*e1fe3e4aSElliott Hughes pen.qCurveTo((793, 386), (771, 367)) 128*e1fe3e4aSElliott Hughes pen.closePath() 129*e1fe3e4aSElliott Hughes 130*e1fe3e4aSElliott Hughes 131*e1fe3e4aSElliott Hughesclass AreaPenTest(unittest.TestCase): 132*e1fe3e4aSElliott Hughes def test_PScontour_clockwise_line_first(self): 133*e1fe3e4aSElliott Hughes pen = AreaPen(None) 134*e1fe3e4aSElliott Hughes draw1_(pen) 135*e1fe3e4aSElliott Hughes self.assertEqual(-104561.35, round(pen.value, precision)) 136*e1fe3e4aSElliott Hughes 137*e1fe3e4aSElliott Hughes def test_PScontour_counterclockwise_line_last(self): 138*e1fe3e4aSElliott Hughes pen = AreaPen(None) 139*e1fe3e4aSElliott Hughes draw2_(pen) 140*e1fe3e4aSElliott Hughes self.assertEqual(104561.35, round(pen.value, precision)) 141*e1fe3e4aSElliott Hughes 142*e1fe3e4aSElliott Hughes def test_PScontour_clockwise_line_last(self): 143*e1fe3e4aSElliott Hughes pen = AreaPen(None) 144*e1fe3e4aSElliott Hughes draw3_(pen) 145*e1fe3e4aSElliott Hughes self.assertEqual(-104561.35, round(pen.value, precision)) 146*e1fe3e4aSElliott Hughes 147*e1fe3e4aSElliott Hughes def test_PScontour_counterclockwise_line_first(self): 148*e1fe3e4aSElliott Hughes pen = AreaPen(None) 149*e1fe3e4aSElliott Hughes draw4_(pen) 150*e1fe3e4aSElliott Hughes self.assertEqual(104561.35, round(pen.value, precision)) 151*e1fe3e4aSElliott Hughes 152*e1fe3e4aSElliott Hughes def test_TTcontour_clockwise_line_first(self): 153*e1fe3e4aSElliott Hughes pen = AreaPen(None) 154*e1fe3e4aSElliott Hughes draw5_(pen) 155*e1fe3e4aSElliott Hughes self.assertEqual(-104602.791667, round(pen.value, precision)) 156*e1fe3e4aSElliott Hughes 157*e1fe3e4aSElliott Hughes def test_TTcontour_counterclockwise_line_last(self): 158*e1fe3e4aSElliott Hughes pen = AreaPen(None) 159*e1fe3e4aSElliott Hughes draw6_(pen) 160*e1fe3e4aSElliott Hughes self.assertEqual(104602.791667, round(pen.value, precision)) 161*e1fe3e4aSElliott Hughes 162*e1fe3e4aSElliott Hughes def test_TTcontour_clockwise_line_last(self): 163*e1fe3e4aSElliott Hughes pen = AreaPen(None) 164*e1fe3e4aSElliott Hughes draw7_(pen) 165*e1fe3e4aSElliott Hughes self.assertEqual(-104602.791667, round(pen.value, precision)) 166*e1fe3e4aSElliott Hughes 167*e1fe3e4aSElliott Hughes def test_TTcontour_counterclockwise_line_first(self): 168*e1fe3e4aSElliott Hughes pen = AreaPen(None) 169*e1fe3e4aSElliott Hughes draw8_(pen) 170*e1fe3e4aSElliott Hughes self.assertEqual(104602.791667, round(pen.value, precision)) 171*e1fe3e4aSElliott Hughes 172*e1fe3e4aSElliott Hughes def test_openPaths(self): 173*e1fe3e4aSElliott Hughes pen = AreaPen() 174*e1fe3e4aSElliott Hughes pen.moveTo((0, 0)) 175*e1fe3e4aSElliott Hughes pen.endPath() 176*e1fe3e4aSElliott Hughes self.assertEqual(0, pen.value) 177*e1fe3e4aSElliott Hughes 178*e1fe3e4aSElliott Hughes pen.moveTo((0, 0)) 179*e1fe3e4aSElliott Hughes pen.lineTo((1, 0)) 180*e1fe3e4aSElliott Hughes with self.assertRaises(NotImplementedError): 181*e1fe3e4aSElliott Hughes pen.endPath() 182*e1fe3e4aSElliott Hughes 183*e1fe3e4aSElliott Hughes 184*e1fe3e4aSElliott Hughesif __name__ == "__main__": 185*e1fe3e4aSElliott Hughes import sys 186*e1fe3e4aSElliott Hughes 187*e1fe3e4aSElliott Hughes sys.exit(unittest.main()) 188