Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: magnitude calculation issue in vec2 and vec3 angle functions #28

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading