Project

General

Profile

Actions

Bug #10840

closed

documentation for Vector#cross_product in module 'matrix' is inconsistent

Added by anajilly (Ana Johnson) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
http://ruby-doc.org/stdlib-2.1.0/
[ruby-core:68067]

Description

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]

Updated by marcandre (Marc-Andre Lafortune) over 10 years ago

  • 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

Updated by usa (Usaku NAKAMURA) over 10 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED
Actions

Also available in: Atom PDF

Like0
Like0Like0