Skip to content

Commit

Permalink
implement feature_normal_at_point for trimesh (#181)
Browse files Browse the repository at this point in the history
* implement `feature_normal_at_point` for trimesh

---------

Co-authored-by: Thierry Berger <[email protected]>
  • Loading branch information
thefakeplace and Vrixyz authored Sep 9, 2024
1 parent 66d6b80 commit 0928147
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

## Unreleased

### Added

- `TriMesh` now implements `Shape::feature_normal_at_point` to retrieve the normal of a face, when passing a `FeatureId::Face`.

## v0.17.1

### Modified

- Improve convergence of epa algorithm in degenerate configurations.
- Fix bug in the esh/mesh intersection algorithm that didn’t properly take mesh transforms into account.
- Fix bug in the mesh/mesh intersection algorithm that didn’t properly take mesh transforms into account.

## v0.17.0

Expand Down
12 changes: 12 additions & 0 deletions src/shape/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,18 @@ impl Shape for TriMesh {
Real::frac_pi_4()
}

/// Gets the normal of the triangle represented by `feature`.
fn feature_normal_at_point(
&self,
_feature: FeatureId,
_point: &Point<Real>,
) -> Option<Unit<Vector<Real>>> {
#[cfg(feature = "dim2")]
return None;
#[cfg(feature = "dim3")]
return self.feature_normal(_feature);
}

#[cfg(feature = "std")]
fn as_composite_shape(&self) -> Option<&dyn SimdCompositeShape> {
Some(self as &dyn SimdCompositeShape)
Expand Down
11 changes: 11 additions & 0 deletions src/shape/trimesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,17 @@ impl TriMesh {
)
})
}

#[cfg(feature = "dim3")]
/// Gets the normal of the triangle represented by `feature`.
pub fn feature_normal(&self, feature: FeatureId) -> Option<Unit<Vector<Real>>> {
match feature {
FeatureId::Face(i) => self
.triangle(i % self.num_triangles() as u32)
.feature_normal(FeatureId::Face(0)),
_ => None,
}
}
}

impl TriMesh {
Expand Down

0 comments on commit 0928147

Please sign in to comment.