Skip to content

Add cotangent-based Laplace-Beltrami and mean curvature support to fv_surface_mesh#12

Open
Copilot wants to merge 9 commits intomasterfrom
copilot/add-cotangent-weights-laplace-beltrami
Open

Add cotangent-based Laplace-Beltrami and mean curvature support to fv_surface_mesh#12
Copilot wants to merge 9 commits intomasterfrom
copilot/add-cotangent-weights-laplace-beltrami

Conversation

Copy link

Copilot AI commented Feb 24, 2026

This PR extends fv_surface_mesh in src/YgorMath.{h,cc} with core differential-geometry operators requested in the issue: efficient cotangent-weight helpers, per-vertex Laplace-Beltrami application, and per-vertex mean curvature derived from that operator. It also adds focused unit coverage to validate correctness and enforce algorithm preconditions.

  • API additions (fv_surface_mesh)

    • Added:
      • cotangent_weights(I v1, I v2, I v3, I v4) const
      • laplace_beltrami_operator() const
      • mean_curvature() const
  • Cotangent helper implementation

    • Computes both cotangent weights opposite a shared edge in adjacent triangles.
    • Uses a shared internal cotangent routine to avoid duplicated math paths.
  • Laplace-Beltrami operator

    • Implements cotangent-weight discrete Laplace-Beltrami per vertex:
      • accumulates edge contributions using cotangent weights,
      • normalizes by local barycentric area.
    • Adds explicit guardrails for required assumptions:
      • triangular facets only,
      • non-degenerate triangles / stable cotangent denominator,
      • valid face vertex references,
      • manifold edge incidence (≤ 2 triangles per edge),
      • positive local area per vertex.
  • Mean curvature

    • Computes per-vertex scalar mean curvature magnitudes from Laplace-Beltrami output:
      • ( H_i = \frac{1}{2}|\Delta x_i| )
  • Targeted test coverage

    • Added new tests2/YgorMath/fv_surface_mesh.cc subcases for:
      • cotangent weights on a regular tetrahedral mesh,
      • expected Laplace-Beltrami vectors on that mesh,
      • expected mean-curvature magnitudes,
      • failure behavior for non-triangular facets.
const auto lb = mesh.laplace_beltrami_operator();
const auto H  = mesh.mean_curvature(); // H_i = 0.5 * |lb_i|
Original prompt

Files src/YgorMath.{h,cc} implement a fv_surface_mesh class that can be used to hold a surface mesh in facet-vertex representation.

Implement the following methods to expand the usefulness of the existing fv_surface_mesh class:

  1. Helpers to efficiently compute both cotangent weights.

  2. The Laplace-Beltrami operator applied to vertices.

  3. The mean curvature for vertices, which uses the Laplace-Beltrami operator.

It is critical that these functions are validated, so tests should be added.

Be sure to adhere to the local style and conventions.

Where necessary, explicitly confirm requirements of the algorithm (e.g., that the mesh holds a triangular surface mesh, that the triangles have a nice enough aspect ratio so that cotangent weights can be computed, etc.)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 24, 2026 03:14
Co-authored-by: hdclark <934858+hdclark@users.noreply.github.com>
Co-authored-by: hdclark <934858+hdclark@users.noreply.github.com>
Co-authored-by: hdclark <934858+hdclark@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement cotangent weights and Laplace-Beltrami for surface mesh Add cotangent-based Laplace-Beltrami and mean curvature support to fv_surface_mesh Feb 24, 2026
Copilot AI requested a review from hdclark February 24, 2026 03:25
@hdclark hdclark marked this pull request as ready for review February 24, 2026 03:37
Copilot AI review requested due to automatic review settings February 24, 2026 03:37
Copy link

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 differential geometry operators to the fv_surface_mesh class, implementing cotangent-weight based Laplace-Beltrami operator and mean curvature computation. The implementation follows established codebase patterns for error handling, template specialization, and testing.

Changes:

  • Added three new methods to fv_surface_mesh: cotangent_weights, laplace_beltrami_operator, and mean_curvature
  • Implemented cotangent weight computation with validation for degenerate triangles and manifold constraints
  • Added comprehensive unit tests for the new functionality using a regular tetrahedral mesh

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/YgorMath.h Declares three new public methods for differential geometry operations
src/YgorMath.cc Implements cotangent weights, Laplace-Beltrami operator with manifold/degeneracy checks, and mean curvature magnitude computation with proper template specializations
tests2/YgorMath/fv_surface_mesh.cc Adds three test subcases validating cotangent weights, Laplace-Beltrami operator, mean curvature, and error handling for non-triangular meshes

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

std::map<std::pair<I,I>, std::vector<I>> edge_to_opposing_vertices;
for(const auto &fv : this->faces){
if(fv.size() < 3) continue;
if(fv.size() != 3){
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The logic at line 6330 skips faces with fewer than 3 vertices with 'continue', but then line 6331 throws an error if the face doesn't have exactly 3 vertices. This means faces with exactly 3 vertices are processed, faces with fewer than 3 are skipped silently, but faces with more than 3 vertices throw an error. However, the skip at line 6330 is redundant since faces with size < 3 would fail the size != 3 check at line 6331 anyway. Consider removing line 6330 for clarity, or ensuring faces with < 3 vertices should genuinely be skipped rather than trigger an error.

Suggested change
if(fv.size() != 3){
if(fv.size() > 3){

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

Remove line 6330 as only faces with 3 vertices should be accepted.

hdclark and others added 5 commits February 23, 2026 19:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants