From f16325d49a7e364bcf30c2ce8c33ee6a6b8b8193 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 01:56:38 +0000 Subject: [PATCH 1/2] Initial plan From 52615c645d8c9b5f54f52b259e1e269721e31400 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Nov 2025 01:59:42 +0000 Subject: [PATCH 2/2] Address code review comments Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 3 ++- examples/cut_example.py | 1 - loop_cgal/__init__.py | 4 ++-- loop_cgal/utils.py | 6 +----- pyproject.toml | 4 +++- src/mesh.cpp | 4 ++-- src/meshutils.h | 2 +- tests/test_mesh_operations.py | 1 - 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3575896..aeeac98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,8 @@ jobs: - if: matrix.os == 'ubuntu-latest' run: | sudo apt-get install -y libgl1-mesa-dev libeigen3-dev libcgal-dev - - if: matrix.os == 'macos-latest' || matrix.os == 'macos-14' - run: | + - if: ${{ startsWith(matrix.os, 'macos') }} + run: | brew install cgal # Cache vcpkg on Windows - name: Restore vcpkg cache diff --git a/CMakeLists.txt b/CMakeLists.txt index 4276ed1..fe9c2a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,10 +24,11 @@ add_library(_loop_cgal MODULE target_link_libraries(_loop_cgal PRIVATE pybind11::module CGAL::CGAL) target_include_directories(_loop_cgal PRIVATE ${CMAKE_SOURCE_DIR}/src) -set_target_properties(_loop_cgal PROPERTIES PREFIX "" SUFFIX ".so") if(WIN32) set_target_properties(_loop_cgal PROPERTIES PREFIX "" SUFFIX ".pyd") +else() + set_target_properties(_loop_cgal PROPERTIES PREFIX "" SUFFIX ".so") endif() # Windows: copy required DLLs from VCPKG_ROOT diff --git a/examples/cut_example.py b/examples/cut_example.py index d403710..cf6ebb3 100644 --- a/examples/cut_example.py +++ b/examples/cut_example.py @@ -1,5 +1,4 @@ import numpy as np -import pyvista as pv from loop_cgal import TriMesh, set_verbose from LoopStructural.datatypes import BoundingBox set_verbose(True) diff --git a/loop_cgal/__init__.py b/loop_cgal/__init__.py index 8800f05..fcbbe20 100644 --- a/loop_cgal/__init__.py +++ b/loop_cgal/__init__.py @@ -30,7 +30,7 @@ def __init__(self, surface: pv.PolyData): # Extract vertices and triangles verts = np.array(surface.points, dtype=np.float64).copy() faces = surface.faces.reshape(-1, 4)[:, 1:].copy().astype(np.int32) - if (not validate_vertices_and_faces(verts, faces)): + if not validate_vertices_and_faces(verts, faces): raise ValueError("Invalid surface geometry") super().__init__(verts, faces) @@ -54,7 +54,7 @@ def from_vertices_and_triangles( The created TriMesh object. """ # Create a temporary PyVista PolyData object for validation - if (not validate_vertices_and_faces(vertices, triangles)): + if not validate_vertices_and_faces(vertices, triangles): raise ValueError("Invalid vertices or triangles") surface = pv.PolyData(vertices, np.hstack((np.full((triangles.shape[0], 1), 3), triangles)).flatten()) return cls(surface) diff --git a/loop_cgal/utils.py b/loop_cgal/utils.py index 85e2b7d..011395c 100644 --- a/loop_cgal/utils.py +++ b/loop_cgal/utils.py @@ -32,7 +32,7 @@ def validate_pyvista_polydata( raise ValueError(f"{surface_name} points contain NaN or infinite values") -def validate_vertices_and_faces(verts, faces) -> bool: +def validate_vertices_and_faces(verts, faces): """Validate vertices and faces arrays. Parameters ---------- @@ -42,10 +42,6 @@ def validate_vertices_and_faces(verts, faces) -> bool: faces : np.ndarray An array of shape (n_faces, 3) containing the triangle vertex indices. - Returns - ------- - bool - True if valid, False otherwise. Raises ------ ValueError diff --git a/pyproject.toml b/pyproject.toml index e763ed0..d982f35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,9 @@ classifiers = [ ] dependencies = ['pyvista','vtk','scipy','numpy'] -optional-dependencies = { test = ['pytest'] } + +[project.optional-dependencies] +test = ['pytest'] [tool.scikit-build] wheel.expand-macos-universal-tags = true diff --git a/src/mesh.cpp b/src/mesh.cpp index 29c8997..157b2f3 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -294,7 +294,7 @@ void TriMesh::cutWithSurface(TriMesh &clipper, bool preserve_intersection_clipper, bool use_exact_kernel) { - + if (LoopCGAL::verbose) { std::cout << "Cutting mesh with surface." << std::endl; @@ -692,7 +692,7 @@ void TriMesh::cut_with_implicit_function(const std::vector &property, do double v0 = newvals[tri[0]]; double v1 = newvals[tri[1]]; double v2 = newvals[tri[2]]; - if (v0 <= value && v1 <= value && v2 <= value) + if (v0 < value && v1 < value && v2 < value) { continue; } diff --git a/src/meshutils.h b/src/meshutils.h index 4ffea32..5307f45 100644 --- a/src/meshutils.h +++ b/src/meshutils.h @@ -10,5 +10,5 @@ double calculate_triangle_area(const std::array &v1, const std::array &v3); Exact_Mesh convert_to_exact(const TriMesh& input); TriangleMesh convert_to_double_mesh(const Exact_Mesh& input); - + #endif // MESHUTILS_H diff --git a/tests/test_mesh_operations.py b/tests/test_mesh_operations.py index 1710dc5..a181909 100644 --- a/tests/test_mesh_operations.py +++ b/tests/test_mesh_operations.py @@ -10,7 +10,6 @@ def square_surface(): # Unit square made of two triangles return pv.Plane(center=(0,0,0),direction=(0,0,1),i_size=1.0,j_size=1.0) - @pytest.fixture