Skip to content

Commit c8bffe8

Browse files
committed
add vec2d cross product test
1 parent 0a822ff commit c8bffe8

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/vecmath_spec_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ def test_array_zip
234234
assert_equal(zipped, expected)
235235
end
236236

237+
def test_cross # the cross product of 2D vectors is a float
238+
a = Vec2D.new(0, 0)
239+
b = Vec2D.new(100, 100)
240+
c = Vec2D.new(200, 200)
241+
# see http://mathworld.wolfram.com/Collinear.html for details
242+
assert((a - b).cross(b - c).zero?, 'Failed collinearity test using 2D vector product')
243+
end
244+
237245
def test_equals
238246
x, y, z = 1.0000001, 1.01, 0.0
239247
a = Vec3D.new(x, y)

0 commit comments

Comments
 (0)