|
1 | 1 | diff --git a/sympy/geometry/point.py b/sympy/geometry/point.py |
2 | | -index 73c20334d09e..ai0000000000 100644 |
| 2 | +index 73c20334d..5c8636ee6 100644 |
3 | 3 | --- a/sympy/geometry/point.py |
4 | 4 | +++ b/sympy/geometry/point.py |
5 | | -@@ -149,7 +149,7 @@ def __new__(cls, *args, **kwargs): |
| 5 | +@@ -149,9 +149,12 @@ def __new__(cls, *args, **kwargs): |
6 | 6 | if any(coords[dim:]): |
7 | 7 | raise ValueError('Nonzero coordinates cannot be removed.') |
8 | 8 | - if any(a.is_number and im(a) for a in coords): |
| 9 | ++ # With automatic evaluation disabled, im(a) stays unevaluated (e.g. |
| 10 | ++ # im(1)), which made perfectly real coordinates look imaginary |
| 11 | ++ # (issue #22684). Only run this validation when evaluation is on. |
9 | 12 | + if evaluate and any(a.is_number and im(a) for a in coords): |
10 | 13 | raise ValueError('Imaginary coordinates are not permitted.') |
11 | 14 | if not all(isinstance(a, Expr) for a in coords): |
12 | 15 | raise TypeError('Coordinates must be valid SymPy expressions.') |
| 16 | + |
| 17 | + # pad with zeros appropriately |
| 18 | + coords = coords[:dim] + (S.Zero,)*(dim - len(coords)) |
13 | 19 | diff --git a/sympy/geometry/tests/test_point.py b/sympy/geometry/tests/test_point.py |
| 20 | +index 930d7fec2..8a1c2b3d4 100644 |
| 21 | +--- a/sympy/geometry/tests/test_point.py |
| 22 | ++++ b/sympy/geometry/tests/test_point.py |
14 | 23 | @@ -1,5 +1,6 @@ |
15 | 24 | from sympy.core.basic import Basic |
16 | | - from sympy.core.numbers import (I, Rational, pi) |
| 25 | + from sympy.core.numbers import (I, Float, Rational, pi) |
17 | 26 | +from sympy.core.parameters import evaluate |
18 | | -@@ -452,6 +453,12 @@ def test__normalize_dimension(): |
| 27 | + from sympy.core.singleton import S |
| 28 | + from sympy.core.symbol import Symbol |
| 29 | + from sympy.core.sympify import sympify |
| 30 | +@@ -452,6 +453,13 @@ def test__normalize_dimension(): |
| 31 | + assert Point._normalize_dimension(Point(1, 2), Point(3, 4, 0)) == [ |
| 32 | + Point(1, 2, 0), Point(3, 4, 0)] |
| 33 | + |
| 34 | ++ |
19 | 35 | +def test_issue_22684(): |
20 | | -+ # Used to give an error |
| 36 | ++ # Used to raise 'Imaginary coordinates are not permitted.' |
21 | 37 | + with evaluate(False): |
22 | | -+ Point(1, 2) |
| 38 | ++ p = Point(1, 2) |
| 39 | ++ assert p == Point(1, 2) |
| 40 | ++ |
| 41 | + |
| 42 | + def test_direction_cosine(): |
| 43 | + p1 = Point3D(0, 0, 0) |
0 commit comments