Code

Translations. POTFILES.in cleanup and inkscape.pot update.
[inkscape.git] / share / extensions / cspsubdiv.py
1 #!/usr/bin/env python
2 from bezmisc import *
3 from ffgeom import *
5 def maxdist(((p0x,p0y),(p1x,p1y),(p2x,p2y),(p3x,p3y))):
6     p0 = Point(p0x,p0y)
7     p1 = Point(p1x,p1y)
8     p2 = Point(p2x,p2y)
9     p3 = Point(p3x,p3y)
11     s1 = Segment(p0,p3)
12     return max(s1.distanceToPoint(p1),s1.distanceToPoint(p2))
13     
15 def cspsubdiv(csp,flat):
16     for sp in csp:
17         subdiv(sp,flat)
19 def subdiv(sp,flat,i=1):
20     p0 = sp[i-1][1]
21     p1 = sp[i-1][2]
22     p2 = sp[i][0]
23     p3 = sp[i][1]
24     
25     b = (p0,p1,p2,p3)
26     m = maxdist(b)
27     if m <= flat:
28         try:
29             subdiv(sp,flat,i+1)
30         except IndexError:
31             pass
32     else:
33         one, two = beziersplitatt(b,0.5)
34         sp[i-1][2] = one[1]
35         sp[i][0] = two[2]
36         p = [one[2],one[3],two[1]]
37         sp[i:1] = [p]    
38         subdiv(sp,flat,i)
41 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99