diff --git a/cpp/Point2.h b/cpp/Point2.h index ddb9c47de..e3efdddcb 100644 --- a/cpp/Point2.h +++ b/cpp/Point2.h @@ -51,6 +51,7 @@ namespace gtsam { inline bool operator ==(const Point2& q) const {return x_==q.x_ && q.y_==q.y_;} inline Point2 operator + (const Point2& q) const {return Point2(x_+q.x_,y_+q.y_);} inline Point2 operator - (const Point2& q) const {return Point2(x_-q.x_,y_-q.y_);} + inline Point2 operator * (double s) const {return Point2(x_*s,y_*s);} inline Point2 operator / (double q) const {return Point2(x_/q,y_/q);} /** norm of point */ @@ -100,5 +101,7 @@ namespace gtsam { /** "Inverse" - negates each coordinate such that compose(p,inverse(p))=Point2() */ inline Point2 inverse(const Point2& p) { return Point2(-p.x(), -p.y()); } + /** multiply with scalar */ + inline Point2 operator*(double s, const Point2& p) {return p*s;} } diff --git a/cpp/testPoint2.cpp b/cpp/testPoint2.cpp index 906d48a7a..d1eb6e7ef 100644 --- a/cpp/testPoint2.cpp +++ b/cpp/testPoint2.cpp @@ -26,6 +26,9 @@ TEST( Point2, arithmetic) CHECK(assert_equal( Point2(-5,-6), -Point2(5,6) )); CHECK(assert_equal( Point2(5,6), Point2(4,5)+Point2(1,1))); CHECK(assert_equal( Point2(3,4), Point2(4,5)-Point2(1,1) )); + CHECK(assert_equal( Point2(8,6), Point2(4,3)*2)); + CHECK(assert_equal( Point2(4,6), 2*Point2(2,3))); + CHECK(assert_equal( Point2(2,3), Point2(4,6)/2)); } /* ************************************************************************* */