def runTest(self): subpath = geom.Subpath() subpath.AddSegment(('L', (0.0, 0.0), (3.0, 0.0))) subpath.AddSegment(('L', (3.0, 0.0), (3.0, 5.0))) subpath.AddSegment( ('B', (3.0, 5.0), (0.0, 5.0), (2.0, 6.0), (1.0, 6.0))) subpath.closed = True opt = art2polyarea.ConvertOptions() pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.points.pos, [(0.0, 0.0), (3.0, 0.0), (3.0, 5.0), (1.5, 5.75), (0.0, 5.0)]) self.assertEqual(pa.poly, [0, 1, 2, 3, 4]) subpath = geom.Subpath() subpath.AddSegment(('L', (0.0, 0.0), (1.0, 0.0))) opt = art2polyarea.ConvertOptions() opt.smoothness = 0 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.poly, []) subpath = _MakePolySubpath([(0.0, 0.0), (0.000001, 0.0), (1.0, 0.0), (2.0, 2.0), (2.0, 2.0004), (3.0, 5.0), (0.0, -0.00003)]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(pa.points.pos, [(0.0, 0.0), (1.0, 0.0), (2.0, 2.0), (3.0, 5.0)]) self.assertEqual(pa.poly, [0, 1, 2, 3])
def runTest(self): subpath = geom.Subpath() m = 0.551784 # magic number for circle approx by 4 beziers subpath.AddSegment( ('B', (0.0, 0.0), (1.0, 1.0), (m, 0.0), (1.0, 1.0 - m))) subpath.AddSegment( ('B', (1.0, 1.0), (0.0, 2.0), (1.0, 1.0 + m), (m, 2.0))) subpath.AddSegment(('L', (0.0, 2.0), (0.0, 0.0))) subpath.closed = True path = geom.Path() path.AddSubpath(subpath) opt = art2polyarea.ConvertOptions() opt.subdiv_kind = "EVEN" opt.smoothness = 0 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 10) opt.smoothness = 1 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 18) opt.smoothness = 2 art2polyarea._SetEvenLength(opt, [path]) pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 26)
def runTest(self): subpath = geom.Subpath() m = 0.551784 # magic number for circle approx by 4 beziers subpath.AddSegment( ('B', (0.0, 0.0), (1.0, 1.0), (m, 0.0), (1.0, 1.0 - m))) subpath.AddSegment( ('B', (1.0, 1.0), (0.0, 2.0), (1.0, 1.0 + m), (m, 2.0))) subpath.AddSegment( ('B', (0.0, 2.0), (-1.0, 1.0), (-m, 2.0), (-1.0, 1.0 + m))) subpath.AddSegment( ('B', (-1.0, 1.0), (0.0, 0.0), (-1.0, 1.0 - m), (-m, 0.0))) subpath.closed = True opt = art2polyarea.ConvertOptions() opt.subdiv_kind = "ADAPTIVE" opt.smoothness = 0 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 4) opt.smoothness = 1 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 8) opt.smoothness = 2 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 16) opt.smoothness = 3 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 32) opt.smoothness = 4 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 64) opt.smoothness = 5 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 128) opt.smoothness = 6 pa = art2polyarea._SubpathToPolyArea(subpath, opt, geom.Points()) self.assertEqual(len(pa.poly), 128)
def runTest(self): art = vecfile.ParseVecFile("testfiles/colors.ai") if SHOW: opt = art2polyarea.ConvertOptions() pareas = art2polyarea.ArtToPolyAreas(art, opt) for pa in pareas.polyareas: showfaces.ShowPolyArea(pa, "colors.pdf")
def ParseOneAI(self, f): art = vecfile.ParseAIEPSFile("testfiles/" + f) if SHOW: opt = art2polyarea.ConvertOptions() pareas = art2polyarea.ArtToPolyAreas(art, opt) for pa in pareas.polyareas: showfaces.ShowPolyArea(pa, f)
def ParseOneSVG(self, f): art = svg.ParseSVGFile("testfiles/" + f) if SHOW: opt = art2polyarea.ConvertOptions() opt.filled_only = False opt.smoothness = 3 pareas = art2polyarea.ArtToPolyAreas(art, opt) for pa in pareas.polyareas: showfaces.ShowPolyArea(pa, f)
def runTest(self): art = geom.Art() cps = [(0.0, 0.0), (1.0, 1.0), (2.0, 3.0), (3.0, 0.0)] opt = art2polyarea.ConvertOptions() opt.smoothness = 0 ans = art2polyarea.Bezier3Approx(cps, opt) self.assertEqual(ans, [cps[0], cps[3]]) opt.smoothness = 1 ans = art2polyarea.Bezier3Approx(cps, opt) self.assertEqual(len(ans), 3) self.assertAlmostEqual(ans[1][0], 1.5) self.assertAlmostEqual(ans[1][1], 1.5) opt.smoothness = 2 ans = art2polyarea.Bezier3Approx(cps, opt) self.assertEqual(len(ans), 5) self.assertAlmostEqual(ans[1][0], 0.75) self.assertAlmostEqual(ans[1][1], 0.84375)
def runTest(self): art = geom.Art() # path1 - filled with white, so won't appear path1 = geom.Path() path1.AddSubpath(_MakePolySubpath([(1.0, 1.0), (2.0, 1.0), (3.0, 1.0)])) path1.filled = True path1.fillpaint = geom.white_paint # path2 - not filled, so won't appear path2 = geom.Path() path2.AddSubpath(_MakePolySubpath([(0.0, 1.0), (3.0, 1.0), (3.0, 1.0)])) path2.filled = False # path3 - square with triangle hole path3 = geom.Path() path3.AddSubpath( _MakePolySubpath([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)])) path3.AddSubpath(_MakePolySubpath([(.2, .2), (.1, .6), (.4, .2)])) path3.filled = True path3.fillpaint = geom.Paint(1.0, 0.0, 0.0) # red # path 4 - rectangle - covers path3, but shouldn't combine with it path4 = geom.Path() path4.AddSubpath( _MakePolySubpath([(-1.0, -1.0), (5.0, -1.0), (5.0, 2.0), (-1.0, 2.0)])) path4.filled = True path4.fillpaint = geom.Paint(0.0, 1.0, 0.0) # green art.paths = [path1, path2, path3, path4] opt = art2polyarea.ConvertOptions() opt.smoothness = 0 pas = art2polyarea.ArtToPolyAreas(art, opt) self.assertEqual(len(pas.polyareas), 2) self.assertEqual(pas.points.pos, [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.2, 0.2), (0.1, 0.6), (0.4, 0.2), (-1.0, -1.0), (5.0, -1.0), (5.0, 2.0), (-1.0, 2.0)]) self.assertEqual(pas.polyareas[0].poly, [0, 1, 2, 3]) self.assertEqual(pas.polyareas[0].holes, [[4, 5, 6]]) self.assertEqual(pas.polyareas[0].data, (1.0, 0.0, 0.0)) self.assertEqual(pas.polyareas[1].poly, [7, 8, 9, 10]) self.assertEqual(pas.polyareas[1].holes, []) self.assertEqual(pas.polyareas[1].data, (0.0, 1.0, 0.0))