Ejemplo n.º 1
0
 def add_edge(self, region, pt1, pt2):
     """ Add edge handles to region
     Also adds corner handles
     """
     edge = self.get_edge_with(pt1, pt2)
     if edge is None:
         edge = SelectPart("edge", rect=[pt1,pt2])
         self.add_part(edge)
     self.add_corners(region, [pt1, pt2], edge=edge)     # So we get corners
     region.add_connected(edge)
Ejemplo n.º 2
0
 def add_rect(self, rect):
     """ Add rectangle to object as another region
     """                
     rec_ps = [None] * 4
     ulX, ulY = rect[0][0], rect[0][1]
     lrX, lrY = rect[1][0], rect[1][1]
     sr = SelectPart("region", rect=[(ulX,ulY),(lrX,lrY)])   # Just one region now
     self.regions.append(sr)         # Add region
     self.add_part(sr)       
     rec_ps[0] = (ulX, ulY)
     rec_ps[1] = (lrX, ulY) 
     rec_ps[2] = (lrX, lrY)
     rec_ps[3] = (ulX, lrY)
     for pi1 in range(0, 3+1):
         pi2 = pi1 + 1
         if pi2 >= len(rec_ps):
             pi2 = 0          # Ends at first
         pt1 = rec_ps[pi1]
         pt2 = rec_ps[pi2]
         self.add_edge(sr, pt1, pt2)
Ejemplo n.º 3
0
 def add_corners(self, region, points, edge=None):
     """ Add corners to region
     :region: region to which to add corners
     :points: one or more corner locations
     If corner == first corner, set region enclosed
     but DON't add corner
     """
     if not isinstance(points, list):
         points = [points]     # Treat as an array of one
     for point in points:
         if self.is_first_corner(point):
             self.is_enclosed = True
         if self.has_corner(point):
             corner = self.get_corner_part(point[0], point[1])
         else:
             corner = SelectPart("corner", point=point)
         self.add_part(corner)       # Add new corners
             
         region.add_connected(corner)
         if edge is not None:
             corner.add_connected(edge)      # Connect edge to corner
             edge.add_connected(corner)      # Connect corner to edge