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

vecter

v0.1.0

Published

2d vector for math / physics

Downloads

2

Readme

vector-2d CircleCI Coverage Status

2d vector { x, y } for math / physics

Install

npm install vecter

Usage

import Vector from 'vecter';

const vector = new Vector(1, 2);
vector.mult(2); // { x: 2, y 4}

or

import { create, mult } from 'vecter';

const vector = create(1, 2);
const doubleVector = mult(vector, 2); // { x: 2, y 4}

API

Vector

constructor :: (Number, Number) -> Vector

Properties

a vector is shape of { x, y }

  • x
  • y

Static methods

All static methods are immutable.

operators

  • add :: (Vector, Vector) -> Vector

    add two vectors

  • sub :: (Vector, Vector) -> Vector

    subtract one vector from another.

  • mult :: (Vector, Number) -> Vector

    multiply by scalar

  • div :: (Vector, Number) -> Vector

    divide by scalar

  • dot :: (Vector, Vector) -> Number

    dot product

  • cross :: (Vector, Vector) -> Number

    cross product

evaluate

  • mag :: Vector -> Number

    the magnitude of a vector

  • magSq :: Vector -> Number

    the square of the magnitude

  • dir :: Vector -> Number

    the direction of a vector

  • dist :: (Vector, Vector) -> Number

    the distance between two vectors

  • distSq :: (Vector, Vector) -> Number

    the square of the distance between two vectors

  • angle :: (Vector, Vector) -> Number

    the angle between two vectors, range [0, PI]

create

  • create :: (Number, Number) -> Vector

    create a vector by rectangular form

  • fromAngle :: (Number, Number) -> Vector

    create a vector by angle

  • normalize :: Vector -> Vector

    normalize the vector to a length of 1

  • clone :: Vector -> Vector

    create a new vector copy

Instance methods

All instance methods are very similar to the statics. there're two differences.

  • first argument

    instance methods don't need first argument, it's itself.

  • mutable

    most of methods are mutable.

operators

  • add :: Vector -> Vector

    adds a vector

  • sub :: Vector -> Vector

    subtract from another vector

  • mult :: Number -> Vector

    multiply a vector by a scalar

  • div :: Number -> Vector

    divide a vector by a scalar

  • dot :: Vector -> Number

    dot product

  • cross :: Vector -> Number

    cross product

evaluate

  • mag :: () -> Number

    the magnitude of a vector

  • magSq :: () -> Number

    the square of the magnitude

  • dir :: () -> Number

    the direction of a vector

  • dist :: Vector -> Number

    the distance between two vectors

  • distSq :: Vector -> Number

    the square of the distance between two vectors

  • angle :: Vector -> Number

    the angle between two vectors, range [0, PI]

create

  • clone :: () -> Vector

    create a vector copy, this's an immutable method

  • normalize :: () -> Vector

    create a unit vector

manipulate

  • set :: (Number, Number) -> Vector

    set x, y of this vector

  • setX :: Number -> Vector

    set x of this vector

  • setY :: Number -> Vector

    set y of this vector

  • setMag :: Number -> Vector

    set the magnitude of this vector

  • limit :: Number -> Vector

    limit the magnitude of this vector

License

MIT