diff --git a/src/db/db/gsiDeclDbVector.cc b/src/db/db/gsiDeclDbVector.cc index cd9cd6e8d..0d679f1e0 100644 --- a/src/db/db/gsiDeclDbVector.cc +++ b/src/db/db/gsiDeclDbVector.cc @@ -100,6 +100,11 @@ struct vector_defs return std_ext::hfunc (*v); } + static db::point add_with_point (const C *v, const db::point &p) + { + return p + *v; + } + static gsi::Methods methods () { return @@ -120,6 +125,7 @@ struct vector_defs method_ext ("to_p", &to_point, "@brief Turns the vector into a point\n" "This method returns the point resulting from adding the vector to (0,0)." + "\n" "This method has been introduced in version 0.25." ) + method_ext ("-@", &negate, @@ -136,6 +142,13 @@ struct vector_defs "\n" "Adds vector v to self by adding the coordinates.\n" ) + + method_ext ("+", &add_with_point, + "@brief Adds a vector and a point\n" + "\n" + "@args p\n" + "\n" + "Returns the point p shifted by the vector.\n" + ) + method ("-", (C (C::*) (const C &) const) &C::subtract, "@brief Subtract two vectors\n" "\n" diff --git a/testdata/ruby/dbVectorTest.rb b/testdata/ruby/dbVectorTest.rb index 7b27afc8f..e9b30509c 100644 --- a/testdata/ruby/dbVectorTest.rb +++ b/testdata/ruby/dbVectorTest.rb @@ -55,6 +55,11 @@ class DBVector_TestClass < TestBase b.y = a.y assert_equal( a, b ) + assert_equal( c.to_p.class == RBA::DPoint, true ) + assert_equal( c.class == RBA::DVector, true ) + assert_equal( (c + RBA::DPoint::new(1, 2)).class == RBA::DPoint, true ) + assert_equal( (c + RBA::DPoint::new(1, 2)).to_s, "6,13" ) + end # Transforming DVector @@ -101,6 +106,11 @@ class DBVector_TestClass < TestBase b.y = a.y assert_equal( a, b ) + assert_equal( c.to_p.class == RBA::Point, true ) + assert_equal( c.class == RBA::Vector, true ) + assert_equal( (c + RBA::Point::new(1, 2)).class == RBA::Point, true ) + assert_equal( (c + RBA::Point::new(1, 2)).to_s, "6,13" ) + end # Transforming Vector