ruby-changes:34697
From: marcandre <ko1@a...>
Date: Fri, 11 Jul 2014 14:19:47 +0900 (JST)
Subject: [ruby-changes:34697] marcandRe: r46780 (trunk): * lib/matrix.rb: Fix sign for cross_product [#9499]
marcandre 2014-07-11 14:19:33 +0900 (Fri, 11 Jul 2014) New Revision: 46780 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46780 Log: * lib/matrix.rb: Fix sign for cross_product [#9499] Modified files: trunk/ChangeLog trunk/lib/matrix.rb trunk/test/matrix/test_vector.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46779) +++ ChangeLog (revision 46780) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jul 11 14:19:14 2014 Marc-Andre Lafortune <ruby-core@m...> + + * lib/matrix.rb: Fix sign for cross_product [#9499] + Fri Jul 11 11:11:50 2014 Koichi Sasada <ko1@a...> * benchmark/prepare_so_k_nucleotide.rb: use require_relative. Index: lib/matrix.rb =================================================================== --- lib/matrix.rb (revision 46779) +++ lib/matrix.rb (revision 46780) @@ -1811,9 +1811,9 @@ class Vector https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1811 # def cross_product(v) Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3 - Vector[ v[1]*@elements[2] - v[2]*@elements[1], - v[2]*@elements[0] - v[0]*@elements[2], - v[0]*@elements[1] - v[1]*@elements[0] ] + Vector[ v[2]*@elements[1] - v[1]*@elements[2], + v[0]*@elements[2] - v[2]*@elements[0], + v[1]*@elements[0] - v[0]*@elements[1] ] end # Index: test/matrix/test_vector.rb =================================================================== --- test/matrix/test_vector.rb (revision 46779) +++ test/matrix/test_vector.rb (revision 46780) @@ -146,4 +146,9 @@ class TestVector < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_vector.rb#L146 v = Vector[Rational(1,2), 0] assert_equal(0.5, v.norm) end + + def test_cross_product + v = Vector[1, 0, 0].cross_product Vector[0, 1, 0] + assert_equal(Vector[0, 0, 1], v) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/