From aba19e9f43a571b022479bbb10b490c46e16c574 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 2 Oct 2021 07:55:11 -0400 Subject: math: vector: Fix vec2-cross. --- chickadee/math/vector.scm | 4 ++-- tests/math/vector.scm | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/chickadee/math/vector.scm b/chickadee/math/vector.scm index 747200e..218edc7 100644 --- a/chickadee/math/vector.scm +++ b/chickadee/math/vector.scm @@ -247,8 +247,8 @@ polar coordinate (R, THETA) with an arbitrary ORIGIN point." (* (vec3-z v1) (vec3-z v2)))) (define-inlinable (vec2-cross v1 v2) - (- (* (vec2-x v1) (vec2-x v2)) - (* (vec2-y v1) (vec2-y v2)))) + (- (* (vec2-x v1) (vec2-y v2)) + (* (vec2-y v1) (vec2-x v2)))) (define-inlinable (vec3-cross! dest v1 v2) (set-vec3! dest diff --git a/tests/math/vector.scm b/tests/math/vector.scm index e87c241..c3fc900 100644 --- a/tests/math/vector.scm +++ b/tests/math/vector.scm @@ -38,8 +38,13 @@ (vec2-magnitude (vec2 0.0 0.0)) 0.0)) (test-equal "vec2-dot" (vec2-dot (vec2 1.0 2.0) (vec2 3.0 4.0)) 11.0) - (test-equal "vec2-cross" - (vec2-cross (vec2 1.0 2.0) (vec2 3.0 4.0)) -5.0) + (test-group "vec2-cross" + (test-equal "same line" + (vec2-cross (vec2 1.0 2.0) (vec2 2.0 4.0)) 0.0) + (test-equal "clockwise" + (vec2-cross (vec2 1.0 2.0) (vec2 0.0 2.0)) 2.0) + (test-equal "counter-clockwise" + (vec2-cross (vec2 1.0 2.0) (vec2 2.0 0.0)) -4.0)) (test-approximate "vec2-normalize" (vec2-magnitude (vec2-normalize (vec2 3.7 4.9))) 1.0 0.001) (test-group "vec2*" -- cgit v1.2.3