Example #1
0
def test_transformed_path():
    points = [(0, 0), (1, 0), (1, 1), (0, 1)]
    codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
    path = Path(points, codes)

    trans = mtrans.Affine2D()
    trans_path = TransformedPath(path, trans)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       points)

    # Changing the transform should change the result.
    r2 = 1 / np.sqrt(2)
    trans.rotate(np.pi / 4)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])

    # Changing the path does not change the result (it's cached).
    path.points = [(0, 0)] * 4
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])
Example #2
0
def test_transformed_path():
    points = [(0, 0), (1, 0), (1, 1), (0, 1)]
    codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
    path = Path(points, codes)

    trans = mtrans.Affine2D()
    trans_path = TransformedPath(path, trans)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       points)

    # Changing the transform should change the result.
    r2 = 1 / np.sqrt(2)
    trans.rotate(np.pi / 4)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])

    # Changing the path does not change the result (it's cached).
    path.points = [(0, 0)] * 4
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])