[前][次][番号順一覧][スレッド一覧]

ruby-changes:36100

From: marcandre <ko1@a...>
Date: Wed, 29 Oct 2014 11:43:11 +0900 (JST)
Subject: [ruby-changes:36100] marcandRe: r48181 (trunk): * lib/matrix.rb: Add aliases for Vector#cross & dot

marcandre	2014-10-29 11:42:56 +0900 (Wed, 29 Oct 2014)

  New Revision: 48181

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48181

  Log:
    * lib/matrix.rb: Add aliases for Vector#cross & dot
      patch by gogo tanaka [#10352]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/matrix.rb
    trunk/test/matrix/test_vector.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48180)
+++ ChangeLog	(revision 48181)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct 29 11:42:33 2014  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* 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@g...>
 
 	* gems/bundled_gems: Update latest version of bundled gems.
Index: lib/matrix.rb
===================================================================
--- lib/matrix.rb	(revision 48180)
+++ lib/matrix.rb	(revision 48181)
@@ -1684,8 +1684,8 @@ end https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1684
 # * #-@
 #
 # 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 https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1944
     }
     p
   end
+  alias_method :dot, :inner_product
 
   #
   # Returns the cross product of this vector with the other.
@@ -1955,6 +1956,7 @@ class Vector https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1956
             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.
Index: NEWS
===================================================================
--- NEWS	(revision 48180)
+++ NEWS	(revision 48181)
@@ -154,6 +154,7 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L154
       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#+.
Index: test/matrix/test_vector.rb
===================================================================
--- test/matrix/test_vector.rb	(revision 48180)
+++ test/matrix/test_vector.rb	(revision 48181)
@@ -131,6 +131,7 @@ class TestVector < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_vector.rb#L131
 
   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 https://github.com/ruby/ruby/blob/trunk/test/matrix/test_vector.rb#L169
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]