Пример #1
0
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
Пример #2
0
 def find_delete_pt(self, key, value):
     if self.left and self.right:
         c = self.compare_to_key(key)
         # if equal at this pt, and this node's value
         # is less than the seg's slightly above this pt
         if c == 0 and self.compare_lower(key, value) == -1:
             return self.right.find_delete_pt(key, value)
         if c < 1:
             return self.left.find_delete_pt(key, value)
         else:
             return self.right.find_delete_pt(key, value)
     elif self.left:
         c = self.compare_to_key(key)
         if c < 1:
             return self.left.find_delete_pt(key, value)
         else:
             return None
     # is leaf
     else:
         c = self.compare_to_key(key)
         if c == 0 and helper.segs_equal(self.value, value):
             return self
         else:
             return None