Skip to content

Commit

Permalink
refactor(geom-splines): update deps, imports, use new Fn types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 5, 2020
1 parent 4eb9248 commit 780a7b7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/geom-splines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@microsoft/api-extractor": "^7.9.11",
"@thi.ng/api": "^6.12.3",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.1",
"mocha": "^8.1.2",
Expand All @@ -49,7 +50,6 @@
"typescript": "^4.0.2"
},
"dependencies": {
"@thi.ng/api": "^6.12.3",
"@thi.ng/checks": "^2.7.7",
"@thi.ng/geom-api": "^1.0.33",
"@thi.ng/geom-arc": "^0.3.11",
Expand Down
3 changes: 2 additions & 1 deletion packages/geom-splines/src/cubic-arc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FnU2 } from "@thi.ng/api";
import { pointAtTheta } from "@thi.ng/geom-arc";
import { EPS, HALF_PI, PI, roundEps, sincos } from "@thi.ng/math";
import { magSq2, ReadonlyVec, Vec } from "@thi.ng/vectors";
Expand Down Expand Up @@ -34,7 +35,7 @@ export const cubicFromArc = (
return [cubicFromLine(p, q)];
}

const mapP = (x: number, y: number) => {
const mapP: FnU2<number, Vec> = (x, y) => {
x *= rx;
y *= ry;
return [c * x - s * y + pos[0], s * x + c * y + pos[1]];
Expand Down
8 changes: 2 additions & 6 deletions packages/geom-splines/src/cubic-bounds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FnU4 } from "@thi.ng/api";
import { mixCubic } from "@thi.ng/math";
import type { ReadonlyVec, Vec, VecPair } from "@thi.ng/vectors";

Expand Down Expand Up @@ -48,12 +49,7 @@ const axisBounds = (
}
};

export const cubicBounds = (
a: ReadonlyVec,
b: ReadonlyVec,
c: ReadonlyVec,
d: ReadonlyVec
): VecPair => {
export const cubicBounds: FnU4<ReadonlyVec, VecPair> = (a, b, c, d) => {
const min: Vec = [];
const max: Vec = [];
for (let i = a.length; --i >= 0; ) {
Expand Down
3 changes: 2 additions & 1 deletion packages/geom-splines/src/cubic-line.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FnU2 } from "@thi.ng/api";
import { mixN, set, Vec } from "@thi.ng/vectors";

/**
Expand All @@ -8,7 +9,7 @@ import { mixN, set, Vec } from "@thi.ng/vectors";
* @param a - line endpoint
* @param b - line endpoint
*/
export const cubicFromLine = (a: Vec, b: Vec) => [
export const cubicFromLine: FnU2<Vec, Vec[]> = (a, b) => [
set([], a),
mixN([], a, b, 1 / 3),
mixN([], b, a, 1 / 3),
Expand Down
3 changes: 2 additions & 1 deletion packages/geom-splines/src/cubic-quadratic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FnU3 } from "@thi.ng/api";
import { mixN, set, Vec } from "@thi.ng/vectors";

export const cubicFromQuadratic = (a: Vec, b: Vec, c: Vec) => [
export const cubicFromQuadratic: FnU3<Vec, Vec[]> = (a, b, c) => [
set([], a),
mixN([], a, b, 2 / 3),
mixN([], c, b, 2 / 3),
Expand Down
12 changes: 5 additions & 7 deletions packages/geom-splines/src/quadratic-bounds.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import type { FnN3, FnU3 } from "@thi.ng/api";
import { clamp01, inRange } from "@thi.ng/math";
import { max, min, ReadonlyVec, VecPair } from "@thi.ng/vectors";

const solveQuadratic = (a: number, b: number, c: number) => {
const solveQuadratic: FnN3 = (a, b, c) => {
const t = clamp01((a - b) / (a - 2.0 * b + c));
const s = 1 - t;
return s * s * a + 2.0 * s * t * b + t * t * c;
};

const inBounds = (p: ReadonlyVec, min: ReadonlyVec, max: ReadonlyVec) => {
const inBounds: FnU3<ReadonlyVec, boolean> = (p, min, max) => {
for (let i = p.length; --i >= 0; ) {
if (!inRange(p[i], min[i], max[i])) return false;
}
return true;
};

export const quadraticBounds = (
a: ReadonlyVec,
b: ReadonlyVec,
c: ReadonlyVec
): VecPair => {
export const quadraticBounds: FnU3<ReadonlyVec, VecPair> = (a, b, c) => {
const mi = min([], a, c);
const ma = max([], a, c);
if (!inBounds(b, mi, ma)) {
Expand Down
5 changes: 3 additions & 2 deletions packages/geom-splines/src/quadratic-line.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addmN, ReadonlyVec, set } from "@thi.ng/vectors";
import type { FnU2 } from "@thi.ng/api";
import { addmN, ReadonlyVec, set, Vec } from "@thi.ng/vectors";

export const quadraticFromLine = (a: ReadonlyVec, b: ReadonlyVec) => [
export const quadraticFromLine: FnU2<ReadonlyVec, Vec[]> = (a, b) => [
set([], a),
addmN([], a, b, 0.5),
set([], b),
Expand Down

0 comments on commit 780a7b7

Please sign in to comment.