@@ -47,6 +47,43 @@ def test_line_distance_parallel_tolerance():
4747 assert line1 .distance (line2 , tol = 1e8 ) == pytest .approx (np .sqrt (5 ))
4848
4949
50+ @pytest .mark .parametrize (
51+ "point, direction1, direction2" ,
52+ [
53+ ([0 , 0 , 0 ], [1 , 0 , 0 ], [0 , 1 , 0 ]),
54+ ([1 , 2 , 3 ], [1 , 0 , 0 ], [1 , 1 , 0 ]),
55+ ([- 3 , 1 , 2 ], [1 , 2 , 3 ], [- 2 , 1 , 1 ]),
56+ ],
57+ ids = ["origin" , "oblique" , "spatial" ],
58+ )
59+ @pytest .mark .parametrize (
60+ "scale1, scale2" , [(1 , 1 ), (2 , 5 ), (- 2 , 0.25 ), (1e-8 , 1e-8 ), (1e-8 , 1e8 )]
61+ )
62+ def test_line_intersection_point (point , direction1 , direction2 , scale1 , scale2 ):
63+ point = np .array (point )
64+ direction1 , direction2 = np .array (direction1 ), np .array (direction2 )
65+ line1 = Line3 .PointDir (point + 2 * direction1 , scale1 * direction1 )
66+ line2 = Line3 .PointDir (point - 3 * direction2 , scale2 * direction2 )
67+
68+ for first , second in [(line1 , line2 ), (line2 , line1 )]:
69+ intersection = first .intersects (second )
70+ assert intersection is not None
71+ assert intersection .shape == (3 ,)
72+ nt .assert_allclose (intersection , point , rtol = 0 , atol = 1e-12 )
73+
74+
75+ @pytest .mark .parametrize (
76+ "point, direction" ,
77+ [([0 , 1 , 0 ], [1 , 0 , 0 ]), ([2 , 0 , 0 ], [- 2 , 0 , 0 ]), ([0 , 0 , 1 ], [0 , 1 , 0 ])],
78+ ids = ["parallel" , "coincident" , "skew" ],
79+ )
80+ def test_line_intersection_none (point , direction ):
81+ line1 = Line3 .PointDir ([0 , 0 , 0 ], [1 , 0 , 0 ])
82+ line2 = Line3 .PointDir (point , direction )
83+ assert line1 .intersects (line2 ) is None
84+ assert line2 .intersects (line1 ) is None
85+
86+
5087class Line3Test (unittest .TestCase ):
5188 # Primitives
5289 def test_constructor1 (self ):
0 commit comments