Socket
Socket
Sign inDemoInstall

@thi.ng/math

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/math - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

crossing.d.ts

19

api.d.ts

@@ -21,1 +21,20 @@ export declare const PI: number;

export declare let EPS: number;
export declare const enum Crossing {
/**
* lines A & B are equal
*/
EQUAL = 0,
/**
* lines A & B are flat (all same values)
*/
FLAT = 1,
/**
* line A crossed under B
*/
UNDER = 2,
/**
* line A crossed over B
*/
OVER = 3,
OTHER = 4
}

@@ -21,1 +21,21 @@ export const PI = Math.PI;

export let EPS = 1e-6;
export var Crossing;
(function (Crossing) {
/**
* lines A & B are equal
*/
Crossing[Crossing["EQUAL"] = 0] = "EQUAL";
/**
* lines A & B are flat (all same values)
*/
Crossing[Crossing["FLAT"] = 1] = "FLAT";
/**
* line A crossed under B
*/
Crossing[Crossing["UNDER"] = 2] = "UNDER";
/**
* line A crossed over B
*/
Crossing[Crossing["OVER"] = 3] = "OVER";
Crossing[Crossing["OTHER"] = 4] = "OTHER";
})(Crossing || (Crossing = {}));

@@ -6,2 +6,14 @@ # Change Log

# [1.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@1.2.3...@thi.ng/math@1.3.0) (2019-05-22)
### Features
* **math:** add extrema & crossing fns and Crossing enum ([e102f39](https://github.com/thi-ng/umbrella/commit/e102f39))
* **math:** add sigmoid / sigmoid11 fns ([3f085a3](https://github.com/thi-ng/umbrella/commit/3f085a3))
## [1.2.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@1.2.2...@thi.ng/math@1.2.3) (2019-04-24)

@@ -8,0 +20,0 @@

2

index.d.ts
export * from "./api";
export * from "./abs";
export * from "./angle";
export * from "./crossing";
export * from "./eqdelta";
export * from "./extrema";
export * from "./fit";

@@ -6,0 +8,0 @@ export * from "./interval";

export * from "./api";
export * from "./abs";
export * from "./angle";
export * from "./crossing";
export * from "./eqdelta";
export * from "./extrema";
export * from "./fit";

@@ -6,0 +8,0 @@ export * from "./interval";

@@ -25,2 +25,9 @@ 'use strict';

let EPS = 1e-6;
(function (Crossing) {
Crossing[Crossing["EQUAL"] = 0] = "EQUAL";
Crossing[Crossing["FLAT"] = 1] = "FLAT";
Crossing[Crossing["UNDER"] = 2] = "UNDER";
Crossing[Crossing["OVER"] = 3] = "OVER";
Crossing[Crossing["OTHER"] = 4] = "OTHER";
})(exports.Crossing || (exports.Crossing = {}));

@@ -78,2 +85,43 @@ const absDiff = (x, y) => Math.abs(x - y);

const isCrossOver = (a1, a2, b1, b2) => a1 < b1 && a2 > b2;
const isCrossUnder = (a1, a2, b1, b2) => a1 > b1 && a2 < b2;
const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => {
if (isCrossOver(a1, a2, b1, b2)) {
return 3 ;
}
else if (isCrossUnder(a1, a2, b1, b2)) {
return 2 ;
}
return eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps)
? eqDelta(a1, b2, eps)
? 1
: 0
: 4 ;
};
const isMinima = (a, b, c) => a > b && b < c;
const isMaxima = (a, b, c) => a < b && b > c;
const index = (pred, values, from = 0, to = values.length) => {
to--;
for (let i = from + 1; i < to; i++) {
if (pred(values[i - 1], values[i], values[i + 1])) {
return i;
}
}
return -1;
};
const minimaIndex = (values, from = 0, to = values.length) => index(isMinima, values, from, to);
const maximaIndex = (values, from = 0, to = values.length) => index(isMaxima, values, from, to);
function* indices(fn, vals, from = 0, to = vals.length) {
while (from < to) {
const i = fn(vals, from, to);
if (i < 0)
return;
yield i;
from = i + 1;
}
}
const minimaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const maximaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const clamp = (x, min, max) => x < min ? min : x > max ? max : x;

@@ -196,2 +244,4 @@ const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);

};
const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1)));
const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t));

@@ -314,2 +364,3 @@ const fmod = (a, b) => a - b * Math.floor(a / b);

exports.clamp11 = clamp11;
exports.classifyCrossing = classifyCrossing;
exports.cosine = cosine;

@@ -341,2 +392,6 @@ exports.cossin = cossin;

exports.inRange = inRange;
exports.isCrossOver = isCrossOver;
exports.isCrossUnder = isCrossUnder;
exports.isMaxima = isMaxima;
exports.isMinima = isMinima;
exports.loc = loc;

@@ -346,2 +401,4 @@ exports.max2id = max2id;

exports.max4id = max4id;
exports.maximaIndex = maximaIndex;
exports.maximaIndices = maximaIndices;
exports.min2id = min2id;

@@ -351,2 +408,4 @@ exports.min3id = min3id;

exports.minError = minError;
exports.minimaIndex = minimaIndex;
exports.minimaIndices = minimaIndices;
exports.mix = mix;

@@ -365,2 +424,4 @@ exports.mixBilinear = mixBilinear;

exports.sec = sec;
exports.sigmoid = sigmoid;
exports.sigmoid11 = sigmoid11;
exports.sign = sign;

@@ -367,0 +428,0 @@ exports.simplifyRatio = simplifyRatio;

@@ -27,2 +27,9 @@ (function (global, factory) {

let EPS = 1e-6;
(function (Crossing) {
Crossing[Crossing["EQUAL"] = 0] = "EQUAL";
Crossing[Crossing["FLAT"] = 1] = "FLAT";
Crossing[Crossing["UNDER"] = 2] = "UNDER";
Crossing[Crossing["OVER"] = 3] = "OVER";
Crossing[Crossing["OTHER"] = 4] = "OTHER";
})(exports.Crossing || (exports.Crossing = {}));

@@ -80,2 +87,43 @@ const absDiff = (x, y) => Math.abs(x - y);

const isCrossOver = (a1, a2, b1, b2) => a1 < b1 && a2 > b2;
const isCrossUnder = (a1, a2, b1, b2) => a1 > b1 && a2 < b2;
const classifyCrossing = (a1, a2, b1, b2, eps = EPS) => {
if (isCrossOver(a1, a2, b1, b2)) {
return 3 ;
}
else if (isCrossUnder(a1, a2, b1, b2)) {
return 2 ;
}
return eqDelta(a1, b1, eps) && eqDelta(a2, b2, eps)
? eqDelta(a1, b2, eps)
? 1
: 0
: 4 ;
};
const isMinima = (a, b, c) => a > b && b < c;
const isMaxima = (a, b, c) => a < b && b > c;
const index = (pred, values, from = 0, to = values.length) => {
to--;
for (let i = from + 1; i < to; i++) {
if (pred(values[i - 1], values[i], values[i + 1])) {
return i;
}
}
return -1;
};
const minimaIndex = (values, from = 0, to = values.length) => index(isMinima, values, from, to);
const maximaIndex = (values, from = 0, to = values.length) => index(isMaxima, values, from, to);
function* indices(fn, vals, from = 0, to = vals.length) {
while (from < to) {
const i = fn(vals, from, to);
if (i < 0)
return;
yield i;
from = i + 1;
}
}
const minimaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const maximaIndices = (values, from = 0, to = values.length) => indices(minimaIndex, values, from, to);
const clamp = (x, min, max) => x < min ? min : x > max ? max : x;

@@ -198,2 +246,4 @@ const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);

};
const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1)));
const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t));

@@ -316,2 +366,3 @@ const fmod = (a, b) => a - b * Math.floor(a / b);

exports.clamp11 = clamp11;
exports.classifyCrossing = classifyCrossing;
exports.cosine = cosine;

@@ -343,2 +394,6 @@ exports.cossin = cossin;

exports.inRange = inRange;
exports.isCrossOver = isCrossOver;
exports.isCrossUnder = isCrossUnder;
exports.isMaxima = isMaxima;
exports.isMinima = isMinima;
exports.loc = loc;

@@ -348,2 +403,4 @@ exports.max2id = max2id;

exports.max4id = max4id;
exports.maximaIndex = maximaIndex;
exports.maximaIndices = maximaIndices;
exports.min2id = min2id;

@@ -353,2 +410,4 @@ exports.min3id = min3id;

exports.minError = minError;
exports.minimaIndex = minimaIndex;
exports.minimaIndices = minimaIndices;
exports.mix = mix;

@@ -367,2 +426,4 @@ exports.mixBilinear = mixBilinear;

exports.sec = sec;
exports.sigmoid = sigmoid;
exports.sigmoid11 = sigmoid11;
exports.sign = sign;

@@ -369,0 +430,0 @@ exports.simplifyRatio = simplifyRatio;

@@ -52,1 +52,15 @@ export declare const mix: (a: number, b: number, t: number) => number;

export declare const sinc: (k: number, t: number) => number;
/**
* Sigmoid function for inputs in [0..1] interval.
*
* @param k
* @param t
*/
export declare const sigmoid: (k: number, t: number) => number;
/**
* Sigmoid function for inputs in [-1..+1] interval.
*
* @param k
* @param t
*/
export declare const sigmoid11: (k: number, t: number) => number;

@@ -1,2 +0,2 @@

import { PI, HALF_PI } from "./api";
import { HALF_PI, PI } from "./api";
export const mix = (a, b, t) => a + (b - a) * t;

@@ -76,1 +76,15 @@ /**

};
/**
* Sigmoid function for inputs in [0..1] interval.
*
* @param k
* @param t
*/
export const sigmoid = (k, t) => 1 / (1 + Math.exp(-k * (2 * t - 1)));
/**
* Sigmoid function for inputs in [-1..+1] interval.
*
* @param k
* @param t
*/
export const sigmoid11 = (k, t) => 1 / (1 + Math.exp(-k * t));

4

package.json
{
"name": "@thi.ng/math",
"version": "1.2.3",
"version": "1.3.0",
"description": "Assorted common math functions & utilities",

@@ -47,3 +47,3 @@ "module": "./index.js",

"sideEffects": false,
"gitHead": "38b2c61a9a7c1344889b81cd6eb3dcd601ceb443"
"gitHead": "5a4226d52724f320fb25656f08addb2825375fee"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc