[PyX-checkins] commit 3525: trunk/pyx/pyx/normpath.py: allow for the calculation of the upper bound of arclen From: - 2013-10-10 08:51:31 ```Revision: 3525 https://sourceforge.net/p/pyx/code/3525/ Author: wobsta Date: 2013-10-10 08:51:24 +0000 (Thu, 10 Oct 2013) Log Message: ----------- allow for the calculation of the upper bound of arclen Modified Paths: -------------- trunk/pyx/pyx/normpath.py Modified: trunk/pyx/pyx/normpath.py =================================================================== --- trunk/pyx/pyx/normpath.py 2013-10-09 14:55:54 UTC (rev 3524) +++ trunk/pyx/pyx/normpath.py 2013-10-10 08:51:24 UTC (rev 3525) @@ -93,8 +93,11 @@ might be shared between several normsubpaths. """ - def arclen_pt(self, epsilon): - """return arc length in pts""" + def arclen_pt(self, epsilon, upper=False): + """return arc length in pts + + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" pass def _arclentoparam_pt(self, lengths_pt, epsilon): @@ -221,7 +224,7 @@ """return a tuple of params""" return self._arclentoparam_pt(lengths_pt, epsilon)[0] - def arclen_pt(self, epsilon): + def arclen_pt(self, epsilon, upper=False): return math.hypot(self.x0_pt-self.x1_pt, self.y0_pt-self.y1_pt) def at_pt(self, params): @@ -425,9 +428,9 @@ """return a tuple of params""" return self._arclentoparam_pt(lengths_pt, epsilon)[0] - def arclen_pt(self, epsilon): + def arclen_pt(self, epsilon, upper=False): a, b = self._midpointsplit(epsilon) - return a.arclen_pt(epsilon) + b.arclen_pt(epsilon) + return a.arclen_pt(epsilon, upper=upper) + b.arclen_pt(epsilon, upper=upper) def at_pt(self, params): return [( (-self.x0_pt+3*self.x1_pt-3*self.x2_pt+self.x3_pt)*t*t*t + @@ -698,6 +701,12 @@ self.l2_pt = l2_pt self.l3_pt = l3_pt + def arclen_pt(self, epsilon, upper=False): + if upper: + return self.l1_pt + self.l2_pt + self.l3_pt + else: + return math.hypot(self.x0_pt-self.x1_pt, self.y0_pt-self.y1_pt) + def subparamtoparam(self, param): if 0 <= param <= 1: params = mathutils.realpolyroots(self.l1_pt-2*self.l2_pt+self.l3_pt, @@ -862,10 +871,13 @@ else: self.skippedline = normline_pt(xs_pt, ys_pt, xe_pt, ye_pt) - def arclen_pt(self): - """return arc length in pts""" - return sum([npitem.arclen_pt(self.epsilon) for npitem in self.normsubpathitems]) + def arclen_pt(self, upper=False): + """return arc length in pts + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return sum([npitem.arclen_pt(self.epsilon, upper=upper) for npitem in self.normsubpathitems]) + def _arclentoparam_pt(self, lengths_pt): """return a tuple of params and the total length arc length in pts""" # work on a copy which is counted down to negative values @@ -1505,14 +1517,20 @@ else: self.normsubpaths = item.createnormpath(self).normsubpaths - def arclen_pt(self): - """return arc length in pts""" - return sum([normsubpath.arclen_pt() for normsubpath in self.normsubpaths]) + def arclen_pt(self, upper=False): + """return arc length in pts - def arclen(self): - """return arc length""" - return self.arclen_pt() * unit.t_pt + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return sum([normsubpath.arclen_pt(upper=upper) for normsubpath in self.normsubpaths]) + def arclen(self, upper=False): + """return arc length + + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return self.arclen_pt(upper=upper) * unit.t_pt + def _arclentoparam_pt(self, lengths_pt): """return the params matching the given lengths_pt""" # work on a copy which is counted down to negative values ```
 [PyX-checkins] commit 3525: trunk/pyx/pyx/normpath.py: allow for the calculation of the upper bound of arclen From: - 2013-10-10 08:51:31 ```Revision: 3525 https://sourceforge.net/p/pyx/code/3525/ Author: wobsta Date: 2013-10-10 08:51:24 +0000 (Thu, 10 Oct 2013) Log Message: ----------- allow for the calculation of the upper bound of arclen Modified Paths: -------------- trunk/pyx/pyx/normpath.py Modified: trunk/pyx/pyx/normpath.py =================================================================== --- trunk/pyx/pyx/normpath.py 2013-10-09 14:55:54 UTC (rev 3524) +++ trunk/pyx/pyx/normpath.py 2013-10-10 08:51:24 UTC (rev 3525) @@ -93,8 +93,11 @@ might be shared between several normsubpaths. """ - def arclen_pt(self, epsilon): - """return arc length in pts""" + def arclen_pt(self, epsilon, upper=False): + """return arc length in pts + + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" pass def _arclentoparam_pt(self, lengths_pt, epsilon): @@ -221,7 +224,7 @@ """return a tuple of params""" return self._arclentoparam_pt(lengths_pt, epsilon)[0] - def arclen_pt(self, epsilon): + def arclen_pt(self, epsilon, upper=False): return math.hypot(self.x0_pt-self.x1_pt, self.y0_pt-self.y1_pt) def at_pt(self, params): @@ -425,9 +428,9 @@ """return a tuple of params""" return self._arclentoparam_pt(lengths_pt, epsilon)[0] - def arclen_pt(self, epsilon): + def arclen_pt(self, epsilon, upper=False): a, b = self._midpointsplit(epsilon) - return a.arclen_pt(epsilon) + b.arclen_pt(epsilon) + return a.arclen_pt(epsilon, upper=upper) + b.arclen_pt(epsilon, upper=upper) def at_pt(self, params): return [( (-self.x0_pt+3*self.x1_pt-3*self.x2_pt+self.x3_pt)*t*t*t + @@ -698,6 +701,12 @@ self.l2_pt = l2_pt self.l3_pt = l3_pt + def arclen_pt(self, epsilon, upper=False): + if upper: + return self.l1_pt + self.l2_pt + self.l3_pt + else: + return math.hypot(self.x0_pt-self.x1_pt, self.y0_pt-self.y1_pt) + def subparamtoparam(self, param): if 0 <= param <= 1: params = mathutils.realpolyroots(self.l1_pt-2*self.l2_pt+self.l3_pt, @@ -862,10 +871,13 @@ else: self.skippedline = normline_pt(xs_pt, ys_pt, xe_pt, ye_pt) - def arclen_pt(self): - """return arc length in pts""" - return sum([npitem.arclen_pt(self.epsilon) for npitem in self.normsubpathitems]) + def arclen_pt(self, upper=False): + """return arc length in pts + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return sum([npitem.arclen_pt(self.epsilon, upper=upper) for npitem in self.normsubpathitems]) + def _arclentoparam_pt(self, lengths_pt): """return a tuple of params and the total length arc length in pts""" # work on a copy which is counted down to negative values @@ -1505,14 +1517,20 @@ else: self.normsubpaths = item.createnormpath(self).normsubpaths - def arclen_pt(self): - """return arc length in pts""" - return sum([normsubpath.arclen_pt() for normsubpath in self.normsubpaths]) + def arclen_pt(self, upper=False): + """return arc length in pts - def arclen(self): - """return arc length""" - return self.arclen_pt() * unit.t_pt + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return sum([normsubpath.arclen_pt(upper=upper) for normsubpath in self.normsubpaths]) + def arclen(self, upper=False): + """return arc length + + When upper is set, the upper bound is calculated, otherwise the lower + bound is returned.""" + return self.arclen_pt(upper=upper) * unit.t_pt + def _arclentoparam_pt(self, lengths_pt): """return the params matching the given lengths_pt""" # work on a copy which is counted down to negative values ```