From 86b6e012828fe3d65bcfbf09d1adcbca2a68aff9 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Wed, 29 Jan 2025 10:38:22 -0500 Subject: [PATCH 1/3] Added a test for nested cubes --- tests/sample_assemblies.py | 30 ++++++++++++++++++++++++++++++ tests/smoke_test.py | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/sample_assemblies.py b/tests/sample_assemblies.py index 0c06115..baef57f 100644 --- a/tests/sample_assemblies.py +++ b/tests/sample_assemblies.py @@ -1,6 +1,36 @@ import cadquery as cq +def generate_nested_boxes(): + """ + Generates a simple assembly of two cubes where one is nested inside the other. + """ + + # Cube that is nested completely inside the other one + inside_cube = cq.Workplane().box(5, 5, 5) + + # Use the inside cube to make a void inside the outside cube + outside_cube = cq.Workplane().box(10, 10, 10) + outside_cube = outside_cube.cut(inside_cube) + + # Create the assembly + assy = cq.Assembly() + assy.add( + outside_cube, + name="outside_cube", + loc=cq.Location(cq.Vector(0, 0, 0)), + color=cq.Color("blue") + ) + assy.add( + inside_cube, + name="inside_cube", + loc=cq.Location(cq.Vector(0, 0, 0)), + color=cq.Color("red") + ) + + return assy + + def generate_simple_nested_boxes(): """ Generates the simplest assembly case where two boxes are nested inside each other. diff --git a/tests/smoke_test.py b/tests/smoke_test.py index eb36f75..d1ea886 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -1,11 +1,25 @@ import assembly_mesh_plugin.plugin from tests.sample_assemblies import ( + generate_nested_boxes, generate_simple_nested_boxes, generate_test_cross_section, generate_assembly, ) +def test_nested_cubes(): + """ + Tests to make sure that the nested cubes do not cause the correct number of surfaces + in the mesh. + """ + + # Create the basic assembly + assy = generate_nested_boxes() + + # Create a mesh that has all the faces tagged as physical groups + assy.saveToGmsh(mesh_path="tagged_nested_boxes.msh") + + def test_basic_assembly(): """ Tests to make sure that the most basic assembly works correctly with tagging. From 8cdd9ba8de900efae15c01dd3e8203336296e310 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Wed, 29 Jan 2025 10:42:00 -0500 Subject: [PATCH 2/3] Lint fix --- tests/sample_assemblies.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sample_assemblies.py b/tests/sample_assemblies.py index baef57f..7c69b61 100644 --- a/tests/sample_assemblies.py +++ b/tests/sample_assemblies.py @@ -19,13 +19,13 @@ def generate_nested_boxes(): outside_cube, name="outside_cube", loc=cq.Location(cq.Vector(0, 0, 0)), - color=cq.Color("blue") + color=cq.Color("blue"), ) assy.add( inside_cube, name="inside_cube", loc=cq.Location(cq.Vector(0, 0, 0)), - color=cq.Color("red") + color=cq.Color("red"), ) return assy From 2ec0188aca08bfe906afae0af42acea13665f5ca Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Wed, 29 Jan 2025 15:41:45 -0500 Subject: [PATCH 3/3] Check number of surfaces in nested boxes test --- tests/smoke_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/smoke_test.py b/tests/smoke_test.py index d1ea886..51426bb 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -16,8 +16,12 @@ def test_nested_cubes(): # Create the basic assembly assy = generate_nested_boxes() - # Create a mesh that has all the faces tagged as physical groups - assy.saveToGmsh(mesh_path="tagged_nested_boxes.msh") + # Convert the assembly to a GMSH mesh + gmsh = assy.getTaggedGmsh() + + # Make sure we have the correct number of surfaces + surfaces = gmsh.model.getEntities(2) + assert len(surfaces) == 18 def test_basic_assembly():