Skip to content

Commit

Permalink
Update ImageCanvasItem.py
Browse files Browse the repository at this point in the history
Fixed some more type errors.
  • Loading branch information
Tiomat85 committed Jun 19, 2024
1 parent 06da54c commit 10bec43
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions nion/swift/ImageCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,18 +1143,19 @@ def convert_pixel_to_normalised(self, coord: Geometry.IntPoint) -> Geometry.Floa
list())
if widget_mapping:
mapped = self.map_widget_to_image(coord)
norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(mapped, self.__data_shape))
norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(mapped), iter(self.__data_shape)))
return Geometry.FloatPoint(norm_coord[0], norm_coord[1]) # y,x
return Geometry.FloatPoint(-1, -1)

#Apply a zoom factor to the widget, optionally focussed on a specific point
def _apply_fixed_zoom(self, zoom_in: bool, coord: Geometry.IntPoint = None) -> None:
def _apply_fixed_zoom(self, zoom_in: bool, coord: typing.Optional[Geometry.IntPoint]) -> None:
if coord:
# Coordinate specified, so needing to recenter to that point before we adjust zoom levels
widget_mapping = ImageCanvasItemMapping.make(self.__data_shape, self.__composite_canvas_item.canvas_bounds, list())
if widget_mapping:
mapped = self.map_widget_to_image(coord)
norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(mapped, self.__data_shape))
self._set_image_canvas_position(norm_coord)
norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(mapped), iter(self.__data_shape)))
self._set_image_canvas_position(Geometry.FloatPoint(norm_coord[0], norm_coord[1]))

# ensure that at least half of the image is always visible
new_image_norm_center_0 = max(min(norm_coord[0], 1.0), 0.0)
Expand All @@ -1175,15 +1176,15 @@ def _apply_selection_zoom(self, coord1: Geometry.IntPoint, coord2: Geometry.IntP
if widget_mapping:
coord1_mapped = self.map_widget_to_image(coord1)
coord2_mapped = self.map_widget_to_image(coord2)
norm_coord1 = tuple(ele1 / ele2 for ele1, ele2 in zip(coord1_mapped, self.__data_shape))
norm_coord2 = tuple(ele1 / ele2 for ele1, ele2 in zip(coord2_mapped, self.__data_shape))
norm_coord1 = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(coord1_mapped), iter(self.__data_shape)))
norm_coord2 = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(coord2_mapped), iter(self.__data_shape)))

norm_coord = tuple((ele1 + ele2)/2 for ele1, ele2 in zip(norm_coord1, norm_coord2))
self._set_image_canvas_position(norm_coord)
norm_coord = tuple((ele1 + ele2)/2 for ele1, ele2 in zip(iter(norm_coord1), iter(norm_coord2)))
self._set_image_canvas_position(Geometry.FloatPoint(norm_coord[0], norm_coord[1]))
# image now centered on middle of selection, need to calculate new zoom level required
# selection size in widget pixels
selection_size_screen_space = tuple(
abs(ele1 - ele2) for ele1, ele2 in zip(coord1, coord2)) # y,x
abs(ele1 - ele2) for ele1, ele2 in zip(iter(coord1), iter(coord2))) # y,x
widget_width = self.__composite_canvas_item.canvas_bounds.width / self.__image_zoom
widget_height = self.__composite_canvas_item.canvas_bounds.height / self.__image_zoom
widget_width_factor = widget_width / selection_size_screen_space[1]
Expand Down

0 comments on commit 10bec43

Please sign in to comment.