diff --git a/cura/Arranging/ShapeArray.py b/cura/Arranging/ShapeArray.py index 9232c9f22f..6ef92b1743 100644 --- a/cura/Arranging/ShapeArray.py +++ b/cura/Arranging/ShapeArray.py @@ -29,8 +29,14 @@ class ShapeArray: offset_x = int(numpy.amin(flip_vertices[:, 1])) flip_vertices[:, 0] = numpy.add(flip_vertices[:, 0], -offset_y) flip_vertices[:, 1] = numpy.add(flip_vertices[:, 1], -offset_x) + flip_vertices = numpy.ceil(flip_vertices) shape = [int(numpy.amax(flip_vertices[:, 0])), int(numpy.amax(flip_vertices[:, 1]))] + if shape == [0, 0]: + shape = [1, 1] arr = cls.arrayFromPolygon(shape, flip_vertices) + if not numpy.any(arr): + # set at least 1 pixel + arr[0][0] = 1 return cls(arr, offset_x, offset_y) ## Instantiate an offset and hull ShapeArray from a scene node. diff --git a/tests/TestArrange.py b/tests/TestArrange.py index 737305f638..4f6bb64118 100755 --- a/tests/TestArrange.py +++ b/tests/TestArrange.py @@ -118,6 +118,13 @@ def test_arrayFromPolygon2(): assert numpy.any(array) +## Polygon -> array +def test_fromPolygon(): + vertices = numpy.array([[0, 0.5], [0, 0], [0.5, 0]]) + array = ShapeArray.fromPolygon(vertices, scale=0.5) + assert numpy.any(array.arr) + + ## Line definition -> array with true/false def test_check(): base_array = numpy.zeros([5, 5], dtype=float)