Skip to content

Commit

Permalink
fix(vectors): add opt normalize for angleBetween2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 3, 2018
1 parent c0fbb4e commit 25ea00c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/vectors/src/vec2.ts
Expand Up @@ -244,7 +244,7 @@ export const heading2 = (a: ReadonlyVec, ia = 0, sa = 1) =>

export const angleBetween2 = (a: ReadonlyVec, b: ReadonlyVec, normalize = false, ia = 0, ib = 0, sa = 1, sb = 1): number =>
normalize ?
angleBetween2(get2(a, ia, sa), get2(b, ib, sb)) :
angleBetween2(normalize2(get2(a, ia, sa)), normalize2(get2(b, ib, sb))) :
Math.acos(dot2(a, b, ia, ib, sa, sb));

export const bisect2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1, sb = 1) => {
Expand All @@ -254,7 +254,7 @@ export const bisect2 = (a: ReadonlyVec, b: ReadonlyVec, ia = 0, ib = 0, sa = 1,

export const toPolar2 = (a: Vec, ia = 0, sa = 1) => {
const x = a[ia], y = a[ia + sa];
return setS2(a, Math.sqrt(x * x + y * y), atan2Abs1(y, x), ia, sa);
return setS2(a, Math.sqrt(x * x + y * y), Math.atan2(y, x), ia, sa);
};

export const toCartesian2 = (a: Vec, b: ReadonlyVec = ZERO4, ia = 0, ib = 0, sa = 1, sb = 1) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vectors/src/vec3.ts
Expand Up @@ -337,15 +337,15 @@ export const headingYZ3 = (a: ReadonlyVec, ia = 0, sa = 1) =>

export const angleBetween3 = (a: ReadonlyVec, b: ReadonlyVec, normalize = false, ia = 0, ib = 0, sa = 1, sb = 1): number =>
normalize ?
angleBetween3(get3(a, ia, sa), get3(b, ib, sb)) :
angleBetween3(normalize3(get3(a, ia, sa)), normalize3(get3(b, ib, sb))) :
Math.acos(dot3(a, b, ia, ib, sa, sb));

export const toSpherical3 = (a: Vec, ia = 0, sa = 1) => {
const x = a[ia];
const y = a[ia + sa];
const z = a[ia + 2 * sa];
const r = Math.sqrt(x * x + y * y + z * z);
return setS3(a, r, Math.asin(z / r), atan2Abs1(y, x), ia, sa);
return setS3(a, r, Math.asin(z / r), Math.atan2(y, x), ia, sa);
};

export const toCartesian3 = (a: Vec, b: ReadonlyVec = ZERO4, ia = 0, ib = 0, sa = 1, sb = 1) => {
Expand Down

0 comments on commit 25ea00c

Please sign in to comment.