Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including geom2d with all npm packages installed. Try it out:

var geom2d = require("geom2d")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

geom2d v0.0.4

A library for basic 2D affine transformations; will likely add other little items

Explanation

A very alpha version of a JS Library for doing affine transformations and (coming soon) other simple transformations I need for a bigger project. My first node module. Written in IcedCoffeeScript.

Browser Use

<script src="geom2d.js"></script>
<script>
 var affine  = require('affine');
 var polygon = require('polygon');

 var rot_left  = new affine.rotation(  Math.PI / 4);
 var rot_right = new affine.rotation( -Math.PI / 4);
 var go_big    = new affine.scaling (  2,   4);
 var go_small  = new affine.scaling (  0.5, 0.25);
 
 var do_nothing = rot_left.copy();
 do_nothing.rightComposeWith(rot_right);
 do_nothing.rightComposeWith(go_big);
 do_nothing.rightComposeWith(go_small);
 
 var square = polygon.factory.unitSquare();
 
 document.write("<h3>Square before</h3>");
 document.write(JSON.stringify(square));
 
 document.write("<h3>Square after</h3>");
 square.transform(do_nothing);
 document.write(JSON.stringify(square));
</script>

Node Installation

npm install -g geom2d

Usage (CoffeeScript example)

{affine, polygon} = require 'geom2d'

rot_left  = new affine.rotation  Math.PI / 4
rot_right = new affine.rotation -Math.PI / 4
go_big    = new affine.scaling   2,   4
go_small  = new affine.scaling   0.5, 0.25

# 4 compositions that should net nothing
# --------------------------------------
do_nothing = rot_left.copy()
do_nothing.rightComposeWith rot_right
do_nothing.rightComposeWith go_big
do_nothing.rightComposeWith go_small

square = polygon.factory.unitSquare()
square.transform do_nothing

console.log square

Contributing

All .js and .json files are auto-generated. Please edit the appropropriate .iced files and run cake build before committing.

geom2d is written in an improved version of CoffeeScript called "IcedCoffeeScript".

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free