From 95ff5062fe1f2e5ddf78b76a5a6c5e4b50e3383e Mon Sep 17 00:00:00 2001 From: Jaewoo Choi Date: Tue, 22 Aug 2017 20:12:17 +0900 Subject: [PATCH 1/2] fix a bug: creating a box with one point --- libs/canvas.py | 4 ++-- libs/shape.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/canvas.py b/libs/canvas.py index cc681605..5d8e2b3e 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -245,9 +245,9 @@ class Canvas(QWidget): self.current.addPoint(targetPos) self.current.addPoint(QPointF(minX, maxY)) self.current.addPoint(initPos) + self.current.close() self.line[0] = self.current[-1] - if self.current.isClosed(): - self.finalise() + self.finalise() elif not self.outOfPixmap(pos): self.current = Shape() self.current.addPoint(pos) diff --git a/libs/shape.py b/libs/shape.py index de366d27..165ef599 100644 --- a/libs/shape.py +++ b/libs/shape.py @@ -67,9 +67,7 @@ class Shape(object): return False def addPoint(self, point): - if self.points and point == self.points[0]: - self.close() - else: + if not self.reachMaxPoints(): self.points.append(point) def popPoint(self): From 835af44c3a749a10ac825a3f92d7dba734689560 Mon Sep 17 00:00:00 2001 From: Jaewoo Choi Date: Tue, 22 Aug 2017 21:10:36 +0900 Subject: [PATCH 2/2] Prevent from creating a zero sized box --- libs/canvas.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/canvas.py b/libs/canvas.py index 5d8e2b3e..2de8148b 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -244,9 +244,6 @@ class Canvas(QWidget): self.current.addPoint(QPointF(maxX, minY)) self.current.addPoint(targetPos) self.current.addPoint(QPointF(minX, maxY)) - self.current.addPoint(initPos) - self.current.close() - self.line[0] = self.current[-1] self.finalise() elif not self.outOfPixmap(pos): self.current = Shape() @@ -449,6 +446,12 @@ class Canvas(QWidget): def finalise(self): 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.shapes.append(self.current) self.current = None