@daeinc/math
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,3 @@ | ||
export declare const PI: number; | ||
export declare const TWO_PI: number; | ||
/** | ||
@@ -2,0 +4,0 @@ * clamp values between min and max (=constrain) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.snapToArray = exports.snapBy = exports.roundF = exports.reflect = exports.polarToCartesian = exports.modIncl = exports.modF = exports.mod = exports.lerp = exports.mix = exports.map = exports.floorF = exports.distSq = exports.dist = exports.constrain = exports.clamp = void 0; | ||
exports.snapToArray = exports.snapBy = exports.roundF = exports.reflect = exports.polarToCartesian = exports.modIncl = exports.modF = exports.mod = exports.lerp = exports.mix = exports.map = exports.floorF = exports.distSq = exports.dist = exports.constrain = exports.clamp = exports.TWO_PI = exports.PI = void 0; | ||
// frequently used constants | ||
exports.PI = Math.PI; | ||
exports.TWO_PI = Math.PI * 2; | ||
/** | ||
@@ -5,0 +8,0 @@ * clamp values between min and max (=constrain) |
{ | ||
"name": "@daeinc/math", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Math utilities", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
128
README.md
# math utilities | ||
For personal consumption. Breaking changes expected. | ||
## Installation | ||
```sh | ||
npm i @daeinc/math | ||
``` | ||
then, | ||
```js | ||
import { modF, ... } from "@daeinc/math" | ||
``` | ||
## Functions | ||
### clamp | ||
```ts | ||
const clamp: (val: number, min: number, max: number) => number; | ||
``` | ||
### constrain | ||
```ts | ||
const constrain: (val: number, min: number, max: number) => number; | ||
``` | ||
### dist | ||
```ts | ||
const dist: (x1: number, y1: number, x2: number, y2: number) => number; | ||
``` | ||
### distSq | ||
```ts | ||
const distSq: (x1: number, y1: number, x2: number, y2: number) => number; | ||
``` | ||
There's another version in `@daeinc/geom` that takes `Pt: number[]` type as arguments. | ||
### floorF | ||
```ts | ||
const floorF: (n: number, digit: number) => number; | ||
``` | ||
### map | ||
```ts | ||
const map: ( | ||
val: number, | ||
s: number, | ||
e: number, | ||
ns: number, | ||
ne: number | ||
) => number; | ||
``` | ||
### mix | ||
```ts | ||
const mix: (a: number, b: number, t: number) => number; | ||
``` | ||
### lerp | ||
```ts | ||
const lerp: (a: number, b: number, t: number) => number; | ||
``` | ||
### mod | ||
```ts | ||
const mod: (n: number, max: number) => number; | ||
``` | ||
### modF | ||
```ts | ||
const modF: (n: number, max: number, precision?: number) => number; | ||
``` | ||
### modIncl | ||
```ts | ||
const modIncl: (n: number, max: number) => number; | ||
``` | ||
### polarToCartesian | ||
```ts | ||
const polarToCartesian: (radius: number, angle: number) => number[]; | ||
``` | ||
Converts polar coodrinate to cartesian coordinate. To use a different center point than the default `[0, 0]`, do something like this: | ||
```ts | ||
result.map((v, i) => v + center[i]); | ||
``` | ||
### reflect | ||
```ts | ||
const reflect: (num: number, axis: number) => number; | ||
``` | ||
### roundF | ||
```ts | ||
const roundF: (n: number, digit: number) => number; | ||
``` | ||
### snapBy | ||
```ts | ||
const snapBy: (n: number, inc: number) => number; | ||
``` | ||
### snapToArray | ||
```ts | ||
const snapToArray: (n: number, snapArr: number[]) => number; | ||
``` | ||
## To do | ||
- add more tests | ||
## License | ||
MIT |
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
18054
322
134