Пример #1
0
def newLineByTransformingSpace2(self, transformer, transformDensity=0.1, maxError=1.5):
	""" Transforms this line through a function "transformer" which takes one parameter (a Vector2) and returns a Vector2 of the transformed position.

	Unlike, say, newLineByFilteringNodes() this function can transform the "insides" of curves, not just the positions of the nodes. It does this by densly resampling the line, transforming these samples, then fitting a new path through the resulting shape. The optional parameter "transformDensity" sets the number of dense samples per unit length of the input line.  "maxError" controls the tightness of the fit."""

	numSamples = 2 + int(transformDensity*self.cursor().length())
	x = [x.position2() for x in self.newLineByResampling(numSamples).nodes]
	y= [transformer(x) for x in x]
	fit = PathFitter(y, maxError)
	fit.fit()
	return fit.toCachedLine()
Пример #2
0
def newLineByFitting2(self, maxError=1.5, resample=0):
	""" Fits a FLine to this path.

	For oversampled or "noisy" lines, this new line may end up being much simpler (especially if you set maxError to be quite large). For very simple lines you may end up with a few more spline sections (the fitting algorithm used is not perfect). Set resample to a number > 0 to resample this line before fitting, otherwise this line is treated a a mere series of points """

	if (resample>0):
		x = [x.position2() for x in self.newLineByResampling(resample).nodes]
	else:
		x = [x.position2() for x in self.nodes]

	fit = PathFitter(x, maxError)
	fit.fit()
	return fit.toCachedLine()