1
- from sympy import I , Rational , Symbol , pi , sqrt , S
1
+ from sympy import I , Rational , Symbol , pi , sqrt , sympify , S , Basic
2
2
from sympy .geometry import Line , Point , Point2D , Point3D , Line3D , Plane
3
- from sympy .geometry .entity import rotate , scale , translate
3
+ from sympy .geometry .entity import rotate , scale , translate , GeometryEntity
4
4
from sympy .matrices import Matrix
5
5
from sympy .utilities .iterables import subsets , permutations , cartes
6
+ from sympy .utilities .misc import Undecidable
6
7
from sympy .testing .pytest import raises , warns
7
8
8
9
@@ -27,6 +28,8 @@ def test_point():
27
28
assert (p3 + p4 ) == p4
28
29
assert (p2 - p1 ) == Point (y1 - x1 , y2 - x2 )
29
30
assert - p2 == Point (- y1 , - y2 )
31
+ raises (TypeError , lambda : Point (1 ))
32
+ raises (ValueError , lambda : Point ([1 ]))
30
33
raises (ValueError , lambda : Point (3 , I ))
31
34
raises (ValueError , lambda : Point (2 * I , I ))
32
35
raises (ValueError , lambda : Point (3 + I , I ))
@@ -36,10 +39,13 @@ def test_point():
36
39
assert Point .midpoint (p1 , p4 ) == Point (half + half * x1 , half + half * x2 )
37
40
assert Point .midpoint (p2 , p2 ) == p2
38
41
assert p2 .midpoint (p2 ) == p2
42
+ assert p1 .origin == Point (0 , 0 )
39
43
40
44
assert Point .distance (p3 , p4 ) == sqrt (2 )
41
45
assert Point .distance (p1 , p1 ) == 0
42
46
assert Point .distance (p3 , p2 ) == sqrt (p2 .x ** 2 + p2 .y ** 2 )
47
+ raises (TypeError , lambda : Point .distance (p1 , 0 ))
48
+ raises (TypeError , lambda : Point .distance (p1 , GeometryEntity ()))
43
49
44
50
# distance should be symmetric
45
51
assert p1 .distance (line ) == line .distance (p1 )
@@ -48,6 +54,7 @@ def test_point():
48
54
assert Point .taxicab_distance (p4 , p3 ) == 2
49
55
50
56
assert Point .canberra_distance (p4 , p5 ) == 1
57
+ raises (ValueError , lambda : Point .canberra_distance (p3 , p3 ))
51
58
52
59
p1_1 = Point (x1 , x1 )
53
60
p1_2 = Point (y2 , y2 )
@@ -67,6 +74,8 @@ def test_point():
67
74
68
75
assert p3 .intersection (Point (0 , 0 )) == [p3 ]
69
76
assert p3 .intersection (p4 ) == []
77
+ assert p3 .intersection (line ) == []
78
+ assert Point .intersection (Point (0 , 0 , 0 ), Point (0 , 0 )) == [Point (0 , 0 , 0 )]
70
79
71
80
x_pos = Symbol ('x' , real = True , positive = True )
72
81
p2_1 = Point (x_pos , 0 )
@@ -81,6 +90,25 @@ def test_point():
81
90
assert Point .is_concyclic (* pts ) is False
82
91
assert Point .is_concyclic (p4 , p4 * 2 , p4 * 3 ) is False
83
92
assert Point (0 , 0 ).is_concyclic ((1 , 1 ), (2 , 2 ), (2 , 1 )) is False
93
+ assert Point .is_concyclic (Point (0 , 0 , 0 , 0 ), Point (1 , 0 , 0 , 0 ), Point (1 , 1 , 0 , 0 ), Point (1 , 1 , 1 , 0 )) is False
94
+
95
+ assert p1 .is_scalar_multiple (p1 )
96
+ assert p1 .is_scalar_multiple (2 * p1 )
97
+ assert not p1 .is_scalar_multiple (p2 )
98
+ assert Point .is_scalar_multiple (Point (1 , 1 ), (- 1 , - 1 ))
99
+ assert Point .is_scalar_multiple (Point (0 , 0 ), (0 , - 1 ))
100
+ # test when is_scalar_multiple can't be determined
101
+ raises (Undecidable , lambda : Point .is_scalar_multiple (Point (sympify ("x1%y1" ), sympify ("x2%y2" )), Point (0 , 1 )))
102
+
103
+ assert Point (0 , 1 ).orthogonal_direction == Point (1 , 0 )
104
+ assert Point (1 , 0 ).orthogonal_direction == Point (0 , 1 )
105
+
106
+ assert p1 .is_zero is None
107
+ assert p3 .is_zero
108
+ assert p4 .is_zero is False
109
+ assert p1 .is_nonzero is None
110
+ assert p3 .is_nonzero is False
111
+ assert p4 .is_nonzero
84
112
85
113
assert p4 .scale (2 , 3 ) == Point (2 , 3 )
86
114
assert p3 .scale (2 , 3 ) == p3
@@ -103,6 +131,11 @@ def test_point():
103
131
Point (a .n (2 ), b .n (2 ), evaluate = False )
104
132
raises (ValueError , lambda : Point (1 , 2 ) + 1 )
105
133
134
+ # test project
135
+ assert Point .project ((0 , 1 ), (1 , 0 )) == Point (0 , 0 )
136
+ assert Point .project ((1 , 1 ), (1 , 0 )) == Point (1 , 0 )
137
+ raises (ValueError , lambda : Point .project (p1 , Point (0 , 0 )))
138
+
106
139
# test transformations
107
140
p = Point (1 , 0 )
108
141
assert p .rotate (pi / 2 ) == Point (0 , 1 )
@@ -118,6 +151,13 @@ def test_point():
118
151
raises (ValueError , lambda : p3 .transform (p3 ))
119
152
raises (ValueError , lambda : p .transform (Matrix ([[1 , 0 ], [0 , 1 ]])))
120
153
154
+ # test __contains__
155
+ assert 0 in Point (0 , 0 , 0 , 0 )
156
+ assert 1 not in Point (0 , 0 , 0 , 0 )
157
+
158
+ # test affine_rank
159
+ assert Point .affine_rank () == - 1
160
+
121
161
122
162
def test_point3D ():
123
163
x = Symbol ('x' , real = True )
@@ -277,6 +317,9 @@ def test_Point2D():
277
317
assert p1 .coordinates == (1 , 5 )
278
318
assert p2 .coordinates == (4 , 2.5 )
279
319
320
+ # test bounds
321
+ assert p1 .bounds == (1 , 5 , 1 , 5 )
322
+
280
323
def test_issue_9214 ():
281
324
p1 = Point3D (4 , - 2 , 6 )
282
325
p2 = Point3D (1 , 2 , 3 )
@@ -381,6 +424,12 @@ def test_arguments():
381
424
# never raise error if creating an origin
382
425
assert Point (dim = 3 , on_morph = 'error' )
383
426
427
+ # raise error with unmatched dimension
428
+ raises (ValueError , lambda : Point (1 , 1 , dim = 3 , on_morph = 'error' ))
429
+ # test unknown on_morph
430
+ raises (ValueError , lambda : Point (1 , 1 , dim = 3 , on_morph = 'unknown' ))
431
+ # test invalid expressions
432
+ raises (TypeError , lambda : Point (Basic (), Basic ()))
384
433
385
434
def test_unit ():
386
435
assert Point (1 , 1 ).unit == Point (sqrt (2 )/ 2 , sqrt (2 )/ 2 )
0 commit comments