Correcting a few functions not handling Path having empty _segments (#143)
* Correcting poping from Path objects Poping from a 1-lengthed Path would yield an error due to not considering that the _segments attribute would be empty after deleting the last element. * Correcting point function Unspecified behavior if _segments is empty * Correcting setter and getter of start and endpull/98/head
parent
a0fc28849c
commit
1e5bfb4252
|
@ -2394,8 +2394,12 @@ class Path(MutableSequence):
|
|||
def __delitem__(self, index):
|
||||
del self._segments[index]
|
||||
self._length = None
|
||||
self._start = self._segments[0].start
|
||||
self._end = self._segments[-1].end
|
||||
if len(self._segments) > 0:
|
||||
self._start = self._segments[0].start
|
||||
self._end = self._segments[-1].end
|
||||
else:
|
||||
self._start = None
|
||||
self._end = None
|
||||
|
||||
def __iter__(self):
|
||||
return self._segments.__iter__()
|
||||
|
@ -2452,6 +2456,8 @@ class Path(MutableSequence):
|
|||
def point(self, pos):
|
||||
|
||||
# Shortcuts
|
||||
if len(self._segments) == 0:
|
||||
return None
|
||||
if pos == 0.0:
|
||||
return self._segments[0].point(pos)
|
||||
if pos == 1.0:
|
||||
|
@ -2555,25 +2561,27 @@ class Path(MutableSequence):
|
|||
|
||||
@property
|
||||
def start(self):
|
||||
if not self._start:
|
||||
if not self._start and len(self._segments)>0:
|
||||
self._start = self._segments[0].start
|
||||
return self._start
|
||||
|
||||
@start.setter
|
||||
def start(self, pt):
|
||||
self._start = pt
|
||||
self._segments[0].start = pt
|
||||
if len(self._segments)>0:
|
||||
self._segments[0].start = pt
|
||||
|
||||
@property
|
||||
def end(self):
|
||||
if not self._end:
|
||||
if not self._end and len(self._segments)>0:
|
||||
self._end = self._segments[-1].end
|
||||
return self._end
|
||||
|
||||
@end.setter
|
||||
def end(self, pt):
|
||||
self._end = pt
|
||||
self._segments[-1].end = pt
|
||||
if len(self._segments)>0:
|
||||
self._segments[-1].end = pt
|
||||
|
||||
def d(self, useSandT=False, use_closed_attrib=False, rel=False):
|
||||
"""Returns a path d-string for the path object.
|
||||
|
|
Loading…
Reference in New Issue