|
35 | 35 | from ansys.geometry.core.misc.units import UNITS
|
36 | 36 | from ansys.geometry.core.typing import Real, RealSequence
|
37 | 37 |
|
| 38 | +_NUMPY_MAJOR_VERSION = int(np.__version__[0]) |
| 39 | +"""Major version of the numpy library.""" |
| 40 | + |
38 | 41 |
|
39 | 42 | class Vector3D(np.ndarray):
|
40 | 43 | """Provides for managing and creating a 3D vector.
|
@@ -190,7 +193,7 @@ def get_angle_between(self, v: "Vector3D") -> Quantity:
|
190 | 193 |
|
191 | 194 | @check_input_types
|
192 | 195 | def cross(self, v: "Vector3D") -> "Vector3D":
|
193 |
| - """Get the cross product of ``Vector3D`` objects.""" |
| 196 | + """Return the cross product of ``Vector3D`` objects.""" |
194 | 197 | return np.cross(self, v).view(Vector3D)
|
195 | 198 |
|
196 | 199 | @check_input_types
|
@@ -323,9 +326,16 @@ def is_zero(self) -> bool:
|
323 | 326 | return all([comp == 0 for comp in self])
|
324 | 327 |
|
325 | 328 | @check_input_types
|
326 |
| - def cross(self, v: "Vector2D"): |
| 329 | + def cross(self, v: "Vector2D") -> Real: |
327 | 330 | """Return the cross product of ``Vector2D`` objects."""
|
328 |
| - return np.cross(self, v) |
| 331 | + if _NUMPY_MAJOR_VERSION >= 2: |
| 332 | + # See https://github.com/numpy/numpy/issues/26620 and more specifically |
| 333 | + # https://github.com/numpy/numpy/issues/26620#issuecomment-2150748569 |
| 334 | + return self[..., 0] * v[..., 1] - self[..., 1] * v[..., 0] |
| 335 | + else: # pragma: no cover |
| 336 | + # Coverage is measured with the latest version of numpy |
| 337 | + # so this code is not covered |
| 338 | + return np.cross(self, v) |
329 | 339 |
|
330 | 340 | @check_input_types
|
331 | 341 | def is_perpendicular_to(self, other_vector: "Vector2D") -> bool:
|
@@ -415,7 +425,7 @@ def __sub__(self, other: "Vector2D") -> "Vector2D":
|
415 | 425 | """Subtraction operation overload for 2D vectors."""
|
416 | 426 | return np.subtract(self, other).view(Vector2D)
|
417 | 427 |
|
418 |
| - def __mod__(self, other: "Vector2D") -> "Vector2D": |
| 428 | + def __mod__(self, other: "Vector2D") -> Real: |
419 | 429 | """Overload % operator with cross product."""
|
420 | 430 | return self.cross(other)
|
421 | 431 |
|
|
0 commit comments