Beispiel #1
0
def test_dragging_without_edit_mode(polygon: Polygon):

    assume(len(polygon) > 4)

    canvas = PolygonAnnotationCanvas()
    canvas.editing = False
    canvas.polygons = [polygon]

    point_to_drag = polygon.points[0]
    point_target = (50, 50)

    canvas.on_click(*point_to_drag)
    canvas.on_drag(*point_target)

    # test point has not moved
    assert canvas.polygons[0].points[0] == point_to_drag
Beispiel #2
0
def test_drawing_invokes_canvas_fill_arc_in_edit_mode(data: List[Polygon]):

    assume(len(data) > 1)
    canvas = PolygonAnnotationCanvas()
    canvas.load_image(IMAGE)
    print(canvas.image_extent)
    canvas.editing = True

    with patch.object(ipycanvas.Canvas, "fill_arcs") as mock_fill_arcs:
        canvas.data = [poly.data for poly in data]

    for polygon in data:
        for point in polygon.points:
            assert canvas.image_to_canvas_coordinates(point) == point

        if len(polygon.points) > 1:
            mock_fill_arcs.assert_any_call(
                polygon.xy_lists[0],
                polygon.xy_lists[1],
                canvas.point_size,
                0,
                2 * pi,
            )
Beispiel #3
0
def test_editing_mode(polygon: Polygon, polygons: List[Polygon]):

    assume(len(polygon) > 2)

    canvas = PolygonAnnotationCanvas()
    # canvas.polygons = polygons
    canvas.current_polygon = polygon

    pre_move_points = polygon.points.copy()

    canvas.editing = True
    # test that dragging is none by default
    assert canvas.dragging is None

    # clicking on a point sets drag function:
    point_to_drag = polygon.points[0]
    point_target = (50, 50)
    canvas.on_click(*point_to_drag)
    assert canvas.dragging is not None

    # moving mouse moves the point:
    canvas.on_drag(*point_target)
    canvas.on_release(*point_target)

    # test point has moved
    assert canvas.current_polygon.points[0] == (50, 50)
    # test everything else stayed put
    assert canvas.current_polygon.points[1:] == pre_move_points[1:]

    # test release re-set dragging
    assert canvas.dragging is None

    # test undoing moves the point back
    callback = canvas._undo_queue.pop()
    callback()
    assert canvas.current_polygon.points == pre_move_points