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)]
    path = Path(points, closed=True)

    trans = mtransforms.Affine2D()
    trans_path = mtransforms.TransformedPath(path, trans)
    assert_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_allclose(trans_path.get_fully_transformed_path().vertices,
                    [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)],
                    atol=1e-15)

    # Changing the path does not change the result (it's cached).
    path.points = [(0, 0)] * 4
    assert_allclose(trans_path.get_fully_transformed_path().vertices,
                    [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)],
                    atol=1e-15)
Example #3
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)])