class Area (Drawable): def __init__ (self, onto): Drawable.__init__ (self, onto) self.table = Table () self.a = (0, 0) self.b = (10, 10) self.result = None def draw (self): self.reset () for o in self.table.obstacles: if o.pos is None: continue if isinstance (o, RoundObstacle): self.draw_circle (o.pos, o.radius) elif isinstance (o, RectangularObstacle): self.trans_push () self.trans_translate (o.pos) self.trans_rotate (o.angle) self.draw_circle ((0, 0), 0.2) self.draw_rectangle ((o.dim[0] / 2, o.dim[1] / 2), (-o.dim[0] / 2, -o.dim[1] / 2), fill = '') self.trans_pop () elif isinstance (o, PolygonalObstacle): self.trans_push () self.trans_translate (o.pos) self.trans_rotate (o.angle) self.draw_circle ((0, 0), 0.2) self.draw_polygon (*o.points, fill = '', outline = 'black') self.trans_pop () else: raise TypeError ("unknown obstacle") if self.a is not None: self.draw_circle (self.a, 0.2, fill = 'green') if self.b is not None: self.draw_circle (self.b, 0.2, fill = 'red') if self.a is not None and self.b is not None: self.draw_line (self.a, self.b, arrow = 'last') if self.result is not None: self.draw_circle (self.result, 0.2, fill = 'yellow') def update (self, test, **kwargs): self.result = None if self.a is not None and self.b is not None: if test == 'intersect': def nearer (a, b): return a < b i = self.table.intersect (self.a, self.b, comp = nearer, **kwargs) if i is not None: a, b = vector (self.a), vector (self.b) self.result = a + (b - a).unit () * i.distance elif test == 'nearest': n = self.table.nearest (self.b, **kwargs) if n is not None: self.result = n.pos
def __init__ (self, onto): Drawable.__init__ (self, onto) self.table = Table () self.a = (0, 0) self.b = (10, 10) self.result = None