Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

109 lines (75 sloc) 1.634 kb

coords

Transform coordinates.

example

gl_to_pixel.js

var coords = require('coords');
var tr = coords([ 800, 600 ], [ [ -1, 1 ], [ -1, 1 ] ]);
var pos = tr(460, 230);
console.dir(pos);

output:

[ 0.15143929912390486, -0.23205342237061766 ]

flip.js

To flip the coordinates, just put the bigger number first:

var coords = require('coords');
var tr = coords([ 800, 600 ], [ [ 1, -1 ], [ -1, 1 ] ]);
var pos = tr(460, 230);
console.dir(pos);

output:

[ -0.15143929912390486, -0.23205342237061766 ]

pixel_to_gl.js

var coords = require('coords');
var tr = coords([ [ -1, 1 ], [ -1, 1 ] ], [ 800, 600 ]);
var pos = tr([ 0.15143929912390486, -0.23205342237061766 ]);
console.dir(pos);

output:

[ 460, 230 ]

methods

var coords = require('coords')

var tr = coords(from, to)

Return a coordinate transform function tr mapping coordinates specified in from to coordinates specified in to.

Each 2-element array x in from and to represents a coordinate transform on a dimension in the range x[0] to x[1], inclusive.

Any element x in from or to that is not an array will be treated as the array [ 0, x - 1 ].

tr(pos)

Transform the coordinate array pos given the from and to specified earlier in coords(from, to).

tr(x, y, ...)

Shorthand for tr([ x, y, ... ]).

install

With npm do:

npm install coords

test

With npm do:

npm test

license

MIT/X11

Jump to Line
Something went wrong with that request. Please try again.