def get_length(self, line):
polR, polPhi = cmath.polar(line)
return polR
python类polar()的实例源码
def draw_parallel(self, start, guideLine, stepDistance):
polR, polPhi = cmath.polar(guideLine)
polR = stepDistance
return (cmath.rect(polR, polPhi) + start)
def draw_perpendicular(self, start, guideLine, stepDistance, invert = False):
polR, polPhi = cmath.polar(guideLine)
polR = stepDistance
debugMsg(polPhi)
if invert:
polPhi += (cmath.pi / 2)
else:
polPhi -= (cmath.pi / 2)
debugMsg(polPhi)
debugMsg(cmath.rect(polR, polPhi))
return (cmath.rect(polR, polPhi) + start)
def test_polar(self):
self.assertCISEqual(polar(0), (0., 0.))
self.assertCISEqual(polar(1.), (1., 0.))
self.assertCISEqual(polar(-1.), (1., pi))
self.assertCISEqual(polar(1j), (1., pi/2))
self.assertCISEqual(polar(-1j), (1., -pi/2))
def test_polar(self):
self.check_polar(polar)
def test_polar_errno(self):
# Issue #24489: check a previously set C errno doesn't disturb polar()
from _testcapi import set_errno
def polar_with_errno_set(z):
set_errno(11)
try:
return polar(z)
finally:
set_errno(0)
self.check_polar(polar_with_errno_set)
def test_polar(self):
self.check_polar(polar)
def test_polar_errno(self):
# Issue #24489: check a previously set C errno doesn't disturb polar()
from _testcapi import set_errno
def polar_with_errno_set(z):
set_errno(11)
try:
return polar(z)
finally:
set_errno(0)
self.check_polar(polar_with_errno_set)
def test_polar(self):
self.assertCISEqual(polar(0), (0., 0.))
self.assertCISEqual(polar(1.), (1., 0.))
self.assertCISEqual(polar(-1.), (1., pi))
self.assertCISEqual(polar(1j), (1., pi/2))
self.assertCISEqual(polar(-1j), (1., -pi/2))
def __init__(self, _io, _parent=None, _root=None, _conversion_factor=None):
self._conversion_factor = _conversion_factor
self._io = _io
self._parent = _parent
self._root = _root if _root else self
_on = self._parent._parent._station.format.rectangular_or_polar
if _on == 'rectangular':
self.phasors = self._root.PmuData.Phasors.Int.Rectangular(
self._io, self, self._root, self._conversion_factor)
elif _on == 'polar':
self.phasors = self._root.PmuData.Phasors.Int.Polar(
self._io, self, self._root, self._conversion_factor)
def magnitude(self):
if hasattr(self, '_m_magnitude'):
return self._m_magnitude if hasattr(self, '_m_magnitude') else None
self._m_magnitude, self._m_angle = cmath.polar(
complex(self.real, self.imaginary))
return self._m_magnitude if hasattr(self, '_m_magnitude') else None
def angle(self):
if hasattr(self, '_m_angle'):
return self._m_angle if hasattr(self, '_m_angle') else None
self._m_magnitude, self._m_angle = cmath.polar(
complex(self.real, self.imaginary))
return self._m_angle if hasattr(self, '_m_angle') else None
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
_on = self._parent._parent._station.format.rectangular_or_polar
if _on == 'rectangular':
self.phasors = self._root.PmuData.Phasors.Float.Rectangular(
self._io, self, self._root)
elif _on == 'polar':
self.phasors = self._root.PmuData.Phasors.Float.Polar(
self._io, self, self._root)
def magnitude(self):
if hasattr(self, '_m_magnitude'):
return self._m_magnitude if hasattr(self, '_m_magnitude') else None
self._m_magnitude, self._m_angle = cmath.polar(
complex(self.real, self.imaginary))
return self._m_magnitude if hasattr(self, '_m_magnitude') else None
def test_polar(self):
self.assertCISEqual(polar(0), (0., 0.))
self.assertCISEqual(polar(1.), (1., 0.))
self.assertCISEqual(polar(-1.), (1., pi))
self.assertCISEqual(polar(1j), (1., pi/2))
self.assertCISEqual(polar(-1j), (1., -pi/2))
def test_polar(self):
self.check_polar(polar)
def test_polar_errno(self):
# Issue #24489: check a previously set C errno doesn't disturb polar()
from _testcapi import set_errno
def polar_with_errno_set(z):
set_errno(11)
try:
return polar(z)
finally:
set_errno(0)
self.check_polar(polar_with_errno_set)
def test_polar(self):
self.assertCISEqual(polar(0), (0., 0.))
self.assertCISEqual(polar(1.), (1., 0.))
self.assertCISEqual(polar(-1.), (1., pi))
self.assertCISEqual(polar(1j), (1., pi/2))
self.assertCISEqual(polar(-1j), (1., -pi/2))
def test_polar(self):
self.assertCISEqual(polar(0), (0., 0.))
self.assertCISEqual(polar(1.), (1., 0.))
self.assertCISEqual(polar(-1.), (1., pi))
self.assertCISEqual(polar(1j), (1., pi/2))
self.assertCISEqual(polar(-1j), (1., -pi/2))
def draw_box(self, start, guideLine, xDistance, yDistance, kerf):
polR, polPhi = cmath.polar(guideLine)
#Kerf expansion
if self.flipside:
start -= cmath.rect(kerf / 2, polPhi)
start -= cmath.rect(kerf / 2, polPhi + (cmath.pi / 2))
else:
start -= cmath.rect(kerf / 2, polPhi)
start -= cmath.rect(kerf / 2, polPhi - (cmath.pi / 2))
lines = []
lines.append(['M', [start.real, start.imag]])
#Horizontal
polR = xDistance
move = cmath.rect(polR + kerf, polPhi) + start
lines.append(['L', [move.real, move.imag]])
start = move
#Vertical
polR = yDistance
if self.flipside:
polPhi += (cmath.pi / 2)
else:
polPhi -= (cmath.pi / 2)
move = cmath.rect(polR + kerf, polPhi) + start
lines.append(['L', [move.real, move.imag]])
start = move
#Horizontal
polR = xDistance
if self.flipside:
polPhi += (cmath.pi / 2)
else:
polPhi -= (cmath.pi / 2)
move = cmath.rect(polR + kerf, polPhi) + start
lines.append(['L', [move.real, move.imag]])
start = move
lines.append(['Z', []])
return lines
def draw_slots(self, path):
#Female slot creation
start = self.to_complex(path[0][1])
end = self.to_complex(path[1][1])
if self.edgefeatures == False:
segCount = (self.numslots * 2)
else:
segCount = (self.numslots * 2) - 1
distance = end - start
debugMsg(distance)
debugMsg("segCount - " + str(segCount))
try:
if self.edgefeatures:
segLength = self.get_length(distance) / segCount
else:
segLength = self.get_length(distance) / (segCount + 1)
except:
segLength = self.get_length(distance)
debugMsg("segLength - " + str(segLength))
newLines = []
line_style = simplestyle.formatStyle({ 'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.unittouu('1px')) })
for i in range(segCount):
if (self.edgefeatures and (i % 2) == 0) or (not self.edgefeatures and (i % 2)):
newLines = self.draw_box(start, distance, segLength, self.thickness, self.kerf)
debugMsg(newLines)
slot_id = self.uniqueId('slot')
g = inkex.etree.SubElement(self.current_layer, 'g', {'id':slot_id})
line_atts = { 'style':line_style, 'id':slot_id+'-inner-close-tab', 'd':simplepath.formatPath(newLines) }
inkex.etree.SubElement(g, inkex.addNS('path','svg'), line_atts )
#Find next point
polR, polPhi = cmath.polar(distance)
polR = segLength
start = cmath.rect(polR, polPhi) + start