home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Inkscape / Inkscape-0.48.2-1-win32.exe / share / extensions / cspsubdiv.py < prev    next >
Text File  |  2011-07-08  |  910b  |  42 lines

  1. #!/usr/bin/env python
  2. from bezmisc import *
  3. from ffgeom import *
  4.  
  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)
  10.  
  11.     s1 = Segment(p0,p3)
  12.     return max(s1.distanceToPoint(p1),s1.distanceToPoint(p2))
  13.     
  14.  
  15. def cspsubdiv(csp,flat):
  16.     for sp in csp:
  17.         subdiv(sp,flat)
  18.  
  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)
  39.  
  40.  
  41. # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99
  42.