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

gl-vec2

v1.3.0

Published

gl-matrix's vec2, split into smaller pieces

Downloads

507,966

Readme

gl-vec2

stable

Part of a fork of @toji's gl-matrix split into smaller pieces: this package contains glMatrix.vec2.

Usage

NPM

vec2 = require('gl-vec2')

Will load all of the module's functionality and expose it on a single object. Note that any of the methods may also be required directly from their files.

For example, the following are equivalent:

var scale = require('gl-vec2').scale
var scale = require('gl-vec2/scale')

API

add(out:vec2, a:vec2, b:vec2)

Adds two vec2's

ceil(out:vec2, a:vec2)

Math.ceil the components of a vec2

clone(a:vec2)

Creates a new vec2 initialized with values from an existing vector

copy(out:vec2, a:vec2)

Copy the values from one vec2 to another

create()

Creates a new, empty vec2

cross(out:vec3, a:vec2, b:vec2)

Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

distance(a:vec2, b:vec2)

Calculates the euclidian distance between two vec2's. Aliased as dist.

divide(out:vec2, a:vec2, b:vec2)

Divides two vec2's. Aliased as div.

dot(a:vec2, b:vec2)

Calculates the dot product of two vec2's

equals(a:vec2, b:vec2)

Returns whether or not the vectors have approximately the same elements in the same position.

exactEquals(a:vec2, b:vec2)

Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)

floor(out:vec2, a:vec2)

Math.floor the components of a vec2

forEach(a:Array, stride:Number, offset:Number, count:Number, fn:Function, [arg]:Object)

Perform some operation over an array of vec2s.

fromValues(x:Number, y:Number)

Creates a new vec2 initialized with the given values

inverse(out:vec2, a:vec2)

Returns the inverse of the components of a vec2

length(a:vec2)

Calculates the length of a vec2. Aliased as len.

lerp(out:vec2, a:vec2, b:vec2, t:Number)

Performs a linear interpolation between two vec2's

limit(out:vec2, a:vec2, max:Number)

Limit the magnitude of this vector to the value used for the max parameter

max(out:vec2, a:vec2, b:vec2)

Returns the maximum of two vec2's

min(out:vec2, a:vec2, b:vec2)

Returns the minimum of two vec2's

multiply(out:vec2, a:vec2, b:vec2)

Multiplies two vec2's. Aliased as mul.

negate(out:vec2, a:vec2)

Negates the components of a vec2

normalize(out:vec2, a:vec2)

Normalize a vec2

random(out:vec2, [scale]:Number)

Generates a random vector with the given scale

round(out:vec2, a:vec2)

Math.round the components of a vec2

rotate(out:vec2, a:vec2, angle:Number)

Rotates a vec2 by an angle (in radians)

scale(out:vec2, a:vec2, b:Number)

Scales a vec2 by a scalar number

scaleAndAdd(out:vec2, a:vec2, b:vec2, scale:Number)

Adds two vec2's after scaling the second operand by a scalar value

set(out:vec2, x:Number, y:Number)

Set the components of a vec2 to the given values

squaredDistance(a:vec2, b:vec2)

Calculates the squared euclidian distance between two vec2's. Aliased as sqrDist.

squaredLength(a:vec2)

Calculates the squared length of a vec2. Aliased as sqrLen.

subtract(out:vec2, a:vec2, b:vec2)

Subtracts vector b from vector a. Aliased as sub.

transformMat2(out:vec2, a:vec2, m:mat2)

Transforms the vec2 with a mat2

transformMat2d(out:vec2, a:vec2, m:mat2d)

Transforms the vec2 with a mat2d

transformMat3(out:vec2, a:vec2, m:mat3)

Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

transformMat4(out:vec2, a:vec2, m:mat4)

Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

License

zlib. See LICENSE.md for details.