Skip to content

fix(constitution): use per-joint anchor positions in spherical joint simplified API#410

Merged
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:fix/spherical-joint-api
Mar 28, 2026
Merged

fix(constitution): use per-joint anchor positions in spherical joint simplified API#410
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:fix/spherical-joint-api

Conversation

@Ligo04
Copy link
Copy Markdown
Contributor

@Ligo04 Ligo04 commented Mar 27, 2026

Summary

  • Fix variable shadowing bug in the simplified apply_to overload where vector<Vector3> r_local_pos redefined the parameter Vector3 r_local_pos, causing a compilation error.
  • Change simplified API to accept span<Vector3> r_local_pos (per-joint anchor positions) instead of a single Vector3, giving callers more flexibility while keeping the uniform strength_ratio scalar.
  • Update pybind binding to match: the simplified overload now takes a numpy array of anchor positions (py::array_t<Float>) converted via as_span_of<Vector3>.
  • Update test case (80_abd_spherical_joint) to use the new simplified API.

Changed Files

File Change
include/uipc/constitution/affine_body_spherical_joint.h Add span<Vector3> r_local_pos param to simplified overload
src/constitution/affine_body_spherical_joint.cpp Fix shadowing, accept span<Vector3>
src/pybind/pyuipc/constitution/affine_body_spherical_joint.cpp Update pybind to pass py::array_t<Float>span<Vector3>
apps/tests/sim_case/80_abd_spherical_joint.cpp Use simplified API with per-joint anchors

…simplified API

Change the simplified `apply_to` overload to accept `span<Vector3>
r_local_pos` instead of a single `Vector3`, allowing each joint to
specify its own anchor point in body1's local frame. Update the pybind
binding and test case accordingly.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the AffineBodySphericalJoint::apply_to API to support per-joint anchor positions by adding a new r_local_pos parameter. These changes are propagated through the C++ implementation, test cases, and Python bindings. The review feedback suggests renaming several parameters (such as l_instance_id and strength_ratio) to their plural forms in both the C++ and Python signatures to ensure naming consistency across the codebase.

void AffineBodySphericalJoint::apply_to(geometry::SimplicialComplex& sc,
span<S<geometry::SimplicialComplexSlot>> l_geo_slots,
span<IndexT> l_instance_id,
span<IndexT> l_instance_id,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with the simplified apply_to overload and general C++ best practices, it's recommended to use plural names for parameters that are collections (like span).

Consider renaming the following parameters in this function signature (and its declaration in the header file) to reflect that they are collections:

  • l_instance_id -> l_instance_ids
  • r_instance_id -> r_instance_ids
  • strength_ratio -> strength_ratios

This will improve readability and consistency across the API.

Suggested change
span<IndexT> l_instance_id,
span<IndexT> l_instance_ids,

Comment on lines +81 to +85
py::array_t<IndexT> l_instance_id,
py::list r_geo_slots,
py::array_t<IndexT> r_instance_id,
py::array_t<Float> r_local_pos,
py::array_t<Float> strength_ratio)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency and to improve readability, it's better to use plural names for parameters that are collections, like py::array_t. This makes the Python API more intuitive.

Please consider renaming l_instance_id, r_instance_id, and strength_ratio to their plural forms. Remember to also update their usage inside the lambda body.

Suggested change
py::array_t<IndexT> l_instance_id,
py::list r_geo_slots,
py::array_t<IndexT> r_instance_id,
py::array_t<Float> r_local_pos,
py::array_t<Float> strength_ratio)
py::array_t<IndexT> l_instance_ids,
py::list r_geo_slots,
py::array_t<IndexT> r_instance_ids,
py::array_t<Float> r_local_pos,
py::array_t<Float> strength_ratios)

Rename l_instance_id → l_instance_ids, r_instance_id → r_instance_ids,
strength_ratio → strength_ratios in the full apply_to overload across
header, implementation, and pybind binding for consistency.

Made-with: Cursor
@MuGdxy MuGdxy merged commit dd68cbd into spiriMirror:main Mar 28, 2026
14 checks passed
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