1from fontTools.misc.arrayTools import ( 2 calcBounds, calcIntBounds, updateBounds, pointInRect, pointsInRect, 3 vectorLength, asInt16, normRect, scaleRect, offsetRect, insetRect, 4 sectRect, unionRect, rectCenter, intRect) 5import math 6 7 8def test_calcBounds(): 9 assert calcBounds([]) == (0, 0, 0, 0) 10 assert calcBounds( 11 [(0, 40), (0, 100), (50, 50), (80, 10)]) == (0, 10, 80, 100) 12 13 14def test_calcIntBounds(): 15 assert calcIntBounds( 16 [(0.1, 40.1), (0.1, 100.1), (49.9, 49.9), (78.5, 9.5)] 17 ) == (0, 10, 79, 100) 18 19 assert calcIntBounds( 20 [(0.1, 40.1), (0.1, 100.1), (49.9, 49.9), (78.5, 9.5)], 21 round=round 22 ) == (0, 10, 78, 100) 23 24 25def test_updateBounds(): 26 assert updateBounds((0, 0, 0, 0), (100, 100)) == (0, 0, 100, 100) 27 28 29def test_pointInRect(): 30 assert pointInRect((50, 50), (0, 0, 100, 100)) 31 assert pointInRect((0, 0), (0, 0, 100, 100)) 32 assert pointInRect((100, 100), (0, 0, 100, 100)) 33 assert not pointInRect((101, 100), (0, 0, 100, 100)) 34 35 36def test_pointsInRect(): 37 assert pointsInRect([], (0, 0, 100, 100)) == [] 38 assert pointsInRect( 39 [(50, 50), (0, 0), (100, 100), (101, 100)], 40 (0, 0, 100, 100)) == [True, True, True, False] 41 42 43def test_vectorLength(): 44 assert vectorLength((1, 1)) == math.sqrt(2) 45 46 47def test_asInt16(): 48 assert asInt16([0, 0.1, 0.5, 0.9]) == [0, 0, 1, 1] 49 50 51def test_normRect(): 52 assert normRect((0, 10, 100, 200)) == (0, 10, 100, 200) 53 assert normRect((100, 200, 0, 10)) == (0, 10, 100, 200) 54 55 56def test_scaleRect(): 57 assert scaleRect((10, 20, 50, 150), 1.5, 2) == (15.0, 40, 75.0, 300) 58 59 60def test_offsetRect(): 61 assert offsetRect((10, 20, 30, 40), 5, 6) == (15, 26, 35, 46) 62 63 64def test_insetRect(): 65 assert insetRect((10, 20, 50, 60), 5, 10) == (15, 30, 45, 50) 66 assert insetRect((10, 20, 50, 60), -5, -10) == (5, 10, 55, 70) 67 68 69def test_sectRect(): 70 intersects, rect = sectRect((0, 10, 20, 30), (0, 40, 20, 50)) 71 assert not intersects 72 73 intersects, rect = sectRect((0, 10, 20, 30), (5, 20, 35, 50)) 74 assert intersects 75 assert rect == (5, 20, 20, 30) 76 77 78def test_unionRect(): 79 assert unionRect((0, 10, 20, 30), (0, 40, 20, 50)) == (0, 10, 20, 50) 80 81 82def test_rectCenter(): 83 assert rectCenter((0, 0, 100, 200)) == (50.0, 100.0) 84 assert rectCenter((0, 0, 100, 199.0)) == (50.0, 99.5) 85 86 87def test_intRect(): 88 assert intRect((0.9, 2.9, 3.1, 4.1)) == (0, 2, 4, 5) 89