@anselan/maprange
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -37,3 +37,3 @@ "use strict"; | ||
exports.remapArray = remapArray; | ||
const remapCoords = (inputCoords, inputDimensions, targetDimensions, clamp = false, shouldRound = true) => { | ||
const remapCoords = (inputCoords, inputDimensions, targetDimensions, clamp = false, shouldRound = false) => { | ||
if (inputCoords.length !== targetDimensions.length || inputCoords.length !== inputDimensions.length) { | ||
@@ -40,0 +40,0 @@ throw Error('coordinates must have same number of dimensions as input and target dimensions'); |
@@ -148,2 +148,12 @@ "use strict"; | ||
}); | ||
test('cm to pixels', () => { | ||
const [x, y] = [100, 200]; | ||
const pixels = _1.remapCoords([x, y], [400, 400], [1920, 1080]); | ||
expect(pixels).toEqual([480, 540]); | ||
}); | ||
test('pixels, normalised', () => { | ||
const [x, y] = [100, 200]; | ||
const norm = _1.remapCoords([x, y], [1000, 1000], [1, 1], false, false); | ||
expect(norm).toEqual([0.1, 0.2]); | ||
}); | ||
test('normalised to realworld dimensions, 3D', () => { | ||
@@ -150,0 +160,0 @@ const [x, y, z] = [0.25, 0.5, 2.5]; |
{ | ||
"name": "@anselan/maprange", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Map values from one range to another", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -180,2 +180,14 @@ import { remap, remapArray, remapCoords } from '.' | ||
test('cm to pixels', () => { | ||
const [x,y] = [100,200]; | ||
const pixels = remapCoords([x,y], [400,400], [1920,1080]); | ||
expect(pixels).toEqual([480, 540]); | ||
}) | ||
test ('pixels, normalised', () => { | ||
const [x,y] = [100, 200]; | ||
const norm = remapCoords([x,y], [1000,1000], [1,1], false, false); | ||
expect(norm).toEqual([0.1, 0.2]) | ||
}) | ||
test('normalised to realworld dimensions, 3D', () => { | ||
@@ -182,0 +194,0 @@ const [x,y,z] = [0.25, 0.5, 2.5]; |
@@ -35,3 +35,3 @@ const checkValidRanges = (arrays: number[][]): boolean => | ||
const remapCoords = (inputCoords: number[], inputDimensions: number[], targetDimensions: number[], clamp=false, shouldRound = true): number[] => { | ||
const remapCoords = (inputCoords: number[], inputDimensions: number[], targetDimensions: number[], clamp=false, shouldRound = false): number[] => { | ||
if (inputCoords.length !== targetDimensions.length || inputCoords.length !== inputDimensions.length) { | ||
@@ -38,0 +38,0 @@ throw Error('coordinates must have same number of dimensions as input and target dimensions') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
35620
468