Merge pull request #151 from jaewchoi/create

Fix a bug: creating a box with one point
This commit is contained in:
darrenl 2017-08-25 13:47:46 +08:00 committed by GitHub
commit 79f736139b
2 changed files with 8 additions and 7 deletions

View File

@ -244,10 +244,7 @@ class Canvas(QWidget):
self.current.addPoint(QPointF(maxX, minY)) self.current.addPoint(QPointF(maxX, minY))
self.current.addPoint(targetPos) self.current.addPoint(targetPos)
self.current.addPoint(QPointF(minX, maxY)) self.current.addPoint(QPointF(minX, maxY))
self.current.addPoint(initPos) self.finalise()
self.line[0] = self.current[-1]
if self.current.isClosed():
self.finalise()
elif not self.outOfPixmap(pos): elif not self.outOfPixmap(pos):
self.current = Shape() self.current = Shape()
self.current.addPoint(pos) self.current.addPoint(pos)
@ -447,6 +444,12 @@ class Canvas(QWidget):
def finalise(self): def finalise(self):
assert self.current assert self.current
if self.current.points[0] == self.current.points[-1]:
self.current = None
self.drawingPolygon.emit(False)
self.update()
return
self.current.close() self.current.close()
self.shapes.append(self.current) self.shapes.append(self.current)
self.current = None self.current = None

View File

@ -67,9 +67,7 @@ class Shape(object):
return False return False
def addPoint(self, point): def addPoint(self, point):
if self.points and point == self.points[0]: if not self.reachMaxPoints():
self.close()
else:
self.points.append(point) self.points.append(point)
def popPoint(self): def popPoint(self):