0001"""
0002**point** which moves on a given geometric object at each rendering update cyle
0003
0004"""
0005
0006__Def__ =       ['AniPoint']
0007
0008__Classes__ =   [ 'CirclingPoint', 'SlidingPoint']
0009
0010__all__= __Classes__ + __Def__
0011
0012__doc_hints__={'m_type':'factory'}
0013
0014
0015import pygeo.base.abstracts._real as Real
0016
0017from pygeo.base.analytics.pygeomath import PI
0018from pygeo.base.abstracts._element import Element
0019from pygeo.base.support.pygeoopts import MAX
0020from pygeo.base.analytics._position3 import Position3
0021
0022
0023class CirclingPoint(Real._Point):
0024    """
0025*point* which moves along given **circle** at each update cyle
0026    
0027    inherits
0028    
0029        `_Point`__
0030
0031__ base.abstracts._real._Point.html        
0032    """
0033
0034    __doc_hints__=  {'factory':'AniPoint',
0035                    'args':['circle, <rate=integer>,<angle=numeric>']}
0036    __opts__= Real._Point.__opts__[:] + ["rate","angle"]
0037
0038    def __init__(self,circle,angle=0,**kws):
0039        self.circle=circle
0040        self.rate=kws.get("rate",36)
0041        self.rad=2.*PI/(self.rate)
0042        self.angle=angle
0043        self.delta=angle
0044        Real._Point.__init__(self, *[circle],**kws)
0045        self.init()
0046
0047    def findSelf(self):
0048        self-=self.circle._center
0049        self.set(self.rotate(self.rad, self.circle._u))
0050        self+=self.circle._center
0051        return True
0052
0053
0054    def init(self):
0055        self.set(self.circle._cpoint)
0056        self.toCircumPoint(self.circle,self.angle-self.rad)
0057        Element.init(self)
0058
0059
0060class SlidingPoint(Real._Point):
0061    """
0062*point* which moves along the given **line** at each update cylce
0063    
0064    inherits
0065    
0066        `_Point`__
0067
0068__ base.abstracts._real._Point.html        
0069    """
0070    __doc_hints__=  {'factory':'AniPoint',
0071                    'args':['line, <rate=integer>,<ratio=numeric>']}
0072
0073    __opts__= Real._Point.__opts__[:] + ["rate","ratio"]
0074
0075    def __init__(self,line,ratio=0,**kws):
0076        self.line=line
0077        self.rate=kws.get('rate',36)
0078        self.ratio=ratio
0079        self.xdelta=1.0/self.rate
0080        self.delta=self.ratio
0081        self.maxplus=Position3(MAX*self.line.getDirection()+self.line.p2)
0082        self.maxminus=Position3(-MAX*self.line.getDirection()+self.line.p1)
0083        Real._Point.__init__(self, *[line],**kws)
0084        self.init()
0085
0086    def findSelf(self):
0087        if self.line.seg:
0088            self.toInterpolated(self.line.p1,self.line.p2,self.delta)
0089        else:
0090            self.maxplus.set(MAX*self.line.getDirection()+self.line.p2)
0091            self.maxminus.set(-MAX*self.line.getDirection()+self.line.p1)
0092            self.toInterpolated(self.maxplus,self.maxminus,self.delta)
0093        self.delta+=self.xdelta
0094        return True
0095
0096    def init(self):
0097        if self.line.seg:
0098            self.toInterpolated(self.line.p1,self.line.p2,self.ratio)
0099        else:
0100            self.toInterpolated(self.maxplus,self.maxminus,self.ratio)
0101        Element.init(self)
0102
0103
0104def AniPoint(*args,**kws):
0105    """
0106'class factory' function returns instance of object derived from the _Point 
0107abstract class which moves in relation to a given geometric object at each 
0108update cyle
0109    """
0110
0111    from pygeo.base.abstracts._element import method_get
0112    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0113
0114    __sigs__ = [[Real._Circle],[Real._Circle,float],[Real._Line],[Real._Line,float]]
0115
0116    t,i = method_get(__sigs__,args)
0117
0118    if t is None:
0119        raise Argument_Type_Error(__sigs__,args)
0120    else:
0121        if i == 0:
0122            return CirclingPoint(t[0],**kws)
0123        elif i == 1:
0124            return CirclingPoint(t[0],t[1],**kws)
0125        elif i == 2:
0126            return SlidingPoint(t[0],**kws)
0127        elif i == 3:
0128            return SlidingPoint(t[0],t[1],**kws)
0129        else:
0130            raise Argument_Type_Error(__sigs__,args)