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

justmath

v1.0.1

Published

JustMath.js: Two dimensional vector math including a rich toolset for vector operations.

Downloads

5

Readme

JustMath.js - 2D Vector Math Build Status

An implementation of two dimensional vector math including a rich toolset for vector operations. It's also the math library behind eSoccer, a cross-platform multiplayer HTML5 game developed at University of Applied Sciences Bonn.

JustMath

  • Augments core Math
  • Allows replacement of all methods (e.g. custom implementations of JustMath.sqrt(value))
  • Adds some convenience methods (JustMath.sq(value), JustMath.cot(angle))

JustMath.Vec2

  • Vector instantiation (new Vec2(vOrX[, y])) and cloning (Vec2#clone())

  • Direct modification through Vec2#x and Vec2#y, also provides getters (Vec2#getX(), Vec2#getY()) and a setter (Vec2#set(vOrX[, y]))

  • Vector addition (Vec2#add(vOrX[, y])), subtraction (Vec2#sub(vOrX[, y])) and multiplication (Vec2#dot(vOrX[, y])))

  • Vector orthogonality (Vec2#ort())

  • Vector normalization (Vec2#norm()), scaling (Vec2#scale(factor)), inversion (Vec2#inv()) and magnitude (Vec2#mag(), Vec2#magSq()) calculation

  • Vector-Vector distances (Vec2#dist(b), Vec2#distSq(b))

  • Vector rotation (Vec2#rot(angle)) and direction calculation (Vec2#dir())

  • Vector projection (Vec2#project(b)) and rejection (Vec2#reject(b))

  • Vector reflection (Vec2#reflect(n)), also with component-wise (projected and rejected component) scaling (Vec2#reflectAndScale(n, projectFactor, rejectFactor))

  • Vector interpolation (Vec2#lerp(p, percent))

  • Vector containment in rectangle (Vec2#inRect(p1, p2))

  • [Vector,Vector] determinant calculation (Vec2.det(v1, v2))

  • Provides Vector#toString and Vector#equals()

  • Provides vector operation chaining, e.g.

    var a = new Vec2(1,2);
    var b = new Vec2(2,1);
    var n = new Vec2(0,1);
    a.clone().sub(b).norm().project(n)...
  • Provides Vec2#toString() for pain-free debugging

  • Is of course able to evaluate Vec2#equals(b)

  • Exports and imports JSON payloads (Vec2#getXY(), new Vec2(jsonPayload))

  • Small allocation footprint when using Vec2#clone() wisely

  • Accepts another Vec2 or plain X and Y coordinates as parameters where possible (e.g. Vec2#add(vOrX[, y]))

Features

  • CommonJS compatible
  • RequireJS/AMD compatible
  • Shim compatible
  • node.js compatible, also available via npm (npm install justmath)
  • Closure Compiler ADVANCED_OPTIMIZATIONS compatible (fully annotated)
  • Fully documented (jsdoc3)
  • Zero dependencies and prerequisites
  • Small footprint

Usage

Node.js / CommonJS

  • Install: npm install justmath
var JustMath = require("justmath"),
    Vec2 = JustMath.Vec2;
var a = new Vec2(1,2);
console.log("Not more than "+a.x+", "+a.y+", 3.");

Browser (shim)

<script src="//raw.github.com/dcodeIO/JustMath.js/master/JustMath.min.js"></script>
var JustMath = dcodeIO.JustMath,
    Vec2 = JustMath.Vec2;
var a = new Vec2(1,2);
alert("Not more than "+a.x+", "+a.y+", 3.");

RequireJS / AMD

var JustMath = require("/path/to/JustMath.js"),
    Vec2 = JustMath.Vec2;
var a = new Vec2(1,2);
alert("Not more than "+a.x+", "+a.y+", 3.");

Downloads

Documentation

Examples & Tests

License

Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html