Skip to content

Commit

Permalink
Use tolerance when checking if scrolling needs updating on matrix change
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Aug 20, 2024
1 parent d1e5f94 commit f732836
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gaphas/view/gtkview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module contains everything to display a model on a screen."""
from __future__ import annotations

from math import isclose
from collections.abc import Collection, Iterable

import cairo
Expand Down Expand Up @@ -332,6 +333,7 @@ def update_bounding_box(self, items: Collection[Item]) -> None:

def update_scrolling(self) -> None:
matrix = Matrix(*self._matrix) # type: ignore[misc]
# When zooming the bounding box to view size, disregard current scroll offsets
matrix.set(x0=0, y0=0)
bounds = Rectangle(*transform_rectangle(matrix, self._qtree.soft_bounds))

Expand Down Expand Up @@ -386,7 +388,7 @@ def on_selection_update(self, item: Item | None) -> None:

def on_matrix_update(self, matrix, old_matrix_values):
# Test if scale or rotation changed
if tuple(matrix)[:4] != old_matrix_values[:4]:
if not all(map(isclose, matrix, old_matrix_values[:4])):
self.update_scrolling()
self._scrolling.update_position(matrix[4], matrix[5])
self.update_back_buffer()
Expand Down

0 comments on commit f732836

Please sign in to comment.