File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,8 @@ def cos_value(v: Expr, degrees=True):
405405 return Expr .float (0 )
406406 if (degrees and v .is_value (Expr .float (180 ))) or (not degrees and v .is_value (pi )):
407407 return Expr .float (- 1 )
408+ if (degrees and v .is_value (Expr .float (- 90 ))) or (not degrees and v .is_value (- pi / Expr .float (2 ))):
409+ return Expr .float (0 )
408410 return unary_expr (cos_degree if degrees else cos , 'cos' , v )
409411
410412
@@ -416,6 +418,8 @@ def sin_value(v: Expr, degrees=True):
416418 if (degrees and v .is_value (Expr .float (90 ))) or (not degrees and v .is_value (pi / Expr .float (2 ))):
417419 return Expr .float (1 )
418420 if (degrees and v .is_value (Expr .float (180 ))) or (not degrees and v .is_value (- pi / Expr .float (2 ))):
421+ return Expr .float (0 )
422+ if (degrees and v .is_value (Expr .float (- 90 ))) or (not degrees and v .is_value (- pi / Expr .float (2 ))):
419423 return Expr .float (- 1 )
420424 return unary_expr (sin_degree if degrees else sin , 'sin' , v )
421425
@@ -518,7 +522,7 @@ def is_rotation(self):
518522 # The first condition _should_ always be true -- the second is only true if this is not the identity matrix
519523 if round ((self ._axes .inverse () * self ._axes ).trace (), 12 ) == Expr .float (3. ):
520524 return round (self ._axes .trace (), 12 ) != Expr .float (3. )
521- logger .info (f'Not a rotation matrix: { self ._axes } ' )
525+ logger .info (f'Not a rotation matrix: { self ._axes } since trace is { round (( self . _axes . inverse () * self . _axes ). trace (), 12 ) } ' )
522526 return False
523527
524528 @property
Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ def _random():
3838
3939
4040class TestOrientation (TestCase ):
41+ def test_simplifications_in_trig_functions (self ):
42+ from mccode_antlr .instr .orientation import sin_value , cos_value
43+ from mccode_antlr .common import Expr
44+ self .assertEqual (sin_value (Expr .float (0 )), Expr .float (0 ))
45+ self .assertEqual (sin_value (Expr .float (90 )), Expr .float (1 ))
46+ self .assertEqual (sin_value (Expr .float (- 90 )), Expr .float (- 1 ))
47+ self .assertEqual (sin_value (Expr .float (180 )), Expr .float (0 ))
48+
49+ self .assertEqual (cos_value (Expr .float (0 )), Expr .float (1 ))
50+ self .assertEqual (cos_value (Expr .float (90 )), Expr .float (0 ))
51+ self .assertEqual (cos_value (Expr .float (- 90 )), Expr .float (0 ))
52+ self .assertEqual (cos_value (Expr .float (180 )), Expr .float (- 1 ))
53+
54+
4155 def test_matrix_vector_multiply (self ):
4256 from mccode_antlr .instr .orientation import Vector , Matrix
4357 from mccode_antlr .common import Expr
You can’t perform that action at this time.
0 commit comments