Skip to content

Commit 8ff10d2

Browse files
committed
Fix coordinate alteration issue in XYImageItem: return copies of X/Y values to prevent modification of internal data
Fix #49
1 parent dab64c0 commit 8ff10d2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
🛠️ Bug fixes:
6565

66+
* [Issue #49](https://github.com/PlotPyStack/PlotPy/issues/49) - Using cross-section tools on `XYImageItem` images alters the X/Y coordinate arrays
6667
* Fixed index bounds calculation for image slicing compatibility:
6768
* Corrected the calculation of maximum indices in `get_plot_coordinates` to ensure proper bounds when using NumPy array slicing
6869
* Previously, the maximum indices were off by one, which could cause issues when extracting image data using the returned coordinates

plotpy/items/image/standard.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,10 @@ def get_x_values(self, i0: int, i1: int) -> np.ndarray:
703703
Returns:
704704
X values corresponding to the given pixel indexes
705705
"""
706-
return self.x[i0:i1]
706+
# Returning a copy to prevent modification of internal data by caller
707+
# (Fixes issue #49 - Using cross-section tools on `XYImageItem` images alters
708+
# the X/Y coordinate arrays)
709+
return self.x[i0:i1].copy()
707710

708711
def get_y_values(self, j0: int, j1: int) -> np.ndarray:
709712
"""Get Y values from pixel indexes
@@ -715,7 +718,7 @@ def get_y_values(self, j0: int, j1: int) -> np.ndarray:
715718
Returns:
716719
Y values corresponding to the given pixel indexes
717720
"""
718-
return self.y[j0:j1]
721+
return self.y[j0:j1].copy() # (same remark as in `get_x_values`)
719722

720723
def get_closest_coordinates(self, x: float, y: float) -> tuple[float, float]:
721724
"""

0 commit comments

Comments
 (0)