@daeinc/array
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -26,2 +26,13 @@ /** | ||
/** | ||
* interpolates between two 1d array of any size. for now, numbers only. | ||
* | ||
* TODO: | ||
* - expand to take object, nested aray/ojbects. recursive. | ||
* @param arrStart array to start from | ||
* @param arrTarget array to interpolate to | ||
* @param t 0..1 | ||
* @returns 1d array | ||
*/ | ||
export declare const interpolateArray: (arrStart: number[], arrTarget: number[], t: number) => number[]; | ||
/** | ||
* check if all values of array is one. | ||
@@ -28,0 +39,0 @@ * @param arr array to evaluate |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unwrapArrayOfObjects = exports.isAnyZero = exports.isAnyOne = exports.isAllZero = exports.isAllOne = exports.getNonZeroIndices = exports.fillAndMap = exports.addToArray = void 0; | ||
exports.unwrapArrayOfObjects = exports.isAnyZero = exports.isAnyOne = exports.isAllZero = exports.isAllOne = exports.interpolateArray = exports.getNonZeroIndices = exports.fillAndMap = exports.addToArray = void 0; | ||
const math_1 = require("@daeinc/math"); | ||
/** | ||
@@ -58,2 +59,24 @@ * add to array in-place while limiting how many to keep history. | ||
/** | ||
* interpolates between two 1d array of any size. for now, numbers only. | ||
* | ||
* TODO: | ||
* - expand to take object, nested aray/ojbects. recursive. | ||
* @param arrStart array to start from | ||
* @param arrTarget array to interpolate to | ||
* @param t 0..1 | ||
* @returns 1d array | ||
*/ | ||
const interpolateArray = (arrStart, arrTarget, t) => { | ||
if (arrStart.length === 0 || arrTarget.length === 0) | ||
throw new Error("interpolateArray(): arrays cannot be empty"); | ||
if (arrStart.length !== arrTarget.length) | ||
throw new Error("interpolateArray(): length must be same"); | ||
return Array(arrStart.length) | ||
.fill(0) | ||
.map((_, i) => { | ||
return (0, math_1.mix)(arrStart[i], arrTarget[i], t); | ||
}); | ||
}; | ||
exports.interpolateArray = interpolateArray; | ||
/** | ||
* check if all values of array is one. | ||
@@ -60,0 +83,0 @@ * @param arr array to evaluate |
{ | ||
"name": "@daeinc/array", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Array utilities", | ||
@@ -33,3 +33,6 @@ "types": "./dist/index.d.ts", | ||
}, | ||
"homepage": "https://github.com/cdaein/array#readme" | ||
"homepage": "https://github.com/cdaein/array#readme", | ||
"dependencies": { | ||
"@daeinc/math": "^0.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12189
198
1
+ Added@daeinc/math@^0.2.0
+ Added@daeinc/math@0.2.0(transitive)