def intersectsWall(self, C,D): p1 = self.left_point.vec2tuple() p2 = self.right_point.vec2tuple() p3 = C.position.vec2tuple() p4 = D.position.vec2tuple() x = calculateIntersectPoint(p1,p2,p3,p4) if not x: return False else: return True
def find_loops(point_dict): points = point_dict.values() padding = 100 points = [(p1*padding, p2*padding) for (p1,p2) in points] #print points lines = [] for i, point in enumerate(points): if (i < (len(points)-1)): lines.append((point, points[i+1])) intersection_indices = [] intersection_points = [] intersections = {} for a, lineA in enumerate(lines): for b, lineB in enumerate(reversed(lines)): intersection = geometry.calculateIntersectPoint(lineA[0], lineA[1], lineB[0], lineB[1]) if intersection != None and (lineA != lineB): #print intersection, a, len(lines)-b-1 # if the geometry library intersection method finds # an intersection which is one of the points in the original # list/dictionary of points, ignore it point_not_found = True if (intersection[0],intersection[1]) in points: point_not_found = False # if the geometry library intersection method finds # an intersection which was already found, ignore it intersection_not_found = True if intersection in intersection_points: intersection_not_found = False # don't bother adding loops within loops intersection_within_not_found = True for idx in intersection_indices: if a > idx[0] and len(lines)-b-1 < idx[1] and a < len(lines)-b-1: print idx, a, len(lines)-b-1 intersection_within_not_found = False if point_not_found and intersection_not_found and intersection_within_not_found: intersection_indices.append((a,len(lines)-b-1)) intersection_points.append(intersection) intersections[(a,len(lines)-b-1)] = [intersection[0]/padding, intersection[1]/padding] print intersections return intersections