Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Jun 4, 2014
1 parent 70ebc2d commit 612a50f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var recquire_t = require('recquire');

var recquire = recquire_t('cg', 'index.js', false, true);
var recquire = recquire_t('cg', 'index.js', 'intro.js', 'outro.js', false, true);

recquire(__dirname + '/src/', module.exports, -1);
26 changes: 25 additions & 1 deletion js/src/2d/sin_sign.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@

/**
* Computes the cross product of _ab_ and _ac_,
* can be interpreted as the sinus sign in a "right-handed" coordinate system
* (i.e. clockwise angle values).
*
* <p>
* Originally implemented as
*
* a[1] * (c[0] - b[0]) + b[1] * (a[0] - c[0]) + c[1] * (b[0] - a[0])
*
* with
* - 2 add
* - 3 sub
* - 3 mul
*
* Reduced to
*
* (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])
*
* with
* - 5 sub
* - 2 mul
*
*/

var sin_sign = function(a, b, c){
return a[1] * (c[0] - b[0]) + b[1] * (a[0] - c[0]) + c[1] * (b[0] - a[0]);
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
};


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "cg",
"version": "0.0.1",
"version": "0.1.0",
"description": "cg (computational geometry) algorithms templates for JavaScript",
"main": "js/index.js",
"dependencies": {
"recquire": "^0.0.0"
"recquire": "~0.1.0"
},
"devDependencies": {
"qunit": "git://github.com/gotwarlost/node-qunit.git#istanbul-coverage",
Expand Down
17 changes: 8 additions & 9 deletions test/js/src/2d/sin_sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ test('sin_sign', function (assert) {
var p = [
[0, 0],
[0, 1],
[0, 2],
[1, 0],
[1, 1],
[1, 2],
Expand All @@ -15,14 +14,14 @@ test('sin_sign', function (assert) {
[-1, 0]
];

ok(cg.sin_sign(p[0], p[1], p[2]) === 0, '0');
ok(cg.sin_sign(p[0], p[1], p[3]) < 0, '45');
ok(cg.sin_sign(p[0], p[1], p[4]) < 0, '90');
ok(cg.sin_sign(p[0], p[1], p[5]) < 0, '135');
ok(cg.sin_sign(p[0], p[1], p[6]) === 0, '180');
ok(cg.sin_sign(p[0], p[1], p[7]) > 0, '225');
ok(cg.sin_sign(p[0], p[1], p[8]) > 0, '270');
ok(cg.sin_sign(p[0], p[1], p[9]) > 0, '315');
ok(cg.sin_sign(p[0], p[1], p[0]) === 0, '0');
ok(cg.sin_sign(p[0], p[1], p[2]) < 0, '315');
ok(cg.sin_sign(p[0], p[1], p[3]) < 0, '270');
ok(cg.sin_sign(p[0], p[1], p[4]) < 0, '225');
ok(cg.sin_sign(p[0], p[1], p[5]) === 0, '180');
ok(cg.sin_sign(p[0], p[1], p[6]) > 0, '135');
ok(cg.sin_sign(p[0], p[1], p[7]) > 0, '90');
ok(cg.sin_sign(p[0], p[1], p[8]) > 0, '45');



Expand Down

0 comments on commit 612a50f

Please sign in to comment.