0001"""
0002**points of the complex plane** which can be picked and moved
0003"""
0004
0005__Def__ = ['zSlider']
0006
0007__Classes__ = [ 'zFreePoint', 'zCircleSlider', 'zLineSlider']
0008
0009__all__ = __Classes__ + __Def__
0010
0011__doc_hints__={'m_type':'factory'}
0012
0013
0014import pygeo.base.abstracts._complex as Complex
0015from pygeo.base.abstracts._element import Element
0016
0017
0018from pygeo.base.analytics.pygeomath import math_E, tan, sqrt, array, matrixmultiply, PI, mod2
0020
0021class zFreePoint(Complex._zFreePosition):
0022 """
0023*complex point* intially at given (real,imaginary) **coordinates** that can be picked and
0024moved freely on the complex plane
0025
0026 inherits
0027
0028 `_zPoint`__
0029
0030__ class-base.abstracts._complex._zPoint.html
0031
0032 """
0033
0034 __doc_hints__= {'factory':'zSlider',
0035 'args':['float <,float>']}
0036
0037 def __init__(self,*args,**kws):
0038 Complex._zFreePosition.__init__(self,*args,**kws)
0039 self.init()
0040
0041
0042class zCircleSlider(Complex._zFreePosition):
0043 """
0044*complex point* on the given **complex circle** which can be picked, with movement constrained to
0045the given circle and with initial position determined by the 'angle' keyword.
0046
0047 inherits
0048
0049 `_zPoint`__
0050
0051__ class-base.abstracts._complex._zPoint.html
0052
0053 """
0054
0055 __doc_hints__= {'factory':'zSlider',
0056 'args':['zcircle <,angle = float>']}
0057
0058 __opts__= Complex._zPoint.__opts__[:] + ["angle"]
0059
0060 def __init__(self,zcircle,**kw):
0061 self.zcircle=zcircle
0062 self.angle=kw.get("angle",PI)*self.zcircle.a
0063 Complex._zFreePosition.__init__(self,*[zcircle],**kw)
0064 self.init()
0065
0066 def findSelf(self):
0067 circle=self.zcircle
0068 vt=self-circle._center
0069 len=vt.mod()
0070 if len:
0071 factor = circle._radius/len
0072 c = vt*factor+circle._center
0073 else:
0074 c=complex(1,0)*circle._radius+circle._center
0075 self.real=c.real
0076 self.imag=c.imag
0077 return True
0078
0079 def reset(self):
0080 self.init()
0081 Complex._zPoint.update(self)
0082
0083 def init(self):
0084 circle=self.zcircle
0085 self.set(circle._radius*(math_E**complex(0,self.angle))+circle._center)
0086 Element.init(self)
0087
0088class zLineSlider(Complex._zFreePosition):
0089 """
0090*complex point* on the given **complex line** which can be picked, with movement constrained to
0091the given line and with initial position determined by the 'ratio' keyword.
0092
0093 inherits
0094
0095 `_zPoint`__
0096
0097__ class-base.abstracts._complex._zPoint.html
0098
0099 """
0100
0101 __doc_hints__= {'factory':'zSlider',
0102 'args':['zline <,ratio = float>']}
0103
0104 __opts__= Complex._zPoint.__opts__[:] + ["ratio"]
0105
0106 def __init__(self,zline,**kw):
0107 self.zline=zline
0108 self.ratio=kw.get("ratio",.5)
0109 Complex._zFreePosition.__init__(self,*[zline],**kw)
0110 self.init()
0111
0112 def findSelf(self):
0113 p1=self.zline.p1
0114 p2=self.zline.p2
0115 vxs = p2 - p1
0116 vxt = self - p1
0117 try:
0118 factor= ((vxt.real*vxs.real+vxt.imag*vxs.imag)
0119 /vxs.mod2())
0120 self.set(vxs*factor+p1)
0121 return True
0122
0123 except ZeroDivisionError:
0124 print self.__class__.__name__
0125 print " points defining line segments are coincident. toLine returned False"
0126 return False
0127
0128
0129 def reset(self):
0130 self.init()
0131 Complex._zPoint.update(self)
0132
0133 def init(self):
0134 self.set(self.zline.p1*(1.0-self.ratio)+self.zline.p2*self.ratio)
0135 Element.init(self)
0136
0137
0138def zSlider(*args,**kws):
0139 """
0140'class factory' function returns instance of object derived from the
0141*_zPoint* abstract class representing a point of the complex plane which can be
0142picked and moved
0143 """
0144 from pygeo.base.abstracts._element import method_get
0145 from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0146
0147 __sigs__ = [[],[float,float],[complex],[float],[Complex._zCircle],[Complex._zLine]]
0148 t,i = method_get(__sigs__,args)
0149 if t is None:
0150 raise Argument_Type_Error(__sigs__,args)
0151 else:
0152 if i==0:
0153 return zFreePoint(**kws)
0154 elif i==1:
0155 return zFreePoint(t[0],t[1],**kws)
0156 elif i==2:
0157 return zFreePoint(t[0],**kws)
0158 elif i==3:
0159 return zFixedPoint(t[0],0,**kws)
0160 elif i == 4:
0161 return zCircleSlider(t[0],**kws)
0162 elif i == 5:
0163 return zLineSlider(t[0],**kws)
0164 else:
0165 raise Argument_Type_Error(__sigs__,args)