def test_intersect(s1, s2): if s1 == None or s2 == None: return False # testing: s2 endpoints on the same side of s1 lsign = sideplr(s2.lp0, s1.lp0, s1.rp) rsign = sideplr(s2.rp, s1.lp0, s1.rp) if lsign * rsign > 0: return False # testing: s1 endpoints on the same side of s2 lsign = sideplr(s1.lp0, s2.lp0, s2.rp) rsign = sideplr(s1.rp, s2.lp0, s2.rp) if lsign * rsign > 0: return False return True
def __lt__(self, other): if isinstance(other, Segment): if self.lp and other.lp: lr = sideplr(self.lp, other.lp, other.rp) if lr == 0: lrr = sideplr(self.rp, other.lp, other.rp) if other.lp.x < other.rp.x: return lrr > 0 else: return lrr < 0 else: if other.lp.x > other.rp.x: return lr < 0 else: return lr > 0 return NotImplemented