/[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 917 by gross, Tue Jan 2 02:46:53 2007 UTC revision 919 by gross, Wed Jan 3 22:54:50 2007 UTC
# Line 353  class Curve(Primitive1D): Line 353  class Curve(Primitive1D):
353            if len(primitive) == len(self):            if len(primitive) == len(self):
354               cp0=self.getControlPoints()               cp0=self.getControlPoints()
355               cp1=primitive.getControlPoints()               cp1=primitive.getControlPoints()
356                 match=True
357               for i in range(len(cp0)):               for i in range(len(cp0)):
358                  if not cp0[i].isColocated(cp1[i]):                  if not cp0[i].isColocated(cp1[i]):
359                     return False                     match=False
360                       break
361                 if not match:
362                    for i in range(len(cp0)):
363                       if not cp0[i].isColocated(cp1[len(cp0)-1-i]):
364                          return False
365               return True               return True
366            else:            else:
367               return False               return False
# Line 498  class Arc(Primitive1D): Line 504  class Arc(Primitive1D):
504         returns True curves are on the same position         returns True curves are on the same position
505         """         """
506         if isinstance(primitive,Arc):         if isinstance(primitive,Arc):
507              if not self.getCenterPoint().isColocated(primitive.getCenterPoint()): return False              return (self.getCenterPoint().isColocated(primitive.getCenterPoint())) and ( \
508              if not self.getEndPoint().isColocated(primitive.getEndPoint()): return False                     (self.getEndPoint().isColocated(primitive.getEndPoint()) and self.getStartPoint().isColocated(primitive.getStartPoint()) ) \
509              if not self.getStartPoint().isColocated(primitive.getStartPoint()): return False                  or (self.getEndPoint().isColocated(primitive.getStartPoint()) and self.getStartPoint().isColocated(primitive.getEndPoint()) ) )
             return True  
510         else:         else:
511            return False            return False
512    
513  #=================================================================================================================================  class Primitive2D(Primitive):
514  class CurveLoop(Primitive):        """
515          general two-dimensional primitive
516          """
517          def __init__(self,*args):
518              """
519              create a two-dimensional primitive
520              """
521              super(Primitive2D, self).__init__()
522    class CurveLoop(Primitive2D):
523      """      """
524      An oriented loop of curves.      An oriented loop of curves.
525    
# Line 520  class CurveLoop(Primitive): Line 533  class CurveLoop(Primitive):
533         self.__curves=[]         self.__curves=[]
534         self.addCurve(*curves)         self.addCurve(*curves)
535      def addCurve(self,*curves):      def addCurve(self,*curves):
536           """
537           adds curves to the curves defining the object
538           """
539         for i in range(len(curves)):         for i in range(len(curves)):
540             if not curves[i].isCurve():             if not isinstance(curves[i],Primitive1D):
541                raise TypeError("%s-th argument is not a Curve object."%i)                raise TypeError("%s-th argument is not a Primitive1D object."%i)
542         self.__curves+=curves         self.__curves+=curves
543    
     def isCurveLoop(self):  
         return True  
544      def getCurves(self):      def getCurves(self):
545           """
546           returns the curves defining the CurveLoop
547           """
548         return self.__curves         return self.__curves
     def __add__(self,other):  
        return CurveLoop(*tuple([c+other for c in self.getCurves()[::-1]]))  
549      def __len__(self):      def __len__(self):
550           """
551           return the number of curves in the CurveLoop
552           """
553         return len(self.__curves)         return len(self.__curves)
554    
555      def getPrimitives(self):      def getPrimitives(self):
556            out=set([self])         """
557            for i in self.getCurves(): out|=i.getPrimitives()         returns primitives used to construct the CurveLoop
558            return out         """
559      def getConstructionPoints(self):         out=set()
560            out=set()         for c in self.getCurves(): out|=set(c.getPrimitives())
561            for i in self.getCurves(): out|=i.getConstructionPoints()         out.add(self)
562            return out         return list(out)
563    
564        def copy(self):
565           """
566           returns a deep copy
567           """
568           new_c=[]
569           for c in self.getCurves(): new_c.append(c.copy())
570           return CurveLoop(*tuple(new_c))
571    
572    
573        def apply(self,transformation):
574            """
575            applies transformation
576            """
577            new_c=[]
578            for c in self.getCurves(): new_c.append(c.apply(transformation))
579            return CurveLoop(*tuple(new_c))
580    
581        def isColocated(self,primitive):
582           """
583           returns True if each curve is collocted with a curve in primitive
584           """
585           if isinstance(primitive,CurveLoop):
586              if len(primitive) == len(self):
587                 cp0=self.getCurves()
588                 cp1=primitive.getCurves()
589                 for c0 in cp0:
590                     collocated = False
591                     for c1 in cp1: collocated = collocated or c0.isColocated(c1)
592                     if not collocated: return False
593                 return True
594              else:
595                 return False
596           else:
597              return False
598    
599      def getGmshCommand(self):      def getGmshCommand(self):
600          out=""          out=""
601          for i in self.getCurves():          for i in self.getCurves():
# Line 550  class CurveLoop(Primitive): Line 605  class CurveLoop(Primitive):
605                  out="%s"%i.getID()                  out="%s"%i.getID()
606          return "Line Loop(%s) = {%s};"%(self.getID(),out)          return "Line Loop(%s) = {%s};"%(self.getID(),out)
607    
608    #=================================================================================================================================
609  class Surface(Primitive):  class Surface(Primitive):
610      """      """
611      a surface      a surface

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

  ViewVC Help
Powered by ViewVC 1.1.26