diff --git a/cura/Arranging/ShapeArray.py b/cura/Arranging/ShapeArray.py index 840f9731c2..a063ec30bc 100644 --- a/cura/Arranging/ShapeArray.py +++ b/cura/Arranging/ShapeArray.py @@ -3,7 +3,7 @@ import numpy import copy -from typing import Optional, Tuple, TYPE_CHECKING +from typing import Optional, Tuple, TYPE_CHECKING, Union from UM.Math.Polygon import Polygon @@ -14,14 +14,14 @@ if TYPE_CHECKING: class ShapeArray: """Polygon representation as an array for use with :py:class:`cura.Arranging.Arrange.Arrange`""" - def __init__(self, arr: numpy.array, offset_x: float, offset_y: float, scale: float = 1) -> None: + def __init__(self, arr: numpy.ndarray, offset_x: float, offset_y: float, scale: float = 1) -> None: self.arr = arr self.offset_x = offset_x self.offset_y = offset_y self.scale = scale @classmethod - def fromPolygon(cls, vertices: numpy.array, scale: float = 1) -> "ShapeArray": + def fromPolygon(cls, vertices: numpy.ndarray, scale: float = 1) -> "ShapeArray": """Instantiate from a bunch of vertices :param vertices: @@ -98,7 +98,7 @@ class ShapeArray: return offset_shape_arr, hull_shape_arr @classmethod - def arrayFromPolygon(cls, shape: Tuple[int, int], vertices: numpy.array) -> numpy.array: + def arrayFromPolygon(cls, shape: Union[Tuple[int, int], numpy.ndarray], vertices: numpy.ndarray) -> numpy.ndarray: """Create :py:class:`numpy.ndarray` with dimensions defined by shape Fills polygon defined by vertices with ones, all other values zero @@ -126,7 +126,7 @@ class ShapeArray: return base_array @classmethod - def _check(cls, p1: numpy.array, p2: numpy.array, base_array: numpy.array) -> Optional[numpy.array]: + def _check(cls, p1: numpy.ndarray, p2: numpy.ndarray, base_array: numpy.ndarray) -> Optional[numpy.ndarray]: """Return indices that mark one side of the line, used by arrayFromPolygon Uses the line defined by p1 and p2 to check array of diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 6e518e984a..7f62a0a8fa 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -65,7 +65,7 @@ class LayerPolygon: # When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType # Should be generated in better way, not hardcoded. - self._is_infill_or_skin_type_map = numpy.array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], dtype = numpy.bool) + self._is_infill_or_skin_type_map = numpy.array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], dtype = bool) self._build_cache_line_mesh_mask = None # type: Optional[numpy.ndarray] self._build_cache_needed_points = None # type: Optional[numpy.ndarray] @@ -73,18 +73,17 @@ class LayerPolygon: def buildCache(self) -> None: # For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out. self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype = bool) - mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask) self._index_begin = 0 - self._index_end = mesh_line_count + self._index_end = cast(int, numpy.sum(self._build_cache_line_mesh_mask)) - self._build_cache_needed_points = numpy.ones((len(self._types), 2), dtype = numpy.bool) + self._build_cache_needed_points = numpy.ones((len(self._types), 2), dtype = bool) # Only if the type of line segment changes do we need to add an extra vertex to change colors self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1] # Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points ) self._vertex_begin = 0 - self._vertex_end = numpy.sum( self._build_cache_needed_points ) + self._vertex_end = cast(int, numpy.sum(self._build_cache_needed_points)) def build(self, vertex_offset: int, index_offset: int, vertices: numpy.ndarray, colors: numpy.ndarray, line_dimensions: numpy.ndarray, feedrates: numpy.ndarray, extruders: numpy.ndarray, line_types: numpy.ndarray, indices: numpy.ndarray) -> None: """Set all the arrays provided by the function caller, representing the LayerPolygon diff --git a/cura/Snapshot.py b/cura/Snapshot.py index bc7da4080a..ca9c442fb5 100644 --- a/cura/Snapshot.py +++ b/cura/Snapshot.py @@ -25,8 +25,8 @@ class Snapshot: pixels = numpy.frombuffer(pixel_array, dtype=numpy.uint8).reshape([height, width, 4]) # Find indices of non zero pixels nonzero_pixels = numpy.nonzero(pixels) - min_y, min_x, min_a_ = numpy.amin(nonzero_pixels, axis=1) - max_y, max_x, max_a_ = numpy.amax(nonzero_pixels, axis=1) + min_y, min_x, min_a_ = numpy.amin(nonzero_pixels, axis=1) # type: ignore + max_y, max_x, max_a_ = numpy.amax(nonzero_pixels, axis=1) # type: ignore return min_x, max_x, min_y, max_y