def test_step(contour: Contour) -> None: first_vertex, *rest_vertices = contour result = edges_intersect(rest_vertices) next_result = edges_intersect(contour) first_edge, last_edge = ((first_vertex, rest_vertices[0]), (rest_vertices[-1], first_vertex)) rest_edges = contour_to_segments(rest_vertices) assert (next_result is (result and len(rest_vertices) > 2 and (any( segments_intersections(rest_edges[index], rest_edges[other_index]) for index in range(len(rest_edges) - 1) for other_index in chain(range(index - 1), range(index + 2, len(rest_edges) - 1)) ) or any( segments_relationship(edge, other_edge) is SegmentsRelationship.OVERLAP for edge, other_edge in combinations(rest_edges[:-1], 2))) or any( segments_intersections(first_edge, edge) for edge in rest_edges[1:-1]) or any( segments_intersections(last_edge, edge) for edge in rest_edges[:-2]) or len(rest_vertices) > 1 and (segments_relationship(first_edge, rest_edges[0]) is SegmentsRelationship.OVERLAP or segments_relationship(first_edge, last_edge) is SegmentsRelationship.OVERLAP or segments_relationship(last_edge, rest_edges[0]) is SegmentsRelationship.OVERLAP)))
def test_step(context: Context, contour: Contour) -> None: first_vertex, *rest_vertices = contour.vertices rest_contour = Contour(rest_vertices) result = edges_intersect(rest_contour) next_result = edges_intersect(contour) first_edge, last_edge = (Segment(first_vertex, rest_vertices[0]), Segment(rest_vertices[-1], first_vertex)) rest_edges = contour_to_edges(rest_contour) overlap_relations = (Relation.COMPONENT, Relation.COMPOSITE, Relation.EQUAL, Relation.OVERLAP) assert (next_result is (result and len(rest_vertices) > 2 and (any( segments_pair_intersections( rest_edges[index].start, rest_edges[index].end, rest_edges[other_index].start, rest_edges[other_index].end) for index in range(len(rest_edges) - 1) for other_index in chain(range(index - 1), range(index + 2, len(rest_edges) - 1)) ) or any( segments_pair_intersections(edge.start, edge.end, other_edge.start, other_edge.end) in overlap_relations for edge, other_edge in combinations(rest_edges[:-1], 2))) or any( segments_pair_intersections(first_edge.start, first_edge.end, edge.start, edge.end) for edge in rest_edges[1:-1]) or any( segments_pair_intersections(last_edge.start, last_edge.end, edge.start, edge.end) for edge in rest_edges[:-2]) or len(rest_vertices) > 1 and ( context.segments_relation( first_edge.start, first_edge.end, rest_edges[0].start, rest_edges[0].end) in overlap_relations or context.segments_relation(first_edge.start, first_edge.end, last_edge.start, last_edge.end) in overlap_relations or context.segments_relation( last_edge.start, last_edge.end, rest_edges[0].start, rest_edges[0].end) in overlap_relations)))
def test_degenerate_contour(contour: Contour) -> None: with pytest.raises(ValueError): edges_intersect(contour)
def test_reversed_coordinates(contour: Contour) -> None: result = edges_intersect(contour) assert result is edges_intersect( [reverse_point_coordinates(vertex) for vertex in contour])
def test_reversed(contour: Contour) -> None: result = edges_intersect(contour) assert result is edges_intersect(contour[::-1])
def test_base_case(contour: Contour) -> None: result = edges_intersect(contour) left_vertex, mid_vertex, right_vertex = sorted(contour) assert result is segment_contains((left_vertex, right_vertex), mid_vertex)
def test_basic(contour: Contour) -> None: result = edges_intersect(contour) assert isinstance(result, bool)
def check_for_self_intersection(pts): context = get_context() Point, Contour = context.point_cls, context.contour_cls ctr = [ Point(a,b) for [a,b] in pts ] curve = Contour(ctr) return edges_intersect(curve)
def test_reversed_coordinates(contour: Contour) -> None: result = edges_intersect(contour) assert result is edges_intersect(reverse_contour_coordinates(contour))
def test_base_case(context: Context, contour: Contour) -> None: result = edges_intersect(contour) left_vertex, mid_vertex, right_vertex = sorted(contour.vertices) assert result is context.segment_contains_point(left_vertex, right_vertex, mid_vertex)