Skip to content

Commit

Permalink
Fix: magnitude calculation issue in vec2 and vec3 angle functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonO123 authored and greggman committed May 11, 2024
1 parent 3a3cbb7 commit 44588fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/vec2-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export function addScaled(a: Vec2, b: Vec2, scale: number, dst?: Vec2) {
export function angle(a: Vec2, b: Vec2): number {
const ax = a[0];
const ay = a[1];
const bx = a[0];
const by = a[1];
const bx = b[0];
const by = b[1];
const mag1 = Math.sqrt(ax * ax + ay * ay);
const mag2 = Math.sqrt(bx * bx + by * by);
const mag = mag1 * mag2;
Expand Down
6 changes: 3 additions & 3 deletions src/vec3-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ export function angle(a: Vec3, b: Vec3): number {
const ax = a[0];
const ay = a[1];
const az = a[2];
const bx = a[0];
const by = a[1];
const bz = a[2];
const bx = b[0];
const by = b[1];
const bz = b[2];
const mag1 = Math.sqrt(ax * ax + ay * ay + az * az);
const mag2 = Math.sqrt(bx * bx + by * by + bz * bz);
const mag = mag1 * mag2;
Expand Down
2 changes: 1 addition & 1 deletion test/tests/vec2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function check(Type) {
{ a: [1, 0], b: [ 0, 1], expected: Math.PI / 2, },
{ a: [1, 0], b: [-1, 0], expected: Math.PI, },
{ a: [1, 0], b: [ 1, 0], expected: 0, },
{ a: [1, 2], b: [ 4, 5], expected: 0.225726 },
{ a: [1, 2], b: [ 4, 5], expected: 0.2110933, },
{ a: [1, 0], b: [ 0, Number.POSITIVE_INFINITY], expected: Math.PI / 2, },
];
for (const {a, b, expected} of tests) {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/vec3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function check(Type) {
{ a: [1, 0, 0], b: [ 0, 1, 0], expected: Math.PI / 2, },
{ a: [1, 0, 0], b: [-1, 0, 0], expected: Math.PI, },
{ a: [1, 0, 0], b: [ 1, 0, 0], expected: 0, },
{ a: [1, 2, 3], b: [ 4, 5, 6], expected: 0.225726 },
{ a: [1, 2, 3], b: [ 4, 5, 6], expected: 0.2257261 },
{ a: [1, 0, 0], b: [ 0, Number.POSITIVE_INFINITY, 0], expected: Math.PI / 2, },
];
for (const {a, b, expected} of tests) {
Expand Down

0 comments on commit 44588fe

Please sign in to comment.