npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lemonade-math

v1.2.0

Published

Math utility functions

Downloads

3

Readme

lemonade-math

Math utility functions

Installation

npm install lemonade-math

Usage

import { lerp } from 'lemonade-math';

console.log(lerp(0, 2, 0.5)); // 1

Constants

PI

TAU

HALF_PI

RAD2DEG

DEG2RAD

Functions

clamp

  • Type: (value: number, min:number, max:number) => number

Constrain a value to lie between two further values

cross

  • Type: (a: number[3], b: number[3]) => number[3]

Compute the cross product of two 3D vectors

degToRad

  • Type: (angle: number) => number

Convert an angle in degrees to radians

distance

  • Type: (a: number[2|3], b: number[2|3]) => number

Compute the Euclidian distance between two vectors

distance2D

  • Type: (a: number[2], b: number[2]) => number

Compute the Euclidian distance between two 2D vectors

distance3D

  • Type: (a: number[3], b: number[3]) => number

Compute the Euclidian distance between two 3D vectors

squaredDistance

  • Type: (a: number[2|3], b: number[2|3]) => number

Compute the square of the Euclidian distance between two vectors

squaredDistance2D

  • Type: (a: number[2], b: number[2]) => number

Compute the square of the Euclidian distance between two 2D vectors

squaredDistance3D

  • Type: (a: number[3], b: number[3]) => number

Compute the square of the Euclidian distance between two 3D vectors

fract

  • Type: (value: number) => number

Compute the fractional part of a value

geocentricToPolar

  • Type: ({ x: number, y: number, z: number }) => { latitude: number, longitude: number }

Convert geocentric coordinates (x, y, z) to polar coordinates (latitude, longitude)

length

  • Type: (a: number[2|3|4], b: number[2|3|4]) => number

Compute the Euclidian length between two vectors

length2D

  • Type: (a: number[2], b: number[2]) => number

Compute the Euclidian length between two 2D vectors

length3D

  • Type: (a: number[3], b: number[3]) => number

Compute the Euclidian length between two 3D vectors

length4D

  • Type: (a: number[4], b: number[4]) => number

Compute the Euclidian length between two 4D vectors

squaredLength

  • Type: (a: number[2|3|4], b: number[2|3|4]) => number

Compute the square of the Euclidian length between two vectors

squaredLength2D

  • Type: (a: number[2], b: number[2]) => number

Compute the square of the Euclidian length between two 2D vectors

squaredLength3D

  • Type: (a: number[3], b: number[3]) => number

Compute the square of the Euclidian length between two 3D vectors

squaredLength4D

  • Type: (a: number[4], b: number[4]) => number

Compute the square of the Euclidian length between two 4D vectors

lerp

  • Type: (a: number, b: number) => number

Linearly interpolate between two values

lerp2D

  • Type: (a: number[2], b: number[2]) => number[2]

Linearly interpolate between two 2D vectors

lerp3D

  • Type: (a: number[3], b: number[3]) => number[3]

Linearly interpolate between two 3D vectors

lerp4D

  • Type: (a: number[4], b: number[4]) => number[4]

Linearly interpolate between two 4D vectors

map

  • Type: (value: number, min: number, max: number, nmin: number, nmax: number) => number

Convert a number from one range to an other

normal

  • Type: (a: number[2], b: number[2], direction?: number) => number[2]

Compute the normal between two 2D vectors

normalize

  • Type: (a: number[2|3|4], b: number[2|3|4]) => number[2|3|4]

Compute the unit vector of a vector

normalize2D

  • Type: (a: number[2], b: number[2]) => number[2]

Compute the unit vector of a 2D vector

normalize3D

  • Type: (a: number[3], b: number[3]) => number[3]

Compute the unit vector of a 3D vector

normalize4D

  • Type: (a: number[4], b: number[4]) => number[4]

Compute the unit vector of a 4D vector

polarToGeocentric

  • Type: ({ latitude: number, longitude: number }) => { x: number, y: number, z: number }

Convert polar coordinates (latitude, longitude) to geocentric coordinates (x,y,z)

radToDeg

  • Type: (angle: number) => number

Convert an angle in radians to degrees

License

MIT License, see LICENSE for details