cubicsuperpath.py revision 80809dee6f6d120234c4570056c9a10c063953d8
1549N/A#!/usr/bin/env python
1549N/A"""
1549N/Acubicsuperpath.py
1549N/A
1549N/ACopyright (C) 2005 Aaron Spike, aaron@ekips.org
1549N/A
1549N/AThis program is free software; you can redistribute it and/or modify
1549N/Ait under the terms of the GNU General Public License as published by
1549N/Athe Free Software Foundation; either version 2 of the License, or
1549N/A(at your option) any later version.
1549N/A
1549N/AThis program is distributed in the hope that it will be useful,
1549N/Abut WITHOUT ANY WARRANTY; without even the implied warranty of
1549N/AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1549N/AGNU General Public License for more details.
1549N/A
1549N/AYou should have received a copy of the GNU General Public License
1549N/Aalong with this program; if not, write to the Free Software
1549N/AFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1549N/A
1549N/A"""
1549N/Aimport simplepath
1549N/A
1549N/Adef CubicSuperPath(simplepath):
1549N/A csp = []
1549N/A subpath = -1
1549N/A subpathstart = []
1549N/A last = []
1549N/A lastctrl = []
1549N/A for s in simplepath:
1549N/A cmd, params = s
1549N/A if cmd == 'M':
1549N/A if last:
1549N/A csp[subpath].append([lastctrl[:],last[:],last[:]])
1549N/A subpath += 1
1549N/A csp.append([])
1549N/A subpathstart = params[:]
1549N/A last = params[:]
1549N/A lastctrl = params[:]
1549N/A elif cmd == 'L':
1549N/A csp[subpath].append([lastctrl[:],last[:],last[:]])
1549N/A last = params[:]
1549N/A lastctrl = params[:]
1549N/A elif cmd == 'C':
1549N/A csp[subpath].append([lastctrl[:],last[:],params[:2]])
1549N/A last = params[-2:]
1549N/A lastctrl = params[2:4]
1549N/A elif cmd == 'Q':
1549N/A #TODO: convert to cubic
1549N/A csp[subpath].append([lastctrl[:],last[:],last[:]])
1549N/A last = params[-2:]
1549N/A lastctrl = params[-2:]
1549N/A elif cmd == 'A':
1549N/A #TODO: convert to cubics
1549N/A csp[subpath].append([lastctrl[:],last[:],last[:]])
1549N/A last = params[-2:]
1549N/A lastctrl = params[-2:]
elif cmd == 'Z':
csp[subpath].append([lastctrl[:],last[:],last[:]])
last = subpathstart[:]
lastctrl = subpathstart[:]
#append final superpoint
csp[subpath].append([lastctrl[:],last[:],last[:]])
return csp
def unCubicSuperPath(csp):
a = []
for subpath in csp:
if subpath:
a.append(['M',subpath[0][1][:]])
for i in range(1,len(subpath)):
a.append(['C',subpath[i-1][2][:] + subpath[i][0][:] + subpath[i][1][:]])
return a
def parsePath(d):
return CubicSuperPath(simplepath.parsePath(d))
def formatPath(p):
return simplepath.formatPath(unCubicSuperPath(p))