@thi.ng/math
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,2 @@ | ||
export declare const sincos: (theta: number) => number[]; | ||
export declare const absTheta: (theta: number) => number; | ||
@@ -2,0 +3,0 @@ export declare const angleDist: (a: number, b: number) => number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const api_1 = require("./api"); | ||
exports.sincos = (theta) => [Math.sin(theta), Math.cos(theta)]; | ||
exports.absTheta = (theta) => (theta %= api_1.TAU, theta < 0 ? api_1.TAU + theta : theta); | ||
@@ -5,0 +6,0 @@ exports.angleDist = (a, b) => (a = exports.absTheta((b % api_1.TAU) - (a % api_1.TAU)), a > api_1.PI ? api_1.TAU - a : a); |
@@ -6,2 +6,14 @@ # Change Log | ||
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@0.1.0...@thi.ng/math@0.2.0) (2018-10-21) | ||
### Features | ||
* **math:** add sincos() & roundEps() ([f891c41](https://github.com/thi-ng/umbrella/commit/f891c41)) | ||
* **math:** migrate mixCubic()/mixQuadratic() from geom package ([4a47daa](https://github.com/thi-ng/umbrella/commit/4a47daa)) | ||
# 0.1.0 (2018-10-17) | ||
@@ -8,0 +20,0 @@ |
@@ -19,2 +19,4 @@ export declare const mix: (a: number, b: number, t: number) => number; | ||
export declare const mixBilinear: (a: number, b: number, c: number, d: number, u: number, v: number) => number; | ||
export declare const mixQuadratic: (a: number, b: number, c: number, t: number) => number; | ||
export declare const mixCubic: (a: number, b: number, c: number, d: number, t: number) => number; | ||
export declare const tween: (f: (t: number) => number, from: number, to: number) => (t: number) => number; | ||
@@ -21,0 +23,0 @@ /** |
10
mix.js
@@ -22,2 +22,12 @@ "use strict"; | ||
exports.mixBilinear = (a, b, c, d, u, v) => exports.mix(exports.mix(a, b, u), exports.mix(c, d, u), v); | ||
exports.mixQuadratic = (a, b, c, t) => { | ||
const s = 1 - t; | ||
return a * s * s + b * 2 * s * t + c * t * t; | ||
}; | ||
exports.mixCubic = (a, b, c, d, t) => { | ||
const t2 = t * t; | ||
const s = 1 - t; | ||
const s2 = s * s; | ||
return a * s2 * s + b * 3 * s2 * t + c * 3 * t2 * s + d * t2 * t; | ||
}; | ||
exports.tween = (f, from, to) => (t) => exports.mix(from, to, f(t)); | ||
@@ -24,0 +34,0 @@ /** |
{ | ||
"name": "@thi.ng/math", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Assorted common math functions & utilities", | ||
@@ -24,7 +24,7 @@ "main": "./index.js", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.5.5", | ||
"@types/node": "^10.12.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"typedoc": "^0.11.1", | ||
"typescript": "^3.0.1" | ||
"nyc": "^13.1.0", | ||
"typedoc": "^0.13.0", | ||
"typescript": "^3.1.3" | ||
}, | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "6e563377f8cdbdda904559c956a2a558eb9fed64" | ||
"gitHead": "5bb513915cb3c533bd4278f6f365389b3664f4d1" | ||
} |
@@ -11,1 +11,8 @@ /** | ||
export declare const roundTo: (x: number, prec?: number) => number; | ||
/** | ||
* Only rounds `x` to nearest int if `fract(x)` < `eps` or > `1-eps`. | ||
* | ||
* @param x | ||
* @param eps | ||
*/ | ||
export declare const roundEps: (x: number, eps?: number) => number; |
13
prec.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const api_1 = require("./api"); | ||
/** | ||
@@ -13,1 +14,13 @@ * Returns `a - b * floor(a/b)` | ||
exports.roundTo = (x, prec = 1) => Math.round(x / prec) * prec; | ||
/** | ||
* Only rounds `x` to nearest int if `fract(x)` < `eps` or > `1-eps`. | ||
* | ||
* @param x | ||
* @param eps | ||
*/ | ||
exports.roundEps = (x, eps = api_1.EPS) => { | ||
const f = exports.fract(x); | ||
return f <= eps || f >= 1 - eps ? | ||
Math.round(x) : | ||
x; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36542
719