Skip to content

Add value-based equality for TriangleMesh#7382

Open
sean85914 wants to merge 5 commits into
isl-org:mainfrom
sean85914:dev-sean
Open

Add value-based equality for TriangleMesh#7382
sean85914 wants to merge 5 commits into
isl-org:mainfrom
sean85914:dev-sean

Conversation

@sean85914

Copy link
Copy Markdown

Type

  • New feature (non-breaking change which adds functionality).

Motivation and Context

Currently, TriangleMesh instances in Python compare by identity due to the lack of a C++ operator==.
This leads to unintuitive behavior:

m1 = o3d.geometry.TriangleMesh.create_sphere(0.1)
m1.compute_vertex_normals()
m2 = o3d.geometry.TriangleMesh(m1)

m1 == m2   # False

Although m2 is a copy of m1, equality returns False.
This PR adds a value-based equality operator for TriangleMesh to fix this.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

  • Added bool TriangleMesh::operator==(const TriangleMesh &mesh) const
  • Equality is defined as vertices and triangles being identical.
  • vertices_ comparison uses isApprox for floating-point precision.
  • triangles_ comparison uses exact equality for integer indices.
  • Bound Python equality using py::self == py::self for TriangleMesh.
  • Updated Python behavior:
m1 = o3d.geometry.TriangleMesh.create_sphere(0.1)
m2 = o3d.geometry.TriangleMesh(m1)
assert m1 == m2   # True
  • Copy constructor remains consistent with value-based equality semantics.
  • Normals, colors, and other auxiliary attributes are not considered in equality, as they can be recomputed.

@update-docs

update-docs Bot commented Dec 9, 2025

Copy link
Copy Markdown

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ssheorey

Copy link
Copy Markdown
Member

A feature like this needs motivation (Why?) and use cases (When would you use this?). The implementation provided here is incorrect, since it ignores a reordering of the vertices.

@ssheorey ssheorey added status / needs info Waiting for information from reporter / author labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status / needs info Waiting for information from reporter / author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants