Source code for pyfeyn2.render.pyx.utils

"""Utility functions and classes for PyFeyn"""

import pyx

from pyfeyn2.render.pyx import config

## Default units
defunit = pyx.unit.cm
todefunit = pyx.unit.tocm


[docs]def sign(x): """Get the sign of a numeric type""" if x < 0: return -1 if x > 0: return 1 if x == 0: return 0
[docs]class Visible:
[docs] def isVisible(self): """Check if this instance is visible.""" return True
[docs] def getPath(self): """Return the path of this instance.""" return None
[docs] def getVisiblePath(self): """Return the visible path of this instance.""" return self.getPath()
[docs] def setDepth(self, depth): """Set the depth at which this instance lives.""" self.depth = depth return self
[docs] def getDepth(self): """Return the depth at which this instance lives.""" if "depth" in self.__dict__: return self.depth else: return None
def __cmp__(self, other): """Compare with another visible class, just using layers.""" if other is None: return -1 if config.getOptions().DEBUG: print( "Comparing visible classes: ", self.__class__, "->", self.getDepth(), "vs.", other.__class__, "->", other.getDepth(), ) else: return cmp(self.getDepth(), other.getDepth())