Avoid possible divide-by-zero in Vectors layer thumbnail update
@@ -665,6 +665,12 @@ class Vectors(Layer):
def _update_thumbnail(self):
"""Update thumbnail with current vectors and colors."""
+ # Set the default thumbnail to black, opacity 1
+ colormapped = np.zeros(self._thumbnail_shape)
+ colormapped[..., 3] = 1
+ if len(self.data) == 0:
+ self.thumbnail = colormapped
+ else:
# calculate min vals for the vertices and pad with 0.5
# the offset is needed to ensure that the top left corner of the
# vectors corresponds to the top left corner of the thumbnail
@@ -680,7 +686,6 @@ class Vectors(Layer):
).astype(int)[-2:]
zoom_factor = np.divide(self._thumbnail_shape[:2], shape).min()
- # vectors = copy(self._data_view[:, :, -2:])
if self._view_data.shape[0] > self._max_vectors_thumbnail:
thumbnail_indices = np.random.randint(
0, self._view_data.shape[0], self._max_vectors_thumbnail
@@ -690,13 +695,13 @@ class Vectors(Layer):
else:
vectors = copy(self._view_data[:, :, -2:])
thumbnail_color_indices = self._view_indices
- vectors[:, 1, :] = vectors[:, 0, :] + vectors[:, 1, :] * self.length
+ vectors[:, 1, :] = (
+ vectors[:, 0, :] + vectors[:, 1, :] * self.length
+ )
downsampled = (vectors - offset) * zoom_factor
downsampled = np.clip(
downsampled, 0, np.subtract(self._thumbnail_shape[:2], 1)
)
- colormapped = np.zeros(self._thumbnail_shape)
- colormapped[..., 3] = 1
edge_colors = self._edge.colors[thumbnail_color_indices]
for v, ec in zip(downsampled, edge_colors):
start = v[0]
