MCPcopy Create free account
hub / github.com/PageBot/PageBot / Radians

Class Radians

Lib/pagebot/toolbox/units.py:2716–2773  ·  view source on GitHub ↗

Store the value as radians factor to math.pi, so 0.5*pi is stored in self.angle as 0.5. >>> from math import pi >>> a = radians(0.75) >>> a 0.75rad >>> a.degrees, a.radians (135, 0.75) >>> a = radians(0) >>> a.degrees, a.radians (0, 0) >>> # Add numbers i

Source from the content-addressed store, hash-verified

2714 return Degrees(angle)
2715
2716class Radians(Angle):
2717 """Store the value as radians factor to math.pi, so 0.5*pi is stored in
2718 self.angle as 0.5.
2719
2720 >>> from math import pi
2721 >>> a = radians(0.75)
2722 >>> a
2723 0.75rad
2724 >>> a.degrees, a.radians
2725 (135, 0.75)
2726 >>> a = radians(0)
2727 >>> a.degrees, a.radians
2728 (0, 0)
2729 >>> # Add numbers in the context of the angle type.
2730 >>> a = radians(0.5)
2731 >>> a + 0.5 - 0.25
2732 0.75rad
2733 >>> # Reverse addition casts the number into degree value
2734 >>> 20 + a
2735 20.5rad
2736 >>> 1.5 - a
2737 1rad
2738 >>> # Create integer value for whole angles
2739 >>> a/2
2740 0.25rad
2741 >>> -a
2742 -0.5rad
2743 """
2744 def __repr__(self):
2745 return '%srad' % self.angle
2746
2747 def asValue(self, angle):
2748 """Answers the value of angle of the same type as self.
2749
2750 >>> radians(0.5).asValue(0.75)
2751 0.75
2752 >>> radians(30).asValue(radians(0.33))
2753 0.33
2754 >>> radians(30).asValue(degrees(45))
2755 0.25
2756 """
2757 if isinstance(angle, Angle):
2758 return angle.radians
2759 return angle or 0
2760
2761 def _get_degrees(self):
2762 angle = math.degrees(math.pi*self.angle)
2763 if angle == round(angle):
2764 angle = int(angle)
2765 return angle
2766 degrees = property(_get_degrees)
2767
2768 def _get_radians(self):
2769 angle = self.angle
2770 if angle == round(angle):
2771 angle = int(angle)
2772 return angle
2773 radians = property(_get_radians)

Callers 1

radiansFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected