[ecma-proposal-math-extensions] Add typings (#27187)

This commit is contained in:
Konstantin Simon Maria Möllers 2018-07-12 18:39:05 +02:00 committed by Ryan Cavanaugh
parent 2d845a15d2
commit 47af8e9886
4 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import "ecma-proposal-math-extensions";
Math.scale(42, 21, 64, 0, 100);
Math.fscale(0.42, 0.21, 0.64, 0.0, 1.0);
Math.clamp(42, 0, 100);
Math.radians(180) === 180 * Math.DEG_PER_RAD;
Math.degrees(Math.PI) === Math.PI * Math.RAD_PER_DEG;

View File

@ -0,0 +1,52 @@
// Type definitions for ecma-proposal-math-extensions 0.0
// Project: https://github.com/rwaldron/proposal-math-extensions#readme
// Definitions by: Konstantin Simon Maria Möllers <https://github.com/ksm2>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.0
interface Math {
/** This is the number of how many degrees are one radian. */
readonly DEG_PER_RAD: number;
/** This is the number of how many radians are one degree. */
readonly RAD_PER_DEG: number;
/**
* Scales a value between `inLow` and `inHigh` to the range of `outLow` to `outHigh`.
* @param x The numeric value in the input range to scale.
* @param inLow The lower bound of the input range.
* @param inHigh The upper bound of the input range.
* @param outLow The lower bound of the output range.
* @param outHigh The upper bound of the output range.
* @return The input value scaled to the output range.
*/
scale(x: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;
/**
* Scales a floating point value between `inLow` and `inHigh` to the range of `outLow` to `outHigh`.
* @param x The numeric value in the input range to scale.
* @param inLow The lower bound of the input range.
* @param inHigh The upper bound of the input range.
* @param outLow The lower bound of the output range.
* @param outHigh The upper bound of the output range.
* @return The input value scaled to the output range.
*/
fscale(x: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;
/**
* Clamps an incoming value `x` to a range between `lower` and `upper`.
* @param x The value to clamp.
* @param lower The lower bound of the range to clamp `x` to.
* @param upper The upper bound of the range to clamp `x` to.
* @return The input value clamped to the given range.
*/
clamp(x: number, lower: number, upper: number): number;
/**
* Converts an angle given in degrees to an angle given in radians.
* @param degrees The input angle in degrees.
* @return The output angle in radians.
*/
radians(degrees: number): number;
/**
* Converts an angle given in radians to an angle given in degrees.
* @param radians The input angle in radians.
* @return The output angle in degrees.
*/
degrees(radians: number): number;
}

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"target": "es2017",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ecma-proposal-math-extensions-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }