Explorar el Código

Protect unsupported point removal in removePoint

Kentaro Wada hace 2 años
padre
commit
151b8b60c6
Se han modificado 1 ficheros con 24 adiciones y 0 borrados
  1. 24 0
      labelme/shape.py

+ 24 - 0
labelme/shape.py

@@ -4,6 +4,7 @@ import math
 from qtpy import QtCore
 from qtpy import QtGui
 
+from labelme.logger import logger
 import labelme.utils
 
 
@@ -118,6 +119,29 @@ class Shape(object):
         self.points.insert(i, point)
 
     def removePoint(self, i):
+        if not self.canAddPoint():
+            logger.warning(
+                "Cannot remove point from: shape_type=%r",
+                self.shape_type,
+            )
+            return
+
+        if self.shape_type == "polygon" and len(self.points) <= 3:
+            logger.warning(
+                "Cannot remove point from: shape_type=%r, len(points)=%d",
+                self.shape_type,
+                len(self.points),
+            )
+            return
+
+        if self.shape_type == "linestrip" and len(self.points) <= 2:
+            logger.warning(
+                "Cannot remove point from: shape_type=%r, len(points)=%d",
+                self.shape_type,
+                len(self.points),
+            )
+            return
+
         self.points.pop(i)
 
     def isClosed(self):