def calc_isect_nieve(): intersections = [] seen = [] vs = False hs = False es = False for seg1 in S: if helper.approx_equal(seg1[0][0], seg1[1][0], EPSILON): print('VERTICAL SEG') print('') print('') vs = True if helper.approx_equal(seg1[0][1], seg1[1][1], EPSILON): print('HORIZONTAL SEG') print('') print('') hs = True for seg2 in S: if seg1 is not seg2 and helper.segs_equal(seg1, seg2): print('EQUAL SEGS') print('') print('') es = True if seg1 is not seg2 and (seg2, seg1) not in seen: i = helper.intersect(seg1, seg2) if i: intersections.append((i, [seg1, seg2])) # xpts = [seg1[0][0], seg1[1][0], seg2[0][0], seg2[1][0]] # xpts = sorted(xpts) # if (i[0] <= xpts[2] and i[0] >= xpts[1]: # intersections.append((i, [seg1, seg2])) seen.append((seg1, seg2)) return intersections
later = time.time() isect_2 = calc_isect_nieve() now = time.time() n2time = later - now print("N^2 comparison results:", len(isect_2)) print('TIME ELAPSED:', n2time) # further sanity checks isect_1_pts_seen = [] highestseen = 0 for i in isect_2: seen_already = False seen = 0 for p in isect_1_pts_seen: if helper.approx_equal(i[0][0], p[0], EPSILON) and helper.approx_equal(i[0][1], p[1], EPSILON): seen += 1 seen_already = True if seen > highestseen: highestseen = seen if not seen_already: isect_1_pts_seen.append(i[0]) in_k = False for k in isect_1: if helper.approx_equal(k[0], i[0][0], EPSILON) and helper.approx_equal(k[1], i[0][1], EPSILON): in_k = True if in_k == False: print('Not in K: {0}: {1}'.format(i[0], i[1])) # print i print(highestseen)