metapolator/metapolator — pull request #230 by graphicore (2014-10-14 01:57:16+00:00)
Title: Add a command that initializes requirejs and node and then drops into a ...

...node JavaScript shell

This proved already to be very useful for me. I'm documenting an example session
with some good tricks an gotchas below.

$ metapolator dev-js-shell
// load some modules
metapolator> var hobby = require('metapolator/math/hobby');
undefined
metapolator> Vector = require('metapolator/math/Vector');
undefined

// work around a bug in nodejs: joyent/node#8539
metapolator> Vector.prototype._cps_whitelist.inspect = 'inspect';

// do some math
metapolator> var p0 = new Vector(14.671, -0.863), p1 = new Vector(234.736, 634.305);
undefined
metapolator> var p2 = new Vector(60.546, 131.544), p3 = new Vector(263.192, 716.437);
undefined
metapolator> hobby.control2tension(p0, p1, p2, p3)
[ 0.3764358308915479, 0.4087927848941421 ]
// Note that we use +'' to triger the toString method of the returned Vectors
metapolator> hobby.tension2control(p0, p1['-'](p0).angle(), 0.3764358308915479, 0.4087927848941421, p3['-'](p2).angle(), p3) + ''
','
// The same as the input was, despite of precision errors
metapolator>[p1,p2]+''
','

// supose we have changed the math/hobby library and want to reload it
metapolator> require.undef('metapolator/math/hobby');
undefined
var hobby = require('metapolator/math/hobby')
undefined