Skip to content

Commit

Permalink
Merge pull request #11 from open-space-collective/dev@lucas
Browse files Browse the repository at this point in the history
Dev@lucas
  • Loading branch information
lucas-bremond authored Sep 4, 2018
2 parents 50cf3d3 + 00294a9 commit d755fa1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <Library/Mathematics/Geometry/Angle.hpp>
#include <Library/Mathematics/Objects/Vector.hpp>

#include <Library/Core/Types/String.hpp>
#include <Library/Core/Types/Real.hpp>

Expand All @@ -32,6 +33,7 @@ namespace rot

using library::core::types::Real ;
using library::core::types::String ;

using library::math::obj::Vector3d ;
using library::math::geom::Angle ;

Expand Down Expand Up @@ -116,6 +118,17 @@ class RotationVector

Angle getAngle ( ) const ;

/// @brief Convert rotation vector to its string representation
///
/// @code
/// RotationVector(Vector3d(0.0, 0.0, 1.0), Angle::Degrees(90.0)).toString() ; // "[0.0, 0.0, 1.0] : 90.0 [deg]"
/// @endcode
///
/// @param [in] (optional) aPrecision A precision
/// @return String representation

String toString ( const Integer& aPrecision = Integer::Undefined() ) const ;

/// @brief Constructs an undefined rotation vector
///
/// @code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ inline void LibraryMathematicsPy_Geometry_Transformations_Ro

.def("getAxis", &RotationVector::getAxis)
.def("getAngle", &RotationVector::getAngle)
.def("Undefined", &RotationVector::Undefined)
.def("toString", &RotationVector::toString)

.def("Undefined", &RotationVector::Undefined)
.def("Unit", &RotationVector::Unit).staticmethod("Unit")
.def("Quaternion", &RotationVector::Quaternion).staticmethod("Quaternion")
.def("RotationMatrix", &RotationVector::RotationMatrix).staticmethod("RotationMatrix")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ Angle RotationVector::getAngle ( )

}

String RotationVector::toString ( const Integer& aPrecision ) const
{

if (!this->isDefined())
{
throw library::core::error::runtime::Undefined("Rotation vector") ;
}

return String::Format("{} : {}", (aPrecision.isDefined() ? axis_.toString(aPrecision) : axis_.toString()), angle_.toString(aPrecision)) ;

}

RotationVector RotationVector::Undefined ( )
{
return RotationVector() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,50 @@ TEST (Library_Mathematics_Geometry_Transformations_Rotations_RotationVector, Get

}

TEST (Library_Mathematics_Geometry_Transformations_Rotations_RotationVector, ToString)
{

using library::math::geom::Angle ;
using library::math::geom::trf::rot::RotationVector ;

{

EXPECT_EQ("[1.0, 0.0, 0.0] : 0.0 [deg]", RotationVector({ 1.0, 0.0, 0.0 }, Angle::Degrees(0.0)).toString()) ;

EXPECT_EQ("[0.0, 0.0, 1.0] : -30.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-30.0)).toString()) ;
EXPECT_EQ("[0.0, 0.0, 1.0] : 30.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+30.0)).toString()) ;

EXPECT_EQ("[0.0, 0.0, 1.0] : -90.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-90.0)).toString()) ;
EXPECT_EQ("[0.0, 0.0, 1.0] : 90.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+90.0)).toString()) ;

EXPECT_EQ("[0.0, 0.0, 1.0] : -180.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-180.0)).toString()) ;
EXPECT_EQ("[0.0, 0.0, 1.0] : 180.0 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+180.0)).toString()) ;

}

{

EXPECT_EQ("[1.000, 0.000, 0.000] : 0.000 [deg]", RotationVector({ 1.0, 0.0, 0.0 }, Angle::Degrees(0.0)).toString(3)) ;

EXPECT_EQ("[0.000, 0.000, 1.000] : -30.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-30.0)).toString(3)) ;
EXPECT_EQ("[0.000, 0.000, 1.000] : 30.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+30.0)).toString(3)) ;

EXPECT_EQ("[0.000, 0.000, 1.000] : -90.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-90.0)).toString(3)) ;
EXPECT_EQ("[0.000, 0.000, 1.000] : 90.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+90.0)).toString(3)) ;

EXPECT_EQ("[0.000, 0.000, 1.000] : -180.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(-180.0)).toString(3)) ;
EXPECT_EQ("[0.000, 0.000, 1.000] : 180.000 [deg]", RotationVector({ 0.0, 0.0, 1.0 }, Angle::Degrees(+180.0)).toString(3)) ;

}

{

EXPECT_ANY_THROW(RotationVector::Undefined().toString()) ;

}

}

TEST (Library_Mathematics_Geometry_Transformations_Rotations_RotationVector, Undefined)
{

Expand Down

0 comments on commit d755fa1

Please sign in to comment.