Permalink
Browse files

Removed exhaustive version of algorithm. The quick one gets the same …

…results.
  • Loading branch information...
1 parent 6b36f72 commit d4d0594328ca6d60c493178a427757152e3b6a10 dylan committed Mar 24, 2012
Showing with 25 additions and 56 deletions.
  1. +1 −24 scripts/guts/gridify.js
  2. +24 −32 test/t/test_gridify.js
View
@@ -1,23 +1,5 @@
define(['guts/comparison', 'guts/griddle'], function(comparison, griddle) {
-
- var exhaustive = function(aspectRatio) {
- return function(totalWidth, totalHeight) {
- return function(numCells) {
- var arrayMin = comparison.arrayMin;
- var by = comparison.by;
-
- var r = _.range(1, numCells + 1);
- var g = griddle(totalWidth, totalHeight, numCells);
- var layouts = _.map(r, g);
- var deltaAr = function(x) {
- return Math.abs(x.meanAr - aspectRatio);
- };
- return arrayMin(by(deltaAr))(layouts);
- };
- };
- };
-
- var quick = function(aspectRatio) {
+ return function(aspectRatio) {
return function(totalWidth, totalHeight) {
return function(numCells) {
var rows = Math.round(Math.sqrt( (aspectRatio * totalHeight * numCells) / totalWidth));
@@ -26,9 +8,4 @@ define(['guts/comparison', 'guts/griddle'], function(comparison, griddle) {
};
};
};
-
- return {
- exhaustive: exhaustive,
- quick: quick
- };
});
View
@@ -2,43 +2,35 @@ define(['guts/gridify', 'underscore', 'guts/util'], function(gridify, _, util) {
return function(assert) {
var ar = 7/3;
- // _.each(_.range(1, 10), function(x) {
- // var g = gridify(ar)(1152, 1024)(x);
- // assert.equal(x, g.cells);
+ _.each(_.range(1, 10), function(x) {
+ var g = gridify(ar)(1152, 1024)(x);
+ assert.equal(x, g.cells);
- // assert.equal(g.cells, util.arraySum(_.map(g.rowLayouts, function(x) {
- // return x.cells;
- // })));
+ assert.equal(g.cells, util.arraySum(_.map(g.rowLayouts, function(x) {
+ return x.cells;
+ })));
- // var numRowLayouts = g.rowLayouts.length;
- // assert.equal(true, numRowLayouts === 0 || numRowLayouts === 1);
+ var numRowLayouts = g.rowLayouts.length;
+ assert.equal(true, numRowLayouts === 1 || numRowLayouts === 2);
- // _.each(g.rowLayouts, function(x) {
- // assert.equal(true, x.cells > 0);
- // assert.equal(true, x.rows > 0);
- // assert.equal(true, x.cols > 0);
- // assert.equal(x.cells, x.rows * x.cols);
- // assert.equal('number', typeof x.ar);
- // assert.equal(false, isNaN(x.ar));
- // assert.equal(false, x.ar === 0);
- // });
- // });
-
- // assert.deepEqual(gridify(ar)(100, 200)(1), { rows: 1,
- // cells: 1,
- // rowLayouts: [ { rows: 1, cols: 1, cells: 1, width: 100, height: 200, ar: 0.5 } ],
- // meanAr: 0.5
- // });
+ _.each(g.rowLayouts, function(x) {
+ assert.equal(true, x.cells > 0);
+ assert.equal(true, x.rows > 0);
+ assert.equal(true, x.cols > 0);
+ assert.equal(true, x.width > 0);
+ assert.equal(true, x.height > 0);
+ assert.equal(x.cells, x.rows * x.cols);
+ assert.equal('number', typeof x.ar);
+ assert.equal(false, isNaN(x.ar));
+ assert.equal(false, x.ar === 0);
+ });
+ });
- _.each(_.range(1, 500), function(i) {
- var e = gridify.exhaustive(ar)(1152, 1024)(i);
- var q = gridify.quick(ar)(1152, 1024)(i);
- console.log([i, ar, e.meanAr, q.meanAr].join(','));
+ assert.deepEqual(gridify(ar)(100, 200)(1), { rows: 1,
+ cells: 1,
+ rowLayouts: [ { rows: 1, cols: 1, cells: 1, width: 100, height: 200, ar: 0.5 } ],
+ meanAr: 0.5
});
- // var q = _.map(_.range(1, 50), gridify(ar)(1152, 1024));
- // _.each(q, function(x) {
- // console.log([x.cells, x.rows, x.meanAr].join(','));
- // });
};
});

0 comments on commit d4d0594

Please sign in to comment.