示例#1
0
  def __cmp__(self, other):    
    if other is None:
      return -1

    other_x, other_y = xy.extract(other)
    if abs(self.x - other_x) < .01 and abs(self.y - other_y) < .01:
      return 0
      
    return cmp(self.x, other.x)
示例#2
0
def nearest_edge(rects, *args):
  x,y = xy.extract(*args)
  
  class Result:
    min_dist = nearest_rect = nearest_edge = None

  result = Result()

  for rect in rects:
    edge = directions.west
    for midpoint in rect.midpoints():
      d = dist.dist([x,y], midpoint)
      if result.min_dist == None or d < result.min_dist:
        result.min_dist = d
        result.nearest_rect = rect
        result.nearest_edge = edge
      edge += 1
  return result
示例#3
0
 def __sub__(self, other):
   x,y = xy.extract(other)
   return self.__class__(self.x - x, self.y - y)
示例#4
0
 def __add__(self, other):
   x, y = xy.extract(other)
   return self.__class__(self.x + x, self.y + y)
示例#5
0
 def set(self, *args):
   self.x, self.y = xy.extract(*args)
示例#6
0
def angle(p1, p2):  
  x1, y1 = xy.extract(p1)
  x2, y2 = xy.extract(p2)
  rel_x, rel_y = x2 - x1, y2 - y1
  angle = math.atan2(rel_y, rel_x) * 180. / math.pi
  return angles.wrap_angle(angle)