def test_path_normalize03(self): # angle: 180 to 270 d = 'M-100,0 A100,100 0 0 0 0,100' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M-100,0 C-100,55.228 -55.228,100 0,100' self.assertEqual(expected, exp)
def test_triangle01_rel_normalize(self): # See also: triangle01.html d = 'm100,100 l200,0 l-100,200 z' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M100,100 L300,100 200,300 Z' self.assertEqual(expected, d)
def test_cubic01_path01_normalize(self): # See also: cubic01.html d = 'M100,200 C100,100 250,100 250,200 S400,300 400,200' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M100,200 C100,100 250,100 250,200 250,300 400,300 400,200' self.assertEqual(expected, d)
def test_path_normalize04(self): # angle: 270 to 360 d = 'M0,100 A100,100 0 0 0 100,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M0,100 C55.228,100 100,55.228 100,0' self.assertEqual(expected, exp)
def test_cubic02_path06_normalize(self): # See also: cubic02.html d = 'M600,800 C625,700 725,700 750,800 S875,900 900,800' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M600,800 C625,700 725,700 750,800 775,900 875,900 900,800' self.assertEqual(expected, d)
def test_vertical_lineto_rel_normalize(self): path_data = list() path_data.append(SVGPathSegment('m', 50, 50)) path_data.append(SVGPathSegment('v', -50)) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M50,50 L50,0' self.assertEqual(expected, d)
def test_path_normalize05(self): # angle: 0 to 30 d = 'M100,0 A100,100 0 0 0 86.60254037844388,-49.99999999999999' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M100,0 C100,-17.554 95.379,-34.798 86.603,-50' self.assertEqual(expected, exp)
def test_path_normalize02(self): # angle: 90 to 180 d = 'M0,-100 A100,100 0 0 0 -100,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M0,-100 C-55.228,-100 -100,-55.228 -100,0' self.assertEqual(expected, exp)
def test_horizontal_lineto_abs_normalize(self): path_data = list() path_data.append(SVGPathSegment('M', 0, 50)) path_data.append(SVGPathSegment('H', 100)) normalize = PathParser.normalize(path_data) d = PathParser.tostring(normalize) expected = 'M0,50 L100,50' self.assertEqual(expected, d)
def test_horizontal_lineto_rel_normalize(self): path_data = list() path_data.append(SVGPathSegment('m', 100, 50)) path_data.append(SVGPathSegment('h', -100)) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M100,50 L0,50' self.assertEqual(expected, d)
def test_path_normalize09(self): # angle: -30 to 30 d = "M86.60254037844383,50.00000000000004" \ " A100,100 0 0 0 86.60254037844388,-49.99999999999999" path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M86.603,50 C104.466,19.06 104.466,-19.06 86.603,-50' self.assertEqual(expected, exp)
def test_path_normalize08(self): # angle: 240 to 300 d = "M-50.00000000000004,86.60254037844383" \ " A100,100 0 0 0 50.000000000000014,86.60254037844386" path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M-50,86.603 C-19.06,104.466 19.06,104.466 50,86.603' self.assertEqual(expected, exp)
def test_path_normalize07(self): # angle: 150 to 210 d = "M-86.60254037844388,-49.99999999999999" \ " A100,100 0 0 0 -86.60254037844386,50.000000000000014" path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M-86.603,-50 C-104.466,-19.06 -104.466,19.06 -86.603,50' self.assertEqual(expected, exp)
def test_path_normalize06(self): # angle: 60 to 120 d = "M50.000000000000014,-86.60254037844386" \ " A100,100 0 0 0 -49.99999999999998,-86.60254037844388" path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M50,-86.603 C19.06,-104.466 -19.06,-104.466 -50,-86.603' self.assertEqual(expected, exp)
def test_ellipse01_path34_normalize(self): # See also: ellipse01.html d = 'M234.923,34.202 A250,100 0 0 0 176.777,-70.711' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = \ "M234.923,34.202 C253.733,-3.014 248.464,-20.795 176.777,-70.711" self.assertEqual(expected, exp)
def test_arcs02_path02_bearing(self): # See also: arcs02.html # same as 'transform="rotate(90 125 75)"' d = 'M 125,75 B90 a100,50 0 0,1 100,50' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M125,75 C125,130.228 102.614,175 75,175' self.assertEqual(expected, exp)
def test_quad02_path02_bbox(self): # See also: quad02.html d = 'M200,300 Q400,50 600,300 Q800,550 1000,300 Q1200,50 1400,300' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(200, bbox.x, places=places) self.assertAlmostEqual(175, bbox.y, places=places) self.assertAlmostEqual(1200, bbox.width, places=places) self.assertAlmostEqual(250, bbox.height, places=places)
def test_bearing01_normalize(self): # See also: bearing01.html d = 'M150,10 B36 h47 b72 h47 b72 h47 b72 h47 Z' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = \ "M150,10 L188.023799,37.625907 173.5,82.325563 126.5,82.325563" \ " 111.976201,37.625907 Z" self.assertEqual(expected, d)
def test_path_normalize01(self): # cx=0 cy=0 r=100 # large_arc_flag=0, sweep_flag=0 # angle: 0 to 90 d = 'M100,0 A100,100 0 0 0 0,-100' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = 'M100,0 C100,-55.228 55.228,-100 0,-100' self.assertEqual(expected, exp)
def test_ellipse01_path32_normalize(self): # See also: ellipse01.html d = 'M-234.923,-34.202 A250,100 0 0 0 -176.777,70.711' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) exp = PathParser.tostring(normalized) expected = \ "M-234.923,-34.202" \ " C-253.733,3.014 -248.464,20.795 -176.777,70.711" self.assertEqual(expected, exp)
def test_quad02_path03_bbox(self): # See also: quad02.html d = 'm200,300 q200,-250 400,0 t400,0 400,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(200, bbox.x, places=places) self.assertAlmostEqual(175, bbox.y, places=places) self.assertAlmostEqual(1200, bbox.width, places=places) self.assertAlmostEqual(250, bbox.height, places=places)
def test_bearing01_bbox(self): # See also: bearing01.html d = 'M150,10 B36 h47 b72 h47 b72 h47 b72 h47 Z' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(111.976, bbox.x, places=places) self.assertAlmostEqual(10, bbox.y, places=places) self.assertAlmostEqual(76.048, bbox.width, places=places) self.assertAlmostEqual(72.326, bbox.height, places=places)
def test_moveto_rel_normalize(self): path_data = list() path_data.append(SVGPathSegment('m', 100, 100)) path_data.append(SVGPathSegment('m', 50, 0)) path_data.append(SVGPathSegment('m', 0, 50)) path_data.append(SVGPathSegment('z')) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = 'M100,100 150,100 150,150 Z' self.assertEqual(expected, d)
def test_cubic02_01_path02_bbox(self): # See also: cubic02_01.html d = 'm100,500 c-75,-100 375,-100 300,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(91.534, bbox.x, places=places) self.assertAlmostEqual(425, bbox.y, places=places) self.assertAlmostEqual(316.933, bbox.width, places=places) self.assertAlmostEqual(75, bbox.height, places=places)
def test_triangle01_bbox(self): # See also: triangle01.html d = 'M 100 100 L 300 100 L 200 300 z' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(100, bbox.x, places=places) self.assertAlmostEqual(100, bbox.y, places=places) self.assertAlmostEqual(200, bbox.width, places=places) self.assertAlmostEqual(200, bbox.height, places=places)
def test_cubic03_path04_bbox(self): # See also: cubic03.html d = 'm575,200 c20,100 50,100 70,0 20,-100 55,-100 75,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(575, bbox.x, places=places) self.assertAlmostEqual(125, bbox.y, places=places) self.assertAlmostEqual(145, bbox.width, places=places) self.assertAlmostEqual(150, bbox.height, places=places)
def test_cubic02_01_path06_bbox(self): # See also: cubic02_01.html d = 'm600,800 c25,-100 125,-100 150,0 s125,100 150,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(600, bbox.x, places=places) self.assertAlmostEqual(725, bbox.y, places=places) self.assertAlmostEqual(300, bbox.width, places=places) self.assertAlmostEqual(150, bbox.height, places=places)
def test_quad01_path01_normalize(self): # See also: quad01.html d = 'M200,300 Q400,50 600,300 T1000,300' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) d = PathParser.tostring(normalized) expected = "M200,300" \ " C333.333,133.333 466.667,133.333 600,300" \ " 733.333,466.667 866.667,466.667 1000,300" self.assertEqual(expected, d)
def test_cubic02_01_path05_bbox(self): # See also: cubic02_01.html d = 'm600,500 c0,-150 300,150 300,0' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(600, bbox.x, places=places) self.assertAlmostEqual(456.699, bbox.y, places=places) self.assertAlmostEqual(300, bbox.width, places=places) self.assertAlmostEqual(86.603, bbox.height, places=places)
def test_cubic03_path02_bbox(self): # See also: cubic03.html d = 'M175,200 C195,300 225,300 245,200 265,100 300,100 320,200' path_data = PathParser.parse(d) normalized = PathParser.normalize(path_data) bbox = PathParser.get_bbox(normalized) self.assertAlmostEqual(175, bbox.x, places=places) self.assertAlmostEqual(125, bbox.y, places=places) self.assertAlmostEqual(145, bbox.width, places=places) self.assertAlmostEqual(150, bbox.height, places=places)