fixed return values

- homomorph, standardize, etc. are silent in-place operations (return
None)
- homomorphed, standardized, etc. are out-of place operations that
report
This commit is contained in:
Martin Diehl 2019-04-19 01:05:48 +02:00
parent 25518df80c
commit 9a43c2e4c5
2 changed files with 25 additions and 10 deletions

View File

@ -45,6 +45,12 @@ class Rotation:
else: else:
self.quaternion = Quaternion(q=quaternion[0],p=quaternion[1:4]) self.quaternion = Quaternion(q=quaternion[0],p=quaternion[1:4])
def __copy__(self):
"""Copy"""
return self.__class__(self.quaternion)
copy = __copy__
def __repr__(self): def __repr__(self):
"""Value in selected representation""" """Value in selected representation"""
@ -61,9 +67,9 @@ class Rotation:
Rotation: Details needed (active/passive), rotation of (3,3,3,3)-matrix should be considered Rotation: Details needed (active/passive), rotation of (3,3,3,3)-matrix should be considered
""" """
if isinstance(other, Rotation): # rotate a rotation if isinstance(other, Rotation): # rotate a rotation
qu = self.quaternion * other.quaternion qu = self.__class__(self.quaternion * other.quaternion)
if qu.q < 0: qu.homomorph() qu.standardize()
return self.__class__(qu) return qu
elif isinstance(other, np.ndarray): elif isinstance(other, np.ndarray):
if other.shape == (3,): # rotate a single (3)-vector if other.shape == (3,): # rotate a single (3)-vector
( x, y, z) = self.quaternion.p ( x, y, z) = self.quaternion.p
@ -102,11 +108,12 @@ class Rotation:
def inverse(self): def inverse(self):
"""In-place inverse rotation/backward rotation""" """In-place inverse rotation/backward rotation"""
self.quaternion.conjugate() self.quaternion.conjugate()
return self
def inversed(self): def inversed(self):
"""Inverse rotation/backward rotation""" """Inverse rotation/backward rotation"""
return self.__class__(self.quaternion.conjugated()) c = self.copy()
c.inverse()
return c
def standardize(self): def standardize(self):
@ -115,7 +122,9 @@ class Rotation:
def standardized(self): def standardized(self):
"""Ensure quaternion representation with positive q""" """Ensure quaternion representation with positive q"""
return self.__class__(self.quaternion.homomorphed() if self.quaternion.q < 0.0 else self.quaternion) c = self.copy()
c.standardize()
return c
def misorientation(self,other): def misorientation(self,other):
@ -929,7 +938,7 @@ class Orientation:
if breaker: break if breaker: break
if breaker: break if breaker: break
return (Orientation(r,self.symmetry), i,j, k == 1) if symmetries else r # disorientation ... return (Orientation(r,self.lattice), i,j, k == 1) if symmetries else r # disorientation ...
# ... own sym, other sym, # ... own sym, other sym,
# self-->other: True, self<--other: False # self-->other: True, self<--other: False

View File

@ -192,7 +192,9 @@ class Quaternion:
def normalized(self): def normalized(self):
"""Returns normalized copy""" """Returns normalized copy"""
return self.copy().normalize() c = self.copy()
c.normalize()
return c
def conjugate(self): def conjugate(self):
@ -201,7 +203,9 @@ class Quaternion:
def conjugated(self): def conjugated(self):
"""Returns conjugated copy""" """Returns conjugated copy"""
return self.copy().conjugate() c = self.copy()
c.conjugate()
return c
def homomorph(self): def homomorph(self):
@ -211,4 +215,6 @@ class Quaternion:
def homomorphed(self): def homomorphed(self):
"""Returns homomorphed copy""" """Returns homomorphed copy"""
return self.copy().homomorph() c = self.copy()
c.homomorph()
return c