Go to the documentation of this file.00001
00002
00003 #ifndef SRC_GUARD_TEST_GEOMETRY_TEST_HELPERS_H
00004 #define SRC_GUARD_TEST_GEOMETRY_TEST_HELPERS_H 1
00005
00006 namespace geometry_test_helpers
00007 {
00012 namespace comparison
00013 {
00014 template<class T>
00015 void display_diff(const T & obj1, const T & obj2, const std::string & msg)
00016 {
00017 std::cerr << msg << std::endl << std::endl
00018 << "Obj1" << std::endl << obj1 << std::endl
00019 << "Obj2" << std::endl << obj2 << std::endl;
00020 return;
00021 }
00022
00023 bool quaternions_are_equals(const geometry_msgs::Quaternion q1,
00024 const geometry_msgs::Quaternion q2,
00025 bool display_error = true)
00026 {
00027 if ((q1.x == q2.x) &&
00028 (q1.y == q2.y) &&
00029 (q1.z == q2.z) &&
00030 (q1.w == q2.w))
00031 return true;
00032
00033 if (display_error)
00034 display_diff<geometry_msgs::Quaternion>(q1, q2, "Quaternions are not equal");
00035
00036 return false;
00037 }
00038
00039 bool points_are_equals(const geometry_msgs::Point & p1,
00040 const geometry_msgs::Point & p2,
00041 bool display_error = true)
00042 {
00043 if ((p1.x == p2.x) &&
00044 (p1.y == p2.y) &&
00045 (p1.z == p2.z))
00046 return true;
00047
00048 if (display_error)
00049 display_diff<geometry_msgs::Point>(p1, p2, "Points are not equal");
00050
00051 return false;
00052 }
00053
00054 bool poses_are_equal(const geometry_msgs::Pose & p1,
00055 const geometry_msgs::Pose & p2,
00056 bool display_error = true)
00057 {
00058 if ((points_are_equals(p1.position, p2.position, false)) &&
00059 (quaternions_are_equals(p1.orientation, p2.orientation, false)))
00060 return true;
00061
00062 if (display_error)
00063 display_diff<geometry_msgs::Pose>(p1, p2, "Poses are not equal");
00064
00065 return false;
00066 }
00067
00068 bool poses_stamped_are_equal(const geometry_msgs::PoseStamped p1,
00069 const geometry_msgs::PoseStamped p2,
00070 bool display_error = true)
00071 {
00072 if ((p1.header.frame_id == p2.header.frame_id) &&
00073 (poses_are_equal(p1.pose, p2.pose, false)))
00074 return true;
00075
00076 if (display_error)
00077 display_diff<geometry_msgs::PoseStamped>(p1, p2, "Poses Stamped are not equal");
00078
00079 return false;
00080 }
00081 }
00082
00087 namespace generator
00088 {
00089 geometry_msgs::Pose generate_fixed_pose(int value)
00090 {
00091 geometry_msgs::Pose p;
00092
00093 p.position.x = value;
00094 p.position.y = value;
00095 p.position.z = value;
00096 p.orientation.x = 0;
00097 p.orientation.y = 1;
00098 p.orientation.z = 0;
00099 p.orientation.w = 0;
00100
00101 return p;
00102 }
00103 }
00104 }
00105
00106
00107
00108 #endif