Skip to content

Commit 44588fe

Browse files
JacksonO123greggman
authored andcommitted
Fix: magnitude calculation issue in vec2 and vec3 angle functions
1 parent 3a3cbb7 commit 44588fe

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/vec2-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ export function addScaled(a: Vec2, b: Vec2, scale: number, dst?: Vec2) {
158158
export function angle(a: Vec2, b: Vec2): number {
159159
const ax = a[0];
160160
const ay = a[1];
161-
const bx = a[0];
162-
const by = a[1];
161+
const bx = b[0];
162+
const by = b[1];
163163
const mag1 = Math.sqrt(ax * ax + ay * ay);
164164
const mag2 = Math.sqrt(bx * bx + by * by);
165165
const mag = mag1 * mag2;

src/vec3-impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ export function angle(a: Vec3, b: Vec3): number {
168168
const ax = a[0];
169169
const ay = a[1];
170170
const az = a[2];
171-
const bx = a[0];
172-
const by = a[1];
173-
const bz = a[2];
171+
const bx = b[0];
172+
const by = b[1];
173+
const bz = b[2];
174174
const mag1 = Math.sqrt(ax * ax + ay * ay + az * az);
175175
const mag2 = Math.sqrt(bx * bx + by * by + bz * bz);
176176
const mag = mag1 * mag2;

test/tests/vec2-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function check(Type) {
102102
{ a: [1, 0], b: [ 0, 1], expected: Math.PI / 2, },
103103
{ a: [1, 0], b: [-1, 0], expected: Math.PI, },
104104
{ a: [1, 0], b: [ 1, 0], expected: 0, },
105-
{ a: [1, 2], b: [ 4, 5], expected: 0.225726 },
105+
{ a: [1, 2], b: [ 4, 5], expected: 0.2110933, },
106106
{ a: [1, 0], b: [ 0, Number.POSITIVE_INFINITY], expected: Math.PI / 2, },
107107
];
108108
for (const {a, b, expected} of tests) {

test/tests/vec3-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function check(Type) {
102102
{ a: [1, 0, 0], b: [ 0, 1, 0], expected: Math.PI / 2, },
103103
{ a: [1, 0, 0], b: [-1, 0, 0], expected: Math.PI, },
104104
{ a: [1, 0, 0], b: [ 1, 0, 0], expected: 0, },
105-
{ a: [1, 2, 3], b: [ 4, 5, 6], expected: 0.225726 },
105+
{ a: [1, 2, 3], b: [ 4, 5, 6], expected: 0.2257261 },
106106
{ a: [1, 0, 0], b: [ 0, Number.POSITIVE_INFINITY, 0], expected: Math.PI / 2, },
107107
];
108108
for (const {a, b, expected} of tests) {

0 commit comments

Comments
 (0)