def bezier_to_sbasis(handles, order): if (order == 0): return l2s(py2geom.Linear(handles[0])) elif (order == 1): return l2s(py2geom.Linear(handles[0], handles[1])) else: return ( py2geom.multiply(OmX, bezier_to_sbasis(handles[:-1], order - 1)) + py2geom.multiply(X, bezier_to_sbasis(handles[1:], order - 1)))
def constant(l): pws = py2geom.PiecewiseSBasis() pws.push_cut(0) pws.push_seg(l2s(py2geom.Linear(l, l))) pws.push_cut(1000) return pws
pwsb = PiecewiseSBasis() pwsb.push_seg(sb) pwsb.push_cut(0) pwsb.push_cut(1) print pwsb.size() print "invariants:", pwsb.invariants() print pwsb(0) def l2s(l): sb = py2geom.SBasis() sb.append(l) return sb X = l2s(py2geom.Linear(0, 1)) OmX = l2s(py2geom.Linear(1, 0)) def bezier_to_sbasis(handles, order): print "b2s:", handles, order if (order == 0): return l2s(py2geom.Linear(handles[0])) elif (order == 1): return l2s(py2geom.Linear(handles[0], handles[1])) else: return ( py2geom.multiply(OmX, bezier_to_sbasis(handles[:-1], order - 1)) + py2geom.multiply(X, bezier_to_sbasis(handles[1:], order - 1)))