gazebosim/gz-math

Vector comparison operator isn't strict

chapulina opened this issue · 1 comments

Environment

  • OS Version: all
  • Source or binary build? all

Description

  • Expected behavior: Operators can be used to strictly order vectors.
  • Actual behavior: Operator is not asymmetric, so a < b and b < a can both be true at the same time, as demonstrated on the example below:
diff --git a/src/Vector3_TEST.cc b/src/Vector3_TEST.cc
index 81d8753..d038e15 100644
--- a/src/Vector3_TEST.cc
+++ b/src/Vector3_TEST.cc
@@ -546,3 +546,13 @@ TEST(Vector3dTest, DistToLine)
     EXPECT_DOUBLE_EQ(point.DistToLine(pointA, pointB), 0);
   }
 }
+
+/////////////////////////////////////////////////
+TEST(Vector3dTest, LessThanOperator)
+{
+  math::Vector3d vec1(1, 0, 0);
+  math::Vector3d vec2(0, 1, 0);
+
+  EXPECT_TRUE(vec2 < vec1);
+  EXPECT_TRUE(vec1 < vec2);
+}

Steps to reproduce

See the example test above, which passes

Additional context

On #219 , the WellOrderedVector was added to provide a strict comparison function so the current behaviour wouldn't be changed. We should consider changing the behaviour on a new major version.

Hey @chapulina . I have done some changes in the Vector3_TEST.cc to resolve the issue of operator not beign assymetric and have given the pull request . Can you just check and verify it .