コード例 #1
0
ファイル: mechanics.py プロジェクト: imoyer/pygestalt
 def transform(self, inputState):
     """Transforms from one state to another based on the provided input units.
       
     This is something of a bonus function, as the recommended useage is to explicitly call forward() or reverse().
     """
       
     if type(inputState) == units.dFloat:
         
         forwardUnitEquivalency = units.getUnitEquivalency(inputState, self.inputUnits(1)) #1 if equivalent, -1 if reciprocals, 0 if not equivalent
         reverseUnitEquivalency = units.getUnitEquivalency(inputState, self.outputUnits(1))
         
         if forwardUnitEquivalency == 1: #inputState units match transform input units. Transform in the forward direction.
             convertedInputState = units.convertToUnits(inputState, self.inputUnits, strict = True) #convert to input units, don't allow reciprocals
             return self.forwardTransform*convertedInputState
         elif reverseUnitEquivalency == 1: #inputState units match transform output units. Transform in the reverse direction.
             convertedInputState = units.convertToUnits(inputState, self.outputUnits, strict = True) #convert to input units, don't allow reciprocals
             return self.reverseTransform*convertedInputState
         else:
             utilities.notice(self, "Input to singleAxisElement transformer cannot be transformed because of a dimensionality mismatch.")
             raise errors.MechanismError("Encountered dimensionality mismatch while attempting transform.")
     else:
         utilities.notice(self, "Input to singleAxisElement transformer must be of type units.dFloat!")
         raise errors.MechanismError("Incorrect input type to singleAxisElement.transform()")
コード例 #2
0
ファイル: mechanics.py プロジェクト: imoyer/pygestalt
 def reverse(self, reverseState):
     """Tranforms in the reverse direction from an output state of the tranformer to the corresponding input state.
     
     inputState -- the input state of the transformer. MUST be provided as a units.dFloat type.
     
     Note that this function over-rides its base class transformer.forward() function.
     """
     
     if type(reverseState) == units.dFloat:
         convertedReverseState = units.convertToUnits(reverseState, self.outputUnits, strict = True) #convert to input units, don't allow reciprocals
         return self.reverseTransform*convertedReverseState
     else:
         utilities.notice(self, "Input to singleAxisElement transformer must be of type units.dFloat!")
         raise errors.MechanismError("Incorrect input type to singleAxisElement.reverse()")