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

@leodeslf/vec.js

v3.0.1

Published

JavaScript vector library

Downloads

182

Readme

Vec.js

version license


            .                 .
    <--------\               /-------->
      <-------\.           ./------->
        <------\\         //------>
          <-----\\.     .//----->
            <----\\\   ///---->
              <---\\\ ///--->
                <--\\Y//-->
                  <-\|/->
                     V

Table of contents

About

JavaScript vector library.

A set of classes that provide functionality related to basic linear-algebra, geometry, and more, for 2, 3, and 4-dimensional vectors.

Installation

npm i @leodeslf/vec.js
pnpm i @leodeslf/vec.js
yarn add @leodeslf/vec.js

CDNs

https://unpkg.com/@leodeslf/[email protected]
https://cdn.jsdelivr.net/npm/@leodeslf/[email protected]

Usage

Most methods are available as both instance and static members. The ones that modify the current vector return this, thus we can chain method calls. Other than e.g.: vector.x, vector.y, and vector.xy (as an array), vectors are iterable, so it's possible to iterate trough their components using for-of or spread operator (e.g.: ...vector).

// E.g.:
import { Vec2 } from '@leodeslf/vec.js';

const position = new Vec2(1, 1.8);
const target = new Vec2(1, 10);
const distance = position.distance(target); // 8.2
const direction = Vec2.subtract(target, position).normalize(); // { x: 0, y: 1 }

Linear Algebra

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: add|✓|✓|✓ angleBetween|✓|✓|✓ cross||✓| distance|✓|✓|✓ distanceChebyshev|✓|✓|✓ distanceManhattan|✓|✓|✓ distanceMinkowski|✓|✓|✓ distanceSq|✓|✓|✓ dot|✓|✓|✓ lerp|✓|✓|✓ negate|✓|✓|✓ normalize|✓|✓|✓ project|✓|✓|✓ rotateX||✓| rotateY||✓| rotateZ|✓|✓| scale|✓|✓|✓ subtract|✓|✓|✓

Copying & Creating

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: clone|✓|✓|✓ copy|✓|✓|✓ fromCylindricalCoords||✓| fromPolarCoords|✓|| fromSphericalCoords||✓| random|✓|✓|✓

Boolean Conditions

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: satisfyEquality|✓|✓|✓ satisfyOpposition|✓|✓|✓ isInfinite|✓|✓|✓ isNaN|✓|✓|✓ isZero|✓|✓|✓

Magnitude Manipulation

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: limitMax|✓|✓|✓ limitMin|✓|✓|✓ clamp|✓|✓|✓ zero|✓|✓|✓

Miscellaneous

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: lookAt|✓|✓|✓ turnLeft|✓|| turnRight|✓||

Getters & Setters

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: angleW|||✓* angleX|✓|✓*|✓* angleY|✓|✓*|✓* angleZ||✓*|✓* magnitude|✓|✓|✓ magnitudeSq|✓*|✓*|✓* a (alias for w)|||✓ r (alias for x)|✓|✓|✓ g (alias for y)|✓|✓|✓ b (alias for z)||✓|✓

*read only.

Shortcuts

Use them to get/set components as/from arrays.

Name|Vec2|Vec3|Vec4 :--|:-:|:-:|:-: xy|✓|| xyz (or alias rgb)||✓| xyzw (or alias rgba)|||✓

Author

Copyright (c) Leonardo de S.L.F, 2018-present.

License

MIT License.