@@ -311,6 +311,61 @@ def test_symmetry_property_wrong_number_of_values_misorientation(error_type, val
311311 o .symmetry = value
312312
313313
314+ def test_from_path_ends ():
315+ """check from_path_ends returns what you would expect and
316+ preserves symmetry information.
317+ In particular, ensure the class of the returned object matches the class
318+ used for creating it, NOT the class of the object passed in.
319+ """
320+ q = Quaternion .random (10 )
321+ r = Rotation .random (10 )
322+ o = Orientation .random (10 , Oh )
323+ m = Misorientation .random (10 , [D3 , Oh ])
324+
325+ # Quaternion sanity checks
326+ a = Quaternion .from_path_ends (q )
327+ assert isinstance (a , Quaternion )
328+ b = Quaternion .from_path_ends (r )
329+ assert isinstance (b , Quaternion )
330+ c = Quaternion .from_path_ends (o )
331+ assert isinstance (c , Quaternion )
332+ d = Quaternion .from_path_ends (m )
333+ assert isinstance (d , Quaternion )
334+
335+ # Rotation sanity checks
336+ a = Rotation .from_path_ends (q )
337+ assert isinstance (a , Rotation )
338+ b = Rotation .from_path_ends (r )
339+ assert isinstance (b , Rotation )
340+ c = Rotation .from_path_ends (o )
341+ assert isinstance (c , Rotation )
342+ d = Rotation .from_path_ends (m )
343+ assert isinstance (d , Rotation )
344+
345+ # Misorientation sanity checks
346+ with pytest .raises (TypeError , match = "Points must be a Misorientation" ):
347+ a = Misorientation .from_path_ends (q )
348+ with pytest .raises (TypeError , match = "Points must be a Misorientation" ):
349+ b = Misorientation .from_path_ends (r )
350+ c = Misorientation .from_path_ends (o )
351+ assert isinstance (c , Misorientation )
352+ d = Misorientation .from_path_ends (m )
353+ assert isinstance (d , Misorientation )
354+ assert c .symmetry [1 ] == o .symmetry
355+ assert d .symmetry == m .symmetry
356+
357+ # Orientation sanity checks
358+ with pytest .raises (TypeError , match = "Points must be an Orientation" ):
359+ a = Orientation .from_path_ends (q )
360+ with pytest .raises (TypeError , match = "Points must be an Orientation" ):
361+ b = Orientation .from_path_ends (r )
362+ c = Orientation .from_path_ends (o )
363+ assert c .symmetry == o .symmetry
364+ assert isinstance (c , Orientation )
365+ with pytest .raises (TypeError , match = "Points must be an Orientation" ):
366+ d = Orientation .from_path_ends (m )
367+
368+
314369class TestMisorientation :
315370 def test_get_distance_matrix (self ):
316371 """Compute distance between every misorientation in an instance
@@ -811,6 +866,11 @@ def test_in_fundamental_region(self):
811866 region = np .radians (pg .euler_fundamental_region )
812867 assert np .all (np .max (ori .in_euler_fundamental_region (), axis = 0 ) <= region )
813868
869+ def test_from_path_ends (self ):
870+ # generate paths with orientations to check symmetry copying
871+ wp_o = Orientation (data = np .eye (4 )[:2 ], symmetry = Oh )
872+ assert Orientation .from_path_ends (wp_o )._symmetry == (C1 , Oh )
873+
814874 def test_inverse (self ):
815875 O1 = Orientation ([np .sqrt (2 ) / 2 , np .sqrt (2 ) / 2 , 0 , 0 ], D6 )
816876 O2 = ~ O1
0 commit comments