Skip to content

Commit

Permalink
move more test functionality to common.js
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Nov 3, 2014
1 parent a81ce4c commit 314971f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 98 deletions.
98 changes: 49 additions & 49 deletions test/browser/tests-browserified.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ var assert = chai.assert;
var common = require('./common.js');
var libtess = common.libtess;
var createTessellator = common.createInstrumentedTessellator;
var createPlaneRotation = common.createPlaneRotation;
var tessellate = common.tessellate;

var basetess = require('./expectations/libtess.baseline.js');

Expand All @@ -605,7 +605,7 @@ var thirdPartyGeometries = Object.keys(thirdPartyFiles).map(function(filename) {
geometries.push.apply(geometries, thirdPartyGeometries);

var OUTPUT_TYPES = common.OUTPUT_TYPES;
var PROVIDE_NORMALS = common.PROVIDE_NORMALS;
var PROVIDE_NORMAL = common.PROVIDE_NORMAL;
var NORMALS = common.NORMALS;
var WINDING_RULES = common.WINDING_RULES;

Expand All @@ -626,7 +626,7 @@ function testGeometry(geometry) {
OUTPUT_TYPES.forEach(function(outputType) {
suite(outputType.name, function() {

PROVIDE_NORMALS.forEach(function(provideNormal) {
PROVIDE_NORMAL.forEach(function(provideNormal) {
suite('using ' + provideNormal.name, function() {

NORMALS.forEach(function(normal) {
Expand Down Expand Up @@ -662,50 +662,6 @@ function testGeometry(geometry) {
});
}

/**
* Tessellate the polygon made up of contours with the tessellator tess, using
* the specified options.
* @param {!libtess.GluTesselator} tess
* @param {!Array.<!Array.<number>>} contours
* @param {{name: string, value: boolean}} outputType
* @param {{name: string, value: boolean}} provideNormal
* @param {{name: string, value: !Array.<number>}} normal
* @param {{name: string, value: boolean}} windingRule
* @return {!Array.<!Array.<number>>}
*/
function tessellate(tess, contours, outputType, provideNormal, normal,
windingRule) {

// winding rule
tess.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE,
windingRule.value);

// transform function to align plane with desired normal
var rotate = createPlaneRotation(normal.value);

// provide normal or compute
if (provideNormal.value) {
tess.gluTessNormal.apply(tess, normal.value);
}

var resultVerts = [];
tess.gluTessBeginPolygon(resultVerts);

for (var i = 0; i < contours.length; i++) {
tess.gluTessBeginContour();
var contour = contours[i];
for (var j = 0; j < contour.length; j += 3) {
var coords = rotate(contour[j], contour[j + 1], contour[j + 2]);
tess.gluTessVertex(coords, coords);
}
tess.gluTessEndContour();
}

tess.gluTessEndPolygon();

return resultVerts;
}

},{"./../third_party/test/geometry/poly2tri-dude.js":14,"./../third_party/test/geometry/roboto-registered.js":15,"./common.js":5,"./expectations/libtess.baseline.js":6,"./geometry/degenerate-hourglass.js":7,"./geometry/hourglass.js":8,"./geometry/letter-e.js":9,"./geometry/shared-borders.js":10,"./geometry/shared-edge-triangles.js":11,"./geometry/two-opposite-triangles.js":12,"./geometry/two-triangles.js":13,"./rfolder.js":4,"chai":undefined}],4:[function(require,module,exports){

},{}],5:[function(require,module,exports){
Expand Down Expand Up @@ -785,7 +741,7 @@ exports.OUTPUT_TYPES = OUTPUT_TYPES_;
* @private {!Array.<{name: string, value: boolean}>}
* @const
*/
var PROVIDE_NORMALS_ = [
var PROVIDE_NORMAL_ = [
{
name: 'explicitNormal',
value: true
Expand All @@ -795,7 +751,7 @@ var PROVIDE_NORMALS_ = [
value: false
}
];
exports.PROVIDE_NORMALS = PROVIDE_NORMALS_;
exports.PROVIDE_NORMAL = PROVIDE_NORMAL_;

/**
* Set of normals for planes in which to test tessellation.
Expand Down Expand Up @@ -910,6 +866,50 @@ exports.createInstrumentedTessellator = function(libtess, opt_outputType) {
return tess;
};

/**
* Tessellate the polygon made up of contours with the tessellator tess, using
* the specified options.
* @param {!libtess.GluTesselator} tess
* @param {!Array.<!Array.<number>>} contours
* @param {{name: string, value: boolean}} outputType
* @param {{name: string, value: boolean}} provideNormal
* @param {{name: string, value: !Array.<number>}} normal
* @param {{name: string, value: boolean}} windingRule
* @return {!Array.<!Array.<number>>}
*/
exports.tessellate = function(tess, contours, outputType, provideNormal, normal,
windingRule) {

// winding rule
tess.gluTessProperty(exports.libtess.gluEnum.GLU_TESS_WINDING_RULE,
windingRule.value);

// transform function to align plane with desired normal
var rotate = exports.createPlaneRotation(normal.value);

// provide normal or compute
if (provideNormal.value) {
tess.gluTessNormal.apply(tess, normal.value);
}

var resultVerts = [];
tess.gluTessBeginPolygon(resultVerts);

for (var i = 0; i < contours.length; i++) {
tess.gluTessBeginContour();
var contour = contours[i];
for (var j = 0; j < contour.length; j += 3) {
var coords = rotate(contour[j], contour[j + 1], contour[j + 2]);
tess.gluTessVertex(coords, coords);
}
tess.gluTessEndContour();
}

tess.gluTessEndPolygon();

return resultVerts;
};

/**
* Create a rotation function that rotates coordinates from a plane with a z=1
* normal to a plane with the specified normal. Normal must be unit length.
Expand Down
48 changes: 46 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ exports.OUTPUT_TYPES = OUTPUT_TYPES_;
* @private {!Array.<{name: string, value: boolean}>}
* @const
*/
var PROVIDE_NORMALS_ = [
var PROVIDE_NORMAL_ = [
{
name: 'explicitNormal',
value: true
Expand All @@ -84,7 +84,7 @@ var PROVIDE_NORMALS_ = [
value: false
}
];
exports.PROVIDE_NORMALS = PROVIDE_NORMALS_;
exports.PROVIDE_NORMAL = PROVIDE_NORMAL_;

/**
* Set of normals for planes in which to test tessellation.
Expand Down Expand Up @@ -199,6 +199,50 @@ exports.createInstrumentedTessellator = function(libtess, opt_outputType) {
return tess;
};

/**
* Tessellate the polygon made up of contours with the tessellator tess, using
* the specified options.
* @param {!libtess.GluTesselator} tess
* @param {!Array.<!Array.<number>>} contours
* @param {{name: string, value: boolean}} outputType
* @param {{name: string, value: boolean}} provideNormal
* @param {{name: string, value: !Array.<number>}} normal
* @param {{name: string, value: boolean}} windingRule
* @return {!Array.<!Array.<number>>}
*/
exports.tessellate = function(tess, contours, outputType, provideNormal, normal,
windingRule) {

// winding rule
tess.gluTessProperty(exports.libtess.gluEnum.GLU_TESS_WINDING_RULE,
windingRule.value);

// transform function to align plane with desired normal
var rotate = exports.createPlaneRotation(normal.value);

// provide normal or compute
if (provideNormal.value) {
tess.gluTessNormal.apply(tess, normal.value);
}

var resultVerts = [];
tess.gluTessBeginPolygon(resultVerts);

for (var i = 0; i < contours.length; i++) {
tess.gluTessBeginContour();
var contour = contours[i];
for (var j = 0; j < contour.length; j += 3) {
var coords = rotate(contour[j], contour[j + 1], contour[j + 2]);
tess.gluTessVertex(coords, coords);
}
tess.gluTessEndContour();
}

tess.gluTessEndPolygon();

return resultVerts;
};

/**
* Create a rotation function that rotates coordinates from a plane with a z=1
* normal to a plane with the specified normal. Normal must be unit length.
Expand Down
50 changes: 3 additions & 47 deletions test/geometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var assert = chai.assert;
var common = require('./common.js');
var libtess = common.libtess;
var createTessellator = common.createInstrumentedTessellator;
var createPlaneRotation = common.createPlaneRotation;
var tessellate = common.tessellate;

var basetess = require('./expectations/libtess.baseline.js');

Expand All @@ -36,7 +36,7 @@ var thirdPartyGeometries = Object.keys(thirdPartyFiles).map(function(filename) {
geometries.push.apply(geometries, thirdPartyGeometries);

var OUTPUT_TYPES = common.OUTPUT_TYPES;
var PROVIDE_NORMALS = common.PROVIDE_NORMALS;
var PROVIDE_NORMAL = common.PROVIDE_NORMAL;
var NORMALS = common.NORMALS;
var WINDING_RULES = common.WINDING_RULES;

Expand All @@ -57,7 +57,7 @@ function testGeometry(geometry) {
OUTPUT_TYPES.forEach(function(outputType) {
suite(outputType.name, function() {

PROVIDE_NORMALS.forEach(function(provideNormal) {
PROVIDE_NORMAL.forEach(function(provideNormal) {
suite('using ' + provideNormal.name, function() {

NORMALS.forEach(function(normal) {
Expand Down Expand Up @@ -92,47 +92,3 @@ function testGeometry(geometry) {
});
});
}

/**
* Tessellate the polygon made up of contours with the tessellator tess, using
* the specified options.
* @param {!libtess.GluTesselator} tess
* @param {!Array.<!Array.<number>>} contours
* @param {{name: string, value: boolean}} outputType
* @param {{name: string, value: boolean}} provideNormal
* @param {{name: string, value: !Array.<number>}} normal
* @param {{name: string, value: boolean}} windingRule
* @return {!Array.<!Array.<number>>}
*/
function tessellate(tess, contours, outputType, provideNormal, normal,
windingRule) {

// winding rule
tess.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE,
windingRule.value);

// transform function to align plane with desired normal
var rotate = createPlaneRotation(normal.value);

// provide normal or compute
if (provideNormal.value) {
tess.gluTessNormal.apply(tess, normal.value);
}

var resultVerts = [];
tess.gluTessBeginPolygon(resultVerts);

for (var i = 0; i < contours.length; i++) {
tess.gluTessBeginContour();
var contour = contours[i];
for (var j = 0; j < contour.length; j += 3) {
var coords = rotate(contour[j], contour[j + 1], contour[j + 2]);
tess.gluTessVertex(coords, coords);
}
tess.gluTessEndContour();
}

tess.gluTessEndPolygon();

return resultVerts;
}

0 comments on commit 314971f

Please sign in to comment.