def test_single_raycast(): triangles = np.array([ [0.0, 0.0, 0.0], [4.0, 0.0, 0.0], [0.0, 4.0, 0.0], ], dtype='f4') result = mesh_raycast.raycast(source=(0.4, 0.8, 5.0), direction=(0.0, 0.0, -1.0), mesh=triangles) expected = { 'face': 0, 'point': (0.4, 0.8, 0.0), 'normal': (0.0, 0.0, 1.0), 'coeff': (0.1, 0.2), 'distance': 5.0, 'dot': 1.0, } assert len(result) == 1 assert result[0]['face'] == expected['face'] for key in ('point', 'normal', 'coeff', 'distance', 'dot'): np.testing.assert_almost_equal(result[0][key], expected[key])
def test_no_result(): triangles = np.array([ [0.0, 0.0, 0.0], [4.0, 0.0, 0.0], [0.0, 4.0, 0.0], ], dtype='f4') result = mesh_raycast.raycast(source=(4.0, 4.0, 4.0), direction=(1.0, 1.0, -1.0), mesh=triangles) assert len(result) == 0
def test_non_bidirectional(): triangles = np.array([ [0.0, 0.0, 0.0], [4.0, 0.0, 0.0], [0.0, 4.0, 0.0], [0.0, 0.0, 2.0], [2.0, 0.0, 2.0], [0.0, 2.0, 2.0], ], dtype='f4') source = (1.0, 1.0, 1.0) direction = mesh_raycast.direction(source, (0.5, 0.5, -0.5)) result = mesh_raycast.raycast(source=source, direction=direction, mesh=triangles) assert len(result) == 1 assert result[0]['face'] == 0
def test_multiple_results(): triangles = np.array([ [0.0, 0.0, 0.0], [4.0, 0.0, 0.0], [0.0, 4.0, 0.0], [0.0, 0.0, 2.0], [2.0, 0.0, 2.0], [0.0, 2.0, 2.0], ], dtype='f4') source = (1.0, 1.0, 5.0) direction = mesh_raycast.direction(source, (0.5, 0.5, -0.5)) result = mesh_raycast.raycast(source=source, direction=direction, mesh=triangles) assert len(result) == 2 assert {result[0]['face'], result[1]['face']} == {0, 1}
import numpy as np import mesh_raycast triangles = np.array([ [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], ], dtype='f4') index = np.array([ [0, 1, 2], ], dtype='i4') print( mesh_raycast.raycast((0.0, 0.0, 2.0), mesh_raycast.normalize((0.1, 0.2, -1.0)), triangles)) print( mesh_raycast.iraycast((0.0, 0.0, 2.0), mesh_raycast.normalize((0.1, 0.2, -1.0)), triangles, index))