зеркало из https://github.com/github/ruby.git
* lib/matrix.rb: Add aliases for Vector#cross & dot
patch by gogo tanaka [#10352] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9419ecc6e9
Коммит
dc38c87779
|
@ -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.
|
||||
|
|
1
NEWS
1
NEWS
|
@ -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#+.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче