|
| 1 | +# import random |
| 2 | +import pytest |
| 3 | +from compas.geometry import Box |
| 4 | +from compas.tolerance import TOL |
| 5 | +from compas_model.algorithms import brep_brep_contacts |
| 6 | +from compas_model.algorithms import mesh_mesh_contacts |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + ["vector", "size"], |
| 11 | + [ |
| 12 | + ([1, 0, 0], 1), |
| 13 | + ([0, 1, 0], 1), |
| 14 | + ([0, 0, 1], 1), |
| 15 | + ([1, 0.5, 0], 0.5), |
| 16 | + ([1, 0, 0.5], 0.5), |
| 17 | + ([1, 0.5, 0.5], 0.25), |
| 18 | + ([0.5, 1, 0], 0.5), |
| 19 | + ([0, 1, 0.5], 0.5), |
| 20 | + ([0.5, 1, 0.5], 0.25), |
| 21 | + ([0.5, 0, 1], 0.5), |
| 22 | + ([0, 0.5, 1], 0.5), |
| 23 | + ([0.5, 0.5, 1], 0.25), |
| 24 | + ], |
| 25 | +) |
| 26 | +def test_brep_brep_contacts(vector, size): |
| 27 | + # Create two cubes |
| 28 | + box1 = Box(1, 1, 1) |
| 29 | + box2 = Box(1, 1, 1) |
| 30 | + |
| 31 | + # Move box2 to overlap with box1 |
| 32 | + box2.translate(vector) |
| 33 | + |
| 34 | + # Convert boxes to BReps |
| 35 | + box1_brep = box1.to_brep() |
| 36 | + box2_brep = box2.to_brep() |
| 37 | + |
| 38 | + # Find contacts between the two BReps |
| 39 | + contacts = brep_brep_contacts(box1_brep, box2_brep) |
| 40 | + |
| 41 | + # Check that contacts were found |
| 42 | + assert len(contacts) > 0 |
| 43 | + assert len(contacts) == 1 |
| 44 | + |
| 45 | + # Check that the contacts are indeed overlapping |
| 46 | + for contact in contacts: |
| 47 | + assert contact.size > 0 |
| 48 | + assert TOL.is_close(contact.size, size) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parametrize( |
| 52 | + ["vector", "size"], |
| 53 | + [ |
| 54 | + ([1, 0, 0], 1), |
| 55 | + ([0, 1, 0], 1), |
| 56 | + ([0, 0, 1], 1), |
| 57 | + ([1, 0.5, 0], 0.5), |
| 58 | + ([1, 0, 0.5], 0.5), |
| 59 | + ([1, 0.5, 0.5], 0.25), |
| 60 | + ([0.5, 1, 0], 0.5), |
| 61 | + ([0, 1, 0.5], 0.5), |
| 62 | + ([0.5, 1, 0.5], 0.25), |
| 63 | + ([0.5, 0, 1], 0.5), |
| 64 | + ([0, 0.5, 1], 0.5), |
| 65 | + ([0.5, 0.5, 1], 0.25), |
| 66 | + ], |
| 67 | +) |
| 68 | +def test_mesh_mesh_contacts(vector, size): |
| 69 | + # Create two cubes |
| 70 | + box1 = Box(1, 1, 1) |
| 71 | + box2 = Box(1, 1, 1) |
| 72 | + |
| 73 | + # Move box2 to overlap with box1 |
| 74 | + box2.translate(vector) |
| 75 | + |
| 76 | + # Convert boxes to BReps |
| 77 | + box1_mesh = box1.to_mesh() |
| 78 | + box2_mesh = box2.to_mesh() |
| 79 | + |
| 80 | + # Find contacts between the two BReps |
| 81 | + contacts = mesh_mesh_contacts(box1_mesh, box2_mesh) |
| 82 | + |
| 83 | + # Check that contacts were found |
| 84 | + assert len(contacts) > 0 |
| 85 | + assert len(contacts) == 1 |
| 86 | + |
| 87 | + # Check that the contacts are indeed overlapping |
| 88 | + for contact in contacts: |
| 89 | + assert contact.size > 0 |
| 90 | + assert TOL.is_close(contact.size, size) |
0 commit comments