/[escript]/trunk/pycad/py_src/primitives.py
ViewVC logotype

Diff of /trunk/pycad/py_src/primitives.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 919 by gross, Wed Jan 3 22:54:50 2007 UTC revision 923 by gross, Tue Jan 9 22:50:43 2007 UTC
# Line 69  class Primitive(object): Line 69  class Primitive(object):
69    
70      def __repr__(self):      def __repr__(self):
71         return "%s(%s)"%(self.__class__.__name__,self.getID())         return "%s(%s)"%(self.__class__.__name__,self.getID())
72    
73      def __cmp__(self,other):      def __cmp__(self,other):
74         return cmp(self.getID(),other.getID())         return cmp(self.getID(),other.getID())
75    
# Line 519  class Primitive2D(Primitive): Line 520  class Primitive2D(Primitive):
520            create a two-dimensional primitive            create a two-dimensional primitive
521            """            """
522            super(Primitive2D, self).__init__()            super(Primitive2D, self).__init__()
523    
524  class CurveLoop(Primitive2D):  class CurveLoop(Primitive2D):
525      """      """
526      An oriented loop of curves.      An oriented loop of curves.
# Line 530  class CurveLoop(Primitive2D): Line 532  class CurveLoop(Primitive2D):
532         creates a polygon from a list of line curves. The curves must form a closed loop.         creates a polygon from a list of line curves. The curves must form a closed loop.
533         """         """
534         super(CurveLoop, self).__init__()         super(CurveLoop, self).__init__()
535         self.__curves=[]         if len(curves)<2:
536         self.addCurve(*curves)              raise TypeError("at least two curves have to be given.")
     def addCurve(self,*curves):  
        """  
        adds curves to the curves defining the object  
        """  
537         for i in range(len(curves)):         for i in range(len(curves)):
538             if not isinstance(curves[i],Primitive1D):             if not isinstance(curves[i],Primitive1D):
539                raise TypeError("%s-th argument is not a Primitive1D object."%i)                raise TypeError("%s-th argument is not a Primitive1D object."%i)
540         self.__curves+=curves         # for the curves a loop:
541           used=[ False for i in curves]
542           self.__curves=[curves[0]]
543           used[0]=True
544           while not min(used):
545              found=False
546              for i in xrange(len(curves)):
547                 if not used[i]:
548                    if self.__curves[-1].getEndPoint() == curves[i].getStartPoint():
549                       self.__curves.append(curves[i])
550                       used[i]=True
551                       found=True
552                       break
553              if not found:
554                 raise ValueError("loop is not closed.")
555           if not self.__curves[0].getStartPoint() == self.__curves[-1].getEndPoint():
556              raise ValueError("loop is not closed.")
557    
558      def getCurves(self):      def getCurves(self):
559         """         """

Legend:
Removed from v.919  
changed lines
  Added in v.923

  ViewVC Help
Powered by ViewVC 1.1.26