Skip to content

Commit

Permalink
fix(vectors): update arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 9, 2019
1 parent b79d0c6 commit 6d213bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/vectors/src/jitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ReadonlyVec, Vec } from "./api";
import { randNorm } from "./random";

export const jitter = (
out: Vec,
out: Vec | null,
a: ReadonlyVec,
n = 1,
rnd: IRandom = SYSTEM
Expand Down
4 changes: 2 additions & 2 deletions packages/vectors/src/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EPS } from "@thi.ng/math";
import { Vec, VecOpVO } from "./api";
import { VecOpVO } from "./api";
import { mag } from "./mag";
import { mulN } from "./muln";
import { set } from "./set";
Expand All @@ -12,7 +12,7 @@ import { set } from "./set";
* @param v
* @param n
*/
export const normalize: VecOpVO<number> = (out: Vec | null, v: Vec, n = 1) => {
export const normalize: VecOpVO<number> = (out, v, n = 1) => {
!out && (out = v);
const m = mag(v);
return m >= EPS ? mulN(out, v, n / m) : out !== v ? set(out, v) : out;
Expand Down
10 changes: 5 additions & 5 deletions packages/vectors/src/ortho-normal.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ReadonlyVec, Vec } from "./api";
import { cross3 } from "./cross";
import { sub3 } from "./sub";
import { normalize } from "./normalize";
import { Vec, ReadonlyVec } from "./api";
import { sub3 } from "./sub";

/**
* Produces a vector which is perpendicular/normal to the plane spanned
* by given 3 input vectors. If `normalize` is true (default), the
* result vector will be normalized.
*
* ```
* orthoNormal3([], [0,0,0], [1,0,0], [0,1,0])
* // [0,0,1]
* orthoNormal3([], [0, 0, 0], [1, 0, 0], [0, 1, 0])
* // [0, 0, 1]
* ```
*
* @param out
Expand All @@ -20,7 +20,7 @@ import { Vec, ReadonlyVec } from "./api";
* @param normalize
*/
export const orthoNormal3 = (
out: Vec,
out: Vec | null,
a: ReadonlyVec,
b: ReadonlyVec,
c: ReadonlyVec,
Expand Down
9 changes: 7 additions & 2 deletions packages/vectors/src/random.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { IRandom, SYSTEM } from "@thi.ng/random";
import { MultiVecOpOOO, ReadonlyVec, Vec, VecOpOOO } from "./api";
import {
MultiVecOpOOO,
ReadonlyVec,
Vec,
VecOpOOO
} from "./api";
import { defHofOp } from "./internal/codegen";
import { normalize } from "./normalize";

Expand Down Expand Up @@ -33,7 +38,7 @@ export const [random, random2, random3, random4] = defHofOp<
* @param n
* @param rnd
*/
export const randNorm = (v: Vec, n = 1, rnd: IRandom = SYSTEM) => {
export const randNorm = (v: Vec | null, n = 1, rnd: IRandom = SYSTEM) => {
v = random(v, -1, 1, rnd);
return normalize(v, v, n);
};
Expand Down

0 comments on commit 6d213bd

Please sign in to comment.