def gen_noncrossing_edges(query_edges, boundary_edges, allpoints): """ Yield query edges which do not intersect boundary edges. @param query_edges: point index pairs @param boundary_edges: point index pairs @param allpoints: ordered points as pairs of coordinates """ for query in query_edges: q0 = CompGeom.Point(allpoints[query[0]]) q1 = CompGeom.Point(allpoints[query[1]]) for boundary in boundary_edges: b0 = CompGeom.Point(allpoints[boundary[0]]) b1 = CompGeom.Point(allpoints[boundary[1]]) if CompGeom.line_segments_intersect(q0, q1, b0, b1): break else: yield query
def get_intersecting_edges(points, edges): """ Edges that share an endpoint do not count as conflicting. @param points: a list of numpy arrays each of length 2 @param edges: a list of point index pairs @return: the set of edges that intersect at least one other edge """ conflicts = set() sedgewick_points = [CompGeom.Point(p.tolist()) for p in points] for ea, eb in itertools.combinations(edges, 2): # only check intersection when each endpoint is unique if len(set([ea[0], ea[1], eb[0], eb[1]])) == 4: a = sedgewick_points[ea[0]] b = sedgewick_points[ea[1]] c = sedgewick_points[eb[0]] d = sedgewick_points[eb[1]] if CompGeom.line_segments_intersect(a, b, c, d): conflicts.add(ea) conflicts.add(eb) return conflicts