Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user-defined copy constructor for Rot2 #806

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions gtsam/geometry/Rot2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ namespace gtsam {

/* ************************************************************************* */
Rot2 Rot2::fromCosSin(double c, double s) {
if (std::abs(c * c + s * s - 1.0) > 1e-9) {
double norm_cs = sqrt(c*c + s*s);
c = c/norm_cs;
s = s/norm_cs;
}
return Rot2(c, s);
Rot2 R(c, s);
return R.normalize();
}

/* ************************************************************************* */
Expand Down Expand Up @@ -59,8 +55,8 @@ bool Rot2::equals(const Rot2& R, double tol) const {
/* ************************************************************************* */
Rot2& Rot2::normalize() {
double scale = c_*c_ + s_*s_;
if(std::abs(scale-1.0)>1e-10) {
scale = pow(scale, -0.5);
if(std::abs(scale-1.0) > 1e-10) {
scale = 1 / sqrt(scale);
c_ *= scale;
s_ *= scale;
}
Expand Down
3 changes: 3 additions & 0 deletions gtsam/geometry/Rot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace gtsam {

/** default constructor, zero rotation */
Rot2() : c_(1.0), s_(0.0) {}

/** copy constructor */
Rot2(const Rot2& r) : Rot2(r.c_, r.s_) {}
Copy link
Member

Choose a reason for hiding this comment

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

Is this not default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean is this not the copy constructor that is generated by default by the compiler? I imagine that it probably is, but it is hard to say whether it is the compiler-generated version of the copy constructor itself or the copy constructor elision for return value optimization that was causing the error without fully dissecting that assembly I posted in the issue reply.


/// Constructor from angle in radians == exponential map at identity
Rot2(double theta) : c_(cos(theta)), s_(sin(theta)) {}
Expand Down