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

js-2dmath

v0.1.1

Published

Fast 2d geometry math: Vector2, Rectangle, Circle, Matrix2x3 (2D transformation), Circle, BoundingBox, Line2, Segment2, Intersections, Distances, Transitions (animation/tween), Random numbers, Noise

Downloads

103

Readme

js-2dmath Build Status

Fast 2d geometry math: Vector2, Rectangle, Circle, Matrix2x3 (2D transformation), Circle, BoundingBox, Line2, Segment2, Intersections, Distances, Transitions (animation/tween), Noise, Random numbers.

So the objective is "Be fast"

Help needed / TODO LIST

  • API completeness
  • Testing
  • Use falafel/esprima to create an asm.js build
  • More Numerical integrators
  • AI: Path-finding, Steer, Backtracking
  • IK: FABRIK
  • Minkowski distance, euclidean, Manhattan
  • Beizer math
  • Serialization / De-serialization
  • did I miss anything useful?

Performance

Performance is based on good practices.

  • Avoid new
  • Use arrays instead of objects, this is huge performance boost!
  • Avoid creating unnecessary variables (reuse intermediate variables) only create & clone methods should create new variables.
  • Cache every function call to a single variable. example: Vec2.add => vec2_add, even Math.*
  • If access a multi-dimensional array in a loop, cache the array access. for(i...) carr=arr[i]; carr[X]
  • Do not use forEach, map, every etc. or other looping method that require apply/call usage, both are costly.

See some performance test that prove it.

funlinify It's a library that do function inline expansion for javascript. It's in early stage but it works perfectly for our usage here.

Obviously I ignore myself in some parts of this library. Feel free to issue me :)

Grunt

npm install -g grunt
npm install -g grunt-cli

grunt dist

Create distribution packages using browserify and documentation.

  • debug: debug/js-2dmath-browser-debug.js

    • argumentify Assert on invalid arguments to properly debug your app.
  • dist: dist/js-2dmath-browser.js

  • dist.min: js-2dmath-browser.min.js

grunt watch

Watch every change and rebuild the distribution code.

What can you do with js-2dmath?

See some examples.

API

The documentation is autogenerated with falafel see dist.js for more fun! :)

FAQ

How do i know a variable type?

You can't, there is no instanceof or anything like that, everything are numbers/arrays.

I choose to keep track of all types using meaningful naming or enclose the variable in an object like

var movable = {
    body: Polygon.create(/*...*/), // could be a circle, change the type...
    type: "polygon"
}