From 1a43b77bfa56df7956b13128d0031bbb4fa50a1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Thu, 21 Oct 2004 13:14:34 +0000 Subject: [PATCH] append/extend in normpath also allows for regular path elements now; path got an extend as well git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@1911 069f4177-920e-0410-937b-c2a4a81bcd90 --- examples/graphs/partialfill.py | 6 +++--- manual/path.tex | 23 +++++++++++------------ pyx/path.py | 39 ++++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/examples/graphs/partialfill.py b/examples/graphs/partialfill.py index eb7fc334..533bcb12 100644 --- a/examples/graphs/partialfill.py +++ b/examples/graphs/partialfill.py @@ -23,9 +23,9 @@ for i in range(0, len(splith)-2, 2): area = area.joined(horiz.split([splith[i+1], splith[i+2]])[1]) area = area.joined(fline.split([splitf[-2], splitf[-1]])[1]) area = area.joined(horiz.split([splith[-1]])[1]) -area[-1].append(path.normline(*(area[-1].end_pt() + g.vpos_pt(1, 0)))) -area[-1].append(path.normline(*(area[-1].end_pt() + g.vpos_pt(0, 0)))) -area[-1].close() +area.append(path.lineto(*g.vpos(1, 0))) +area.append(path.lineto(*g.vpos(0, 0))) +area.append(path.closepath()) # not really needed (filling closes automatically) c = canvas.canvas() diff --git a/manual/path.tex b/manual/path.tex index a54ba8ad..c7c768f5 100644 --- a/manual/path.tex +++ b/manual/path.tex @@ -72,6 +72,10 @@ Returns the total arc length of the path.$^\dagger$ Returns the coordinates (as 2-tuple) of the end point of the path.$^\dagger$ \end{methoddesc} +\begin{methoddesc}{extend}{pathitems} +Appends the list \var{pathitems} to the end of the path. +\end{methoddesc} + \begin{methoddesc}{intersect}{opath} Returns a tuple consisting of two lists of parameter values corresponding to the intersection points of the path with the other @@ -297,18 +301,13 @@ instances, you pass them to the \class{normpath} constructor: is a list of \class{subnormpath} instances. \end{classdesc} -Instances of \class{normpath} offers all methods of normal -\class{path}s, which also have the same semantics. A exceptions are: - -\begin{methoddesc}{append}{anormsubpath} - Append \var{anormsubpath}, which has to be a \class{normsubpath} - instance, to the \class{normpath} instance. -\end{methoddesc} - -\begin{methoddesc}{extend}{normsubpaths} - Extend the \class{normpath} by \var{normsubpaths}, which has to be a - a list of \class{normsubpath} instances. -\end{methoddesc} +Instances of \class{normpath} offers all methods of regular +\class{path}s, which also have the same semantics. An exception are +the methods \method{append} and \method{extend}. While they allow for +adding of instances of \class{subnormpath} to the \class{normpath} +instance, they also keep the functionality of a regular path and allow +for regular path elements to be appended. The later are converted to +the proper normpath representation during addition. In addition to the \class{path} methods, a \class{normpath} instance also offers the following methods, which operate on the instance diff --git a/pyx/path.py b/pyx/path.py index dafac3a3..243b47de 100755 --- a/pyx/path.py +++ b/pyx/path.py @@ -1046,6 +1046,9 @@ class path(base.canvasitem): """return coordinates of last point of last subpath in path""" return self.normpath().end() + def extend(self, pathitems): + self.path.extend(pathitems) + def joined(self, other): """return path consisting of self and other joined together""" return self.normpath().joined(other) @@ -2011,9 +2014,13 @@ class normsubpath: return None def begin_pt(self): + if not self.normsubpathitems and self.skippedline: + return self.skippedline.begin_pt() return self.normsubpathitems[0].begin_pt() def begin(self): + if not self.normsubpathitems and self.skippedline: + return self.skippedline.begin() return self.normsubpathitems[0].begin() def close(self): @@ -2043,9 +2050,13 @@ class normsubpath: return normsubpathitem.curvradius_pt(itemparam) def end_pt(self): + if self.skippedline: + return self.skippedline.end_pt() return self.normsubpathitems[-1].end_pt() def end(self): + if self.skippedline: + return self.skippedline.end() return self.normsubpathitems[-1].end() def extend(self, normsubpathitems): @@ -2381,13 +2392,22 @@ class normpath(base.canvasitem): return normsubpath, normsubpath.arclentoparam(arclen) def append(self, anormsubpath): - assert isinstance(anormsubpath, normsubpath), "only list of normsubpath instance allowed" - self.normsubpaths.append(anormsubpath) - - def extend(self, normsubpaths): - for anormsubpath in normsubpaths: - assert isinstance(anormsubpath, normsubpath), "only list of normsubpath instance allowed" - self.normsubpaths.extend(normsubpaths) + if isinstance(anormsubpath, normsubpath): + # the normsubpaths list can be appended by a normsubpath only + self.normsubpaths.append(anormsubpath) + else: + # ... but we are kind and allow for regular path items as well + # in order to make a normpath to behave more like a regular path + + for pathitem in anormsubpath._normalized(_pathcontext(self.normsubpaths[-1].begin_pt(), + self.normsubpaths[-1].end_pt())): + if isinstance(pathitem, closepath): + self.normsubpaths[-1].close() + elif isinstance(pathitem, moveto_pt): + self.normsubpaths.append(normsubpath([normline(pathitem.x_pt, pathitem.y_pt, + pathitem.x_pt, pathitem.y_pt)])) + else: + self.normsubpaths[-1].append(pathitem) def arclen_pt(self): """returns total arc length of normpath in pts""" @@ -2505,6 +2525,11 @@ class normpath(base.canvasitem): else: raise PathException("cannot return last point of empty path") + def extend(self, normsubpaths): + for anormsubpath in normsubpaths: + # use append to properly handle regular path items as well as normsubpaths + self.append(anormsubpath) + def join(self, other): if not self.normsubpaths: raise PathException("cannot join to end of empty path") -- 2.11.4.GIT