diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | lib/matrix.rb | 6 | ||||
-rw-r--r-- | test/matrix/test_vector.rb | 3 |
4 files changed, 13 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Wed Oct 29 11:42:33 2014 Marc-Andre Lafortune <ruby-core@marc-andre.ca> + + * lib/matrix.rb: Add aliases for Vector#cross & dot + patch by gogo tanaka [#10352] + Wed Oct 29 10:00:18 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com> * gems/bundled_gems: Update latest version of bundled gems. @@ -154,6 +154,7 @@ with all sufficient information, see the ChangeLog file. along the +num+ -th row or column. * Vector.basis(size:, index:) returns the specified basis vector * Unary - and + added for Vector and Matrix + * Vector#dot and #cross are aliases for #inner_product and #cross_product * Pathname * Pathname#/ is aliased to Pathname#+. diff --git a/lib/matrix.rb b/lib/matrix.rb index b39973b93f..cdaa55f157 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1684,8 +1684,8 @@ end # * #-@ # # Vector functions: -# * #inner_product(v) -# * #cross_product(v) +# * #inner_product(v), dot(v) +# * #cross_product(v), cross(v) # * #collect # * #magnitude # * #map @@ -1944,6 +1944,7 @@ class Vector } p end + alias_method :dot, :inner_product # # Returns the cross product of this vector with the other. @@ -1955,6 +1956,7 @@ class Vector v[0]*@elements[2] - v[2]*@elements[0], v[1]*@elements[0] - v[0]*@elements[1] ] end + alias_method :cross, :cross_product # # Like Array#collect. diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb index fa29496451..4e2bca6ef6 100644 --- a/test/matrix/test_vector.rb +++ b/test/matrix/test_vector.rb @@ -131,6 +131,7 @@ class TestVector < Test::Unit::TestCase def test_inner_product assert_equal(1+4+9, @v1.inner_product(@v1)) + assert_equal(1+4+9, @v1.dot(@v1)) end def test_r @@ -168,5 +169,7 @@ class TestVector < Test::Unit::TestCase def test_cross_product v = Vector[1, 0, 0].cross_product Vector[0, 1, 0] assert_equal(Vector[0, 0, 1], v) + v = Vector[1, 0, 0].cross Vector[0, 1, 0] + assert_equal(Vector[0, 0, 1], v) end end |