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