0001"""
0002**point** determined as antipodal (i.e.'opposite') to a given point in 
0003relation to a given geometric object 
0004
0005"""
0006
0007__Def__ =       ['AntiPodal']
0008
0009__Classes__ =   ['CircleAntiPodal', 'SphereAntiPodal','LineAntiPodal']
0010
0011__all__= __Classes__ + __Def__
0012
0013__doc_hints__=  {'m_type':'factory'}
0014
0015import pygeo.base.abstracts._real as Real
0016from pygeo.base.support.pygeoopts import DO_TESTS
0017
0018class CircleAntiPodal(Real._Point):
0019    """
0020*point* on the given **circle** diametrically opposite to the given **point**
0021
0022    inherits
0023    
0024        `_Point`__
0025
0026__ base.abstracts._real._Point.html        
0027
0028    """
0029    __doc_hints__=  {'factory':'AntiPodal',
0030                    'args':['circle,point'],
0031                    'conditions':['point and circle are coplanar','point not circle center'],
0032                    'otherwise': 'None ;  None'}
0033
0034    def __init__(self,circle,point,**kws):
0035        self.circle=circle
0036        self.point=point
0037        Real._Point.__init__(self,*[circle,point],**kws)
0038        self.init()
0039
0040    def findSelf(self):
0041        if DO_TESTS:
0042            t=self.point.onPlane(self.circle)
0043        else:
0044            t=True
0045        if t:
0046            return self.toOpposite(self.circle,self.point)
0047        else:
0048            print self.__class__.__name__
0049            print """circle and point not coplanar, antipodal undefined, 
0050                    returned False"""
0051            return False
0052
0053
0054class SphereAntiPodal(Real._Point):
0055    """
0056*point* on the given **sphere** diametrically opposite to the given **point**
0057
0058    inherits
0059    
0060        `_Point`__
0061
0062__ base.abstracts._real._Point.html        
0063
0064    """
0065    __doc_hints__=  {'factory':'AntiPodal',
0066                    'args':['sphere,point'],
0067                    'conditions':['point not sphere center'],
0068                    'otherwise': 'None'}
0069
0070    def __init__(self,sphere,point,**kws):
0071        self.sphere=sphere
0072        self.point=point
0073        Real._Point.__init__(self,*[sphere,point],**kws)
0074        self.init()
0075
0076    def findSelf(self):
0077        return self.toOpposite(self.sphere,self.point)
0078
0079
0080class LineAntiPodal(Real._Point):
0081    """
0082*point* of **line** segment farthest from the given **point** of the line
0083    
0084    inherits
0085    
0086        `_Point`__
0087
0088__ base.abstracts._real._Point.html        
0089    
0090    """
0091
0092    __doc_hints__=  {'factory':'AntiPodal',
0093                    'args':['line, point'],
0094                    'conditions':['point on line'],
0095                    'otherwise': 'None'}
0096
0097    __opts__= Real._Point.__opts__[:]
0098
0099    def __init__(self,line,point,**kws):
0100        self.line=line
0101        self.point=point
0102        Real._Point.__init__(self,*[line,point], **kws)
0103        self.init()
0104
0105    def findSelf(self):
0106        d1=self.line.p1.distance(self.point)
0107        d2=self.line.p2.distance(self.point)
0108        if d1 > d2:
0109            self.set(self.line.p1)
0110        else:
0111            self.set(self.line.p2)
0112        return True
0113
0114
0115
0116
0117def AntiPodal(*args,**kws):
0118    """
0119'class factory' function returns instance of object derived from the 
0120*_Point* abstract class determined as antipodal (i.e.'opposite') to a given point in 
0121relation to a given geometric object
0122    """
0123
0124    from pygeo.base.abstracts._element import method_get
0125    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0126    from pygeo.base.analytics.pygeomath import vector
0127
0128    __sigs__=__sigs__=[[Real._Circle,vector],[Real._Sphere,vector],
0129                        [Real._Line, Real._Point]]
0130
0131    t,i=method_get(__sigs__,args)
0132
0133    if t is  None:
0134        raise Argument_Type_Error(__sigs__,args)
0135    else:
0136        if i==0:
0137            return CircleAntiPodal(t[0],t[1],**kws)
0138        elif i==1:
0139            return SphereAntiPodal(t[0],t[1],**kws)
0140        elif i==2:
0141            return LineAntiPodal(t[0],t[1],**kws)
0142        else:
0143            raise Argument_Type_Error(__sigs__,args)