Пример #1
0
def test_inversions_repaired(simple_mesh):
    center = [0.5, 0.5, 0.5]

    orig_points = simple_mesh.points
    orig_triangles = simple_mesh.cells_dict["triangle"]
    assert center in Volume(orig_points, orig_triangles)

    inv_triangles = orig_triangles[:, ::-1]
    assert center not in Volume(orig_points, inv_triangles)

    assert center in Volume(orig_points, inv_triangles, validate=True)
Пример #2
0
def test_points(mesh):
    points = mesh.points
    vol = Volume(mesh.points, mesh.cells_dict["triangle"])

    actual = sorted(tuple(p) for p in vol.points)
    expected = sorted(tuple(p) for p in points)
    assert actual == expected
Пример #3
0
def test_near_miss(simple_volume: Volume, steps, angle):
    if angle == "edge":
        start_stop = np.array(
            [
                [-0.5, 0.5, 0.5],
                [0.5, 0.5, -0.5],
            ],
            PRECISION,
        )
    elif angle == "face":
        start_stop = np.array(
            [
                [-1, 0.5, 0],
                [2, 0.5, 0],
            ],
            PRECISION,
        )
    else:
        raise ValueError(
            "Unknown angle '{}', wanted 'edge' or 'face'".format(angle))

    expected_hit = steps >= 0
    fill = np.inf if expected_hit else -np.inf
    toward = np.full(2, fill, PRECISION)

    for _ in range(abs(steps)):
        start_stop[:, 2] = np.nextafter(start_stop[:, 2], toward)

    idxs, _, _ = simple_volume.intersections([start_stop[0]], [start_stop[1]])
    result_hit = len(idxs) > 0
    assert expected_hit == result_hit
Пример #4
0
def test_extents_validity(mesh):
    points = mesh.points
    vol = Volume(mesh.points, mesh.cells_dict["triangle"])

    expected = np.array([points.min(axis=0), points.max(axis=0)], np.float32)
    actual = vol.extents
    assert np.allclose(expected, actual)
Пример #5
0
def test_ncollpyde_contains_threaded(mesh, sample_points, expected, benchmark,
                                     threads):
    if threads > CPU_COUNT:
        pytest.skip(f"Wanted {threads} threads, only have {CPU_COUNT} CPUs")
    ncollpyde_volume = Volume.from_meshio(mesh, n_rays=3, threads=threads)
    actual = benchmark(ncollpyde_volume.contains, sample_points)
    check_internals_equal(expected, actual, 0)
Пример #6
0
def test_points_roundtrip(mesh):
    points = mesh.points
    vol = Volume(mesh.points, mesh.cells_dict["triangle"])

    expected = np.array(sorted(tuple(p) for p in points), dtype=np.float32)
    actual = np.array(sorted(tuple(p) for p in vol.points), dtype=np.float32)

    assert np.allclose(expected, actual)
Пример #7
0
def test_many(mesh, threads):
    points = []
    expected = []
    for p, e in points_expected:
        points.append(p)
        expected.append(e)

    vol = Volume.from_meshio(mesh)
    assert np.array_equal(vol.contains(points, threads=threads), expected)
Пример #8
0
def test_triangles(mesh):
    points = mesh.points
    triangles = mesh.cells_dict["triangle"]
    expected = trimesh.Trimesh(points, triangles)

    vol = Volume(mesh.points, triangles)
    actual = trimesh.Trimesh(vol.points, vol.faces)

    assert expected.volume == actual.volume
Пример #9
0
def test_ncollpyde_intersection(mesh, benchmark, threads):
    if threads > CPU_COUNT:
        pytest.skip(f"Wanted {threads} threads, only have {CPU_COUNT} CPUs")

    n_edges = 1_000
    rng = np.random.default_rng(1991)
    starts = rng.random((n_edges, 3)) * 2 - 0.5
    stops = rng.random((n_edges, 3)) * 2 - 0.5

    vol = Volume.from_meshio(mesh, threads=threads)
    benchmark(vol.intersections, starts, stops)
Пример #10
0
def test_can_repair_hole(mesh):
    triangles = mesh.cells_dict["triangle"]
    triangles = triangles[:-1]
    Volume(mesh.points, triangles, True)
Пример #11
0
def test_ncollpyde_contains(mesh, n_rays, sample_points, expected, benchmark):
    ncollpyde_volume = Volume.from_meshio(mesh, n_rays=n_rays)
    ncollpyde_volume.threads = 0
    actual = benchmark(ncollpyde_volume.contains, sample_points)
    if n_rays:
        check_internals_equal(expected, actual, 0)
Пример #12
0
def ncollpyde_volume(mesh):
    return Volume.from_meshio(mesh)
Пример #13
0
def sez_right():
    return Volume.from_meshio(meshio.read(str(mesh_dir / "SEZ_right.stl")),
                              validate=True)
Пример #14
0
def simple_volume(simple_mesh):
    return Volume.from_meshio(simple_mesh, validate=True)
Пример #15
0
def volume(mesh):
    return Volume.from_meshio(meshio, validate=True)
Пример #16
0
def test_single(mesh, point, expected):
    """Sample pytest test function with the pytest fixture as an argument."""
    vol = Volume.from_meshio(mesh)
    assert (point in vol) == expected
Пример #17
0
def test_corner(mesh):
    vol = Volume.from_meshio(mesh)
    assert mesh.points[0] in vol
Пример #18
0
def test_0_rays(mesh):
    vol = Volume.from_meshio(mesh, n_rays=0)
    points = [p for p, _ in points_expected]
    assert np.array_equal(vol.contains(points), [False] * len(points))
Пример #19
0
def test_no_validation(mesh):
    triangles = mesh.cells_dict["triangle"]
    Volume(mesh.points, triangles, True)
Пример #20
0
def test_ncollpyde_distance(mesh, benchmark, signed):
    n_points = 1_000
    rng = np.random.default_rng(1991)
    points = rng.random((n_points, 3)) * 2 - 0.5
    vol = Volume.from_meshio(mesh)
    benchmark(vol.distance, points, signed)
Пример #21
0
def test_can_repair_inversions(mesh):
    triangles = mesh.cells_dict["triangle"]
    triangles = triangles[:, ::-1]
    Volume(mesh.points, triangles, True)