Generation

docstringSat, 12 Nov 2022

def segs_intersect(start1: Vec, end1: Vec, start2: Vec, end2: Vec) -> bool: if any(not isinstance(v, Vec) for v in [start1, end1, start2, end2]): raise TypeError("incorrect type for segment intersection: {}, {}, {}, and {}".format( type(start1), type(end1), type(start2), type(end2))) elif any(start1.dim() != v.dim() for v in [end1, start2, end2]): raise ValueError("dimension mismatch for vector cross product: {}, {}, {}, and {}".format( start1.dim(), end1.dim(), start2.dim(), end2.dim())) elif start1.dim() != 2: raise NotImplementedError("only implemented for 2D vectors") else: return ( cross(end1 - start1, start2 - start1) * cross(end1 - start1, end2 - start1) < 0 and cross(end2 - start2, start1 - start2) * cross(end2 - start2, end1 - start2) < 0 )

This allows the following:

Questions about programming?Chat with your personal AI assistant