Skip to content

Conversation

@lachlangrose
Copy link
Member

  • Add option to clip surface with implicit function.
  • Also change predicate for clipping to exact kernel to avoid infinite hangs

@lachlangrose lachlangrose requested a review from Copilot November 4, 2025 01:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds several significant features to the loop_cgal library:

  • Implements cut_with_implicit_function to cut meshes based on vertex properties
  • Adds exact kernel support for improved numerical robustness in mesh operations
  • Introduces comprehensive test coverage for mesh operations
  • Refactors validation logic into separate utils module

Reviewed Changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/mesh.cpp Adds cut_with_implicit_function implementation and exact kernel support for cutWithSurface
src/mesh.h Declares new methods and exact kernel types
src/meshutils.cpp Implements conversion functions between exact and double precision meshes
src/meshutils.h Declares mesh conversion functions
src/meshenums.h Defines ImplicitCutMode enum for cut operations
loop_cgal/init.py Refactors validation logic and adds new helper methods
loop_cgal/utils.py Extracts validation functions into separate module
loop_cgal/bindings.cpp Exposes new C++ functionality to Python
tests/test_mesh_operations.py Adds comprehensive test suite for mesh operations
tests/test_degenerate.py Refactors degenerate mesh tests into proper pytest format
pyproject.toml Adds vtk dependency and test optional dependencies
CMakeLists.txt Updates build configuration for cross-platform support
.github/workflows/ci.yml Adds CI workflow for automated testing
examples/*.py Adds example scripts demonstrating new features

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/meshutils.h Outdated
const std::array<double, 3> &v3);
Exact_Mesh convert_to_exact(const TriMesh& input);
TriangleMesh convert_to_double_mesh(const Exact_Mesh& input);

Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 13 should be removed to maintain consistent code formatting.

Suggested change

Copilot uses AI. Check for mistakes.
src/mesh.cpp Outdated
bool preserve_intersection_clipper,
bool use_exact_kernel)
{

Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 297 should be removed to maintain consistent code formatting.

Suggested change

Copilot uses AI. Check for mistakes.
degen_idx = np.where(m.sum(axis=0) != 3)[1]
raise ValueError(f"Surface contains degenerate triangles: {degen_idx} (each triangle must have exactly 3 vertices)")

if (not validate_vertices_and_faces(verts, faces)):
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Unnecessary parentheses around the boolean expression. Python style guides recommend removing them unless needed for line continuation or grouping.

Suggested change
if (not validate_vertices_and_faces(verts, faces)):
if not validate_vertices_and_faces(verts, faces):

Copilot uses AI. Check for mistakes.
The created TriMesh object.
"""
# Create a temporary PyVista PolyData object for validation
if (not validate_vertices_and_faces(vertices, triangles)):
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Unnecessary parentheses around the boolean expression. Python style guides recommend removing them unless needed for line continuation or grouping.

Suggested change
if (not validate_vertices_and_faces(vertices, triangles)):
if not validate_vertices_and_faces(vertices, triangles):

Copilot uses AI. Check for mistakes.
pyproject.toml Outdated
Comment on lines 30 to 31
optional-dependencies = { test = ['pytest'] }

Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TOML syntax for optional-dependencies should use nested table format for better compatibility with TOML parsers. Should be: [project.optional-dependencies]\ntest = ['pytest']

Suggested change
optional-dependencies = { test = ['pytest'] }
[project.optional-dependencies]
test = ['pytest']

Copilot uses AI. Check for mistakes.
Comment on lines 35 to 48
def validate_vertices_and_faces(verts, faces) -> bool:
"""Validate vertices and faces arrays.
Parameters
----------
verts : np.ndarray
An array of shape (n_vertices, 3) containing the vertex coordinates.
faces : np.ndarray
An array of shape (n_faces, 3) containing the triangle vertex indices.
Returns
-------
bool
True if valid, False otherwise.
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function's return type annotation claims it returns bool, but the function actually raises ValueError on validation failures and only returns True on success. The docstring correctly documents that it raises ValueError, so the return type should be either removed or the function should be refactored to return bool consistently.

Suggested change
def validate_vertices_and_faces(verts, faces) -> bool:
"""Validate vertices and faces arrays.
Parameters
----------
verts : np.ndarray
An array of shape (n_vertices, 3) containing the vertex coordinates.
faces : np.ndarray
An array of shape (n_faces, 3) containing the triangle vertex indices.
Returns
-------
bool
True if valid, False otherwise.
def validate_vertices_and_faces(verts, faces):
"""Validate vertices and faces arrays.
Parameters
----------
verts : np.ndarray
An array of shape (n_vertices, 3) containing the vertex coordinates.
faces : np.ndarray
An array of shape (n_faces, 3) containing the triangle vertex indices.

Copilot uses AI. Check for mistakes.
Comment on lines 13 to 15



Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 13 should be removed to maintain consistent code formatting.

Suggested change

Copilot uses AI. Check for mistakes.
- 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'
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions conditional expressions should use proper YAML syntax. The condition should be: if: matrix.os == 'macos-latest' || matrix.os == 'macos-14' (wrapped in quotes if needed), or better yet, use: if: startsWith(matrix.os, 'macos')

Suggested change
- if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
- if: ${{ startsWith(matrix.os, 'macos') }}

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,36 @@
import numpy as np
import pyvista as pv
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'pv' is not used.

Suggested change
import pyvista as pv

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lachlangrose
Copy link
Member Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Nov 4, 2025

@lachlangrose I've opened a new pull request, #17, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits November 4, 2025 13:00
* Initial plan

* Address code review comments

Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
@lachlangrose lachlangrose merged commit 6cec095 into main Nov 4, 2025
32 checks passed
@lachlangrose lachlangrose deleted the fix/adding-implicit-function-cutting branch November 4, 2025 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants