예제 #1
0
 def place_text_in_largest_triangle(self):
     chosen_tri = 0
     max_area = 0
     for i in range(1, len(self.triangles)):
         a = util.area_of_triangle(self.triangles[i])
         if a > max_area:
             max_area = a
             chosen_tri = i
     tri = self.triangles[chosen_tri]
     self.x = tri[0] + tri[2] + tri[4]
     self.y = tri[1] + tri[3] + tri[5]
     self.x /= 3.0
     self.y /= 3.0
예제 #2
0
 def place_text_old(self):
     #This is a complicated block of code which attempts to place the text
     #label in a sane place using a variety of methods.
     self.points = []
     for line in self.lines:
         if line.a not in self.points:
             self.points.append(line.a.get_tuple())
         if line.b not in self.points:
             self.points.append(line.b.get_tuple())
     self.x = 0.0
     self.y = 0.0
     for point in self.points:
         self.x += point[0]
         self.y += point[1]
     self.x /= len(self.points)
     self.y /= len(self.points)
     
     ok = True
     if not self.point_inside(self.x, self.y): ok = False
     if not self.point_inside(self.x+15, self.y): ok = False
     if not self.point_inside(self.x-15, self.y): ok = False
     if not self.point_inside(self.x, self.y+15): ok = False
     if not self.point_inside(self.x, self.y-15): ok = False
     if ok:
         self.place_piece()
         return
     
     chosen_tri = 0
     max_area = 0
     for i in range(1, len(self.triangles)):
         a = util.area_of_triangle(self.triangles[i])
         if a > max_area:
             max_area = a
             chosen_tri = i
     tri = self.triangles[chosen_tri]
     self.x = tri[0] + tri[2] + tri[4]
     self.y = tri[1] + tri[3] + tri[5]
     self.x /= 3.0
     self.y /= 3.0
     self.place_piece()