This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Extending vector class via plugin

Tags: None
(comma "," separated)
atnone
Registered Member
Posts
2
Karma
0

Extending vector class via plugin

Sun Dec 02, 2012 11:16 pm
I'm trying to extend vector2* with something like:

Code: Select all
inline Scalar getR() const{
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2);
    return norm();
}
inline Scalar getTheta() const{
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2);
    return std::atan2(this->operator()(1), this->operator()(0));
}
inline void setPolar(Scalar r, Scalar theta){
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2);
    this->operator()(0) = r * std::cos(theta);
    this->operator()(1) = r * std::sin(theta);
}
inline void setR(Scalar r){
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2);
    setPolar(r, getTheta());
}
inline void setTheta(Scalar theta){
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 2);
    setPolar(getR(), theta);
}


as EIGEN_MATRIXBASE_PLUGIN. The code works, but I think this should be done with template specialisation, but I couldn't get it working :( .
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This sounds good. This code is directly included in the class body of MatrixBase<>, so no need to play with templates here.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]