def intersections(self, p1, p2): result = [] # Manually include the wrap-around, so we get all segments. for (p3, p4) in utils.list_pairs( self.pts + [self.pts[0]] ): isec = _point_intersect(p1,p2,p3,p4) if isec is not None: # Exclude intersections resulting from end-point adjacency. if isec!=p1 and isec!=p2: result.append(isec) return result
def intersections(self, p1, p2): result = [] # Manually include the wrap-around, so we get all segments. for (p3, p4) in utils.list_pairs(self.pts + [self.pts[0]]): isec = _point_intersect(p1, p2, p3, p4) if isec is not None: # Exclude intersections resulting from end-point adjacency. if isec != p1 and isec != p2: result.append(isec) return result
def draw_contourmap(self, gfxwindow, device): # If the drawing failed, then contour_max won't have been set # yet. self.lock.acquire() try: if self.contour_max is not None: if config.dimension() == 2: aspect_ratio = gfxwindow.settings.aspectratio height = self.contour_max - self.contour_min width = height/aspect_ratio device.comment("Colorbar minimum: %s" % self.contour_min) device.comment("Colorbar maximum: %s" % self.contour_max) device.set_colormap(self.colormap) for low, high in utils.list_pairs(self.contour_levels): # Subtract "contour_min" off the y coords, so that # the drawn object will include the point (0,0) -- # otherwise, the canvas bounds are wrong. r_low = low-self.contour_min r_high = high-self.contour_min rect_bndy = map( lambda x: primitives.Point(x[0],x[1]), [ (0.0, r_low), (0.0, r_high), (width, r_high), (width, r_low) ] ) rectangle = primitives.Polygon(rect_bndy) # In the collapsed case, height can be zero. This is # not hugely informative, but should be handled without # crashing. if height>0.0: device.set_fillColor(r_low/height) else: device.set_fillColor(0.0) device.fill_polygon(rectangle) elif config.dimension() == 3: if self.lookuptable: device.draw_scalarbar(self.lookuptable) finally: self.lock.release()
def draw_contourmap(self, gfxwindow, device): # If the drawing failed, then contour_max won't have been set # yet. self.lock.acquire() try: if self.contour_max is not None: if config.dimension() == 2: aspect_ratio = gfxwindow.settings.aspectratio height = self.contour_max - self.contour_min width = height / aspect_ratio device.comment("Colorbar minimum: %s" % self.contour_min) device.comment("Colorbar maximum: %s" % self.contour_max) device.set_colormap(self.colormap) for low, high in utils.list_pairs(self.contour_levels): # Subtract "contour_min" off the y coords, so that # the drawn object will include the point (0,0) -- # otherwise, the canvas bounds are wrong. r_low = low - self.contour_min r_high = high - self.contour_min rect_bndy = map(lambda x: primitives.Point(x[0], x[1]), [(0.0, r_low), (0.0, r_high), (width, r_high), (width, r_low)]) rectangle = primitives.Polygon(rect_bndy) # In the collapsed case, height can be zero. This is # not hugely informative, but should be handled without # crashing. if height > 0.0: device.set_fillColor(r_low / height) else: device.set_fillColor(0.0) device.fill_polygon(rectangle) elif config.dimension() == 3: if self.lookuptable: device.draw_scalarbar(self.lookuptable) finally: self.lock.release()