[ruby-core:68069] [Ruby trunk - Bug #10840] [Closed] documentation for Vector#cross_product in module 'matrix' is inconsistent

From: ruby-core@...
Date: 2015-02-09 02:23:33 UTC
List: ruby-core #68069
Issue #10840 has been updated by Marc-Andre Lafortune.

Status changed from Open to Closed

The bug was fixed in 2.1.3, so if you are looking at the code in the doc for 2.1.0, you will get the wrong code obviously.

In short, refer to the doc & source for 2.1.3, 2.1.4, 2.1.5 or 2.2.0, like:
http://ruby-doc.org/stdlib-2.1.3/libdoc/matrix/rdoc/Vector.html#method-i-cross_product
http://ruby-doc.org/stdlib-2.2.0/libdoc/matrix/rdoc/Vector.html#method-i-cross_product

----------------------------------------
Bug #10840: documentation for Vector#cross_product  in module 'matrix' is inconsistent
https://bugs.ruby-lang.org/issues/10840#change-51453

* Author: Ana Johnson
* Status: Closed
* Priority: Low
* Assignee: 
* ruby -v: http://ruby-doc.org/stdlib-2.1.0/
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
the documentation of cross_product is inconsistent. The doc says:
Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1]

which seems good to me, but the definition given in the "click to toggle source" actually produces: Vector[0,0,-1], which according to a closed bug report seems to be what the function actually once produced. The documented code is still wrong. this would be correct and clear:

def cross_product(v)
  Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3
  Vector[ @elements[1]*v[2] - @elements[2]*v[1],
          @elements[2]*v[0] - @elements[0]*v[2],
          @elements[0]*v[1] - @elements[1]*v[0] ]
end

I recommend also altering the demonstration code so that a reasonably complete test case is shown:

Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1]
Vector[0, 1, 0].cross_product Vector[0, 0, 1] => Vector[1, 0, 0]
Vector[0, 0, 1].cross_product Vector[1, 0, 0] => Vector[0, 1, 0]



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next