Skip to content

Commit

Permalink
Fix numpy.cross 2d vector deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Apr 11, 2024
1 parent 5e865a5 commit 9734709
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/silx/gui/plot/items/_arc_roi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2018-2023 European Synchrotron Radiation Facility
# Copyright (c) 2018-2024 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -632,7 +632,12 @@ def _createGeometryFromControlPoints(self, start, mid, end, weight, closed=None)
center, start, end, radius, weight, startAngle, endAngle
)

elif numpy.linalg.norm(numpy.cross(mid - start, end - start)) < 1e-5:
elif (
numpy.linalg.norm(
numpy.cross(numpy.append(mid - start, 0), numpy.append(end - start, 0))
)
< 1e-5
):
# Degenerated arc, it's a rectangle
return _ArcGeometry.createRect(start, end, weight)
else:
Expand Down
15 changes: 5 additions & 10 deletions src/silx/gui/plot/items/scatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2017-2023 European Synchrotron Radiation Facility
# Copyright (c) 2017-2024 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -713,7 +713,7 @@ def _addBackendRenderer(self, backend):
shape = shape[0], int(numpy.ceil(nbpoints / shape[0]))

if shape[0] < 2 or shape[1] < 2: # Single line, at least 2 points
points = numpy.ones((2, nbpoints, 2), dtype=numpy.float64)
points = numpy.zeros((2, nbpoints, 3), dtype=numpy.float64)
# Use row/column major depending on shape, not on info value
gridOrder = "row" if shape[0] == 1 else "column"

Expand All @@ -727,19 +727,14 @@ def _addBackendRenderer(self, backend):
# Add a second line that will be clipped in the end
points[1, :-1] = (
points[0, :-1]
+ numpy.cross(points[0, 1:] - points[0, :-1], (0.0, 0.0, 1.0))[
:, :2
]
+ numpy.cross(points[0, 1:] - points[0, :-1], (0.0, 0.0, 1.0))
)
points[1, -1] = (
points[0, -1]
+ numpy.cross(points[0, -1] - points[0, -2], (0.0, 0.0, 1.0))[
:2
]
+ numpy.cross(points[0, -1] - points[0, -2], (0.0, 0.0, 1.0))
)

points.shape = 2, nbpoints, 2 # Use same shape for both orders
coords, indices = _quadrilateral_grid_as_triangles(points)
points = points[:, :, :2]

elif gridOrder == "row": # row-major order
if nbpoints != numpy.prod(shape):
Expand Down

0 comments on commit 9734709

Please sign in to comment.