diff options
author | Keuin <[email protected]> | 2022-04-20 22:04:37 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-20 22:04:37 +0800 |
commit | 699287623d51be688f2af0a01fedcf90d035da13 (patch) | |
tree | 4c563ebfb810efb78acca0796b5b49d594e69c05 | |
parent | bfc5e815e6e157291ad653b9ea97bb12ca8bc835 (diff) |
Bugfix: vec3::cross was implemented and tested incorrectly.
-rw-r--r-- | test_vec.cpp | 10 | ||||
-rw-r--r-- | vec.h | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/test_vec.cpp b/test_vec.cpp index 9739160..1c9390f 100644 --- a/test_vec.cpp +++ b/test_vec.cpp @@ -25,15 +25,21 @@ TEST(Vec, VecMin) { } TEST(Vec, CrossProduct) { - vec3i a{1, 1, 1}, b{2, 2, 2}, c{3, 4, 5}, d{6, 7, 8}, e{-3, -6, -3}; + vec3i a{1, 1, 1}, b{2, 2, 2}, c{3, 4, 5}, d{6, 7, 8}, e{-3, 6, -3}; ASSERT_EQ(cross(a, b), vec3i{}); ASSERT_EQ(a.cross(b), vec3i{}); ASSERT_EQ(cross(c, d), e); ASSERT_EQ(c.cross(d), e); - vec3d f{3, 4, 5}, g{6, 7, 8}, h{-3, -6, -3}; + vec3d f{3, 4, 5}, g{6, 7, 8}, h{-3, 6, -3}; ASSERT_EQ(cross(f, g), h); ASSERT_EQ(f.cross(g), h); + + vec3d u{2, -2, -2}, v{2.5, -5, -2.5}, w{-5, 0, -5}; + ASSERT_EQ(cross(u, v), w); + + vec3d x{1.6, 3.5, 11}, y{3, 7, 15}, z{-24.5, 9, 0.7}; + ASSERT_EQ(cross(x, y), z); } TEST(Vec, DotProduct) { @@ -76,7 +76,7 @@ struct vec3 { // cross product (aka outer product, or vector product, producing a vector) vec3 cross(const vec3 &b) const { - return vec3{.x=y * b.z - z * b.y, .y=x * b.z - z * b.x, .z=x * b.y - y * b.x}; + return vec3{.x=y * b.z - z * b.y, .y=z * b.x - x * b.z, .z=x * b.y - y * b.x}; } // Multiply with b on every dimension. |