Skip to content

Commit

Permalink
Make SO3<Scalar>::cast<Scalar>() a noop
Browse files Browse the repository at this point in the history
this saves a useless normalization operation.
  • Loading branch information
Dvad authored and strasdat committed Jun 9, 2024
1 parent 98b4137 commit 1943abb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sophus/so3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,20 @@ class SO3Base {

/// Returns copy of instance casted to NewScalarType.
///
/// Note: The case of casting to the same type is handled specifically to
/// avoid unnecessary quaternion renormalization. In the general case, the
/// construction of returned SO3 renormalizes the quaternion
template <class NewScalarType>
SOPHUS_FUNC SO3<NewScalarType> cast() const {
SOPHUS_FUNC std::enable_if_t<std::is_same<Scalar, NewScalarType>::value,
SO3<NewScalarType>>
cast() const {
return *this;
}

template <class NewScalarType>
SOPHUS_FUNC std::enable_if_t<!std::is_same<Scalar, NewScalarType>::value,
SO3<NewScalarType>>
cast() const {
return SO3<NewScalarType>(unit_quaternion().template cast<NewScalarType>());
}

Expand Down

0 comments on commit 1943abb

Please sign in to comment.