From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/helper-classes/3D/math-utils.js | 252 ++++++++++++++++++------------------- 1 file changed, 126 insertions(+), 126 deletions(-) (limited to 'js/helper-classes/3D/math-utils.js') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 8a9be4b5..3c981d0d 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -33,8 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. // Math Utility functions /////////////////////////////////////////////////////////////////////// var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, - ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, - Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; + ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, + Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { /////////////////////////////////////////////////////////////////////// @@ -61,7 +61,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // Vector Methods /////////////////////////////////////////////////////////////////////// - vecIntersectPlaneForParam: { + vecIntersectPlaneForParam: { value: function( pt0, vec, plane ) { // declare the variable to return - undefined when there is no solution @@ -82,7 +82,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - vecMag3: { + vecMag3: { value: function( vec ) { if (vec.length < 3) return; @@ -92,7 +92,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - vecMag: { + vecMag: { value: function( dimen, vec ) { var sum = 0.0; @@ -102,7 +102,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - vecSubtract: { + vecSubtract: { value: function( a, b ) { var rtnVec; @@ -119,7 +119,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - vecAdd: { + vecAdd: { value: function( a, b ) { var rtnVec; @@ -136,7 +136,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - vecDist: { + vecDist: { value: function( a, b ) { var sum; @@ -176,7 +176,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - getPointOnPlane: { + getPointOnPlane: { value: function( plane ) { // abreviate the plane equation @@ -203,7 +203,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - transformPlane: { + transformPlane: { value: function( plane, mat ) { // we will project a point down one of the coordinate axes to find a point on the plane @@ -213,7 +213,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // find a point on the plane var ptOnPlane = this.getPointOnPlane(plane); - ptOnPlane[3] = 1.0; // 4 dimen so we can transform it + ptOnPlane[3] = 1.0; // 4 dimen so we can transform it // transform the point //ptOnPlane = mat.multiply( ptOnPlane ); @@ -225,12 +225,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - transformHomogeneousPoint: { + transformHomogeneousPoint: { value: function( srcPt, mat ) { var pt = srcPt.slice(0); this.makeDimension4( pt ); - var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ), + var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ), y = VecUtils.vecDot(4, pt, [mat[1], mat[5], mat[ 9], mat[13]] ), z = VecUtils.vecDot(4, pt, [mat[2], mat[6], mat[10], mat[14]] ), w = VecUtils.vecDot(4, pt, [mat[3], mat[7], mat[11], mat[15]] ); @@ -239,7 +239,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - applyHomogeneousCoordinate: { + applyHomogeneousCoordinate: { value: function( hPt ) { var w = hPt[3]; @@ -252,19 +252,19 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - transformAndDivideHomogeneousPoint: { + transformAndDivideHomogeneousPoint: { value: function( pt, mat ) { return this.applyHomogeneousCoordinate( this.transformHomogeneousPoint(pt, mat) ); } }, - transformPoint: { + transformPoint: { value: function( srcPt, mat ) { var pt = srcPt.slice(0); this.makeDimension3( pt ); - var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12], + var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12], y = VecUtils.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13], z = VecUtils.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14]; @@ -272,11 +272,11 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - transformVector: { + transformVector: { value: function( vec, mat ) { this.makeDimension3( vec ); - var x = VecUtils.vecDot(3, vec, [mat[0], mat[4], mat[ 8]] ), + var x = VecUtils.vecDot(3, vec, [mat[0], mat[4], mat[ 8]] ), y = VecUtils.vecDot(3, vec, [mat[1], mat[5], mat[ 9]] ), z = VecUtils.vecDot(3, vec, [mat[2], mat[6], mat[10]] ); @@ -284,7 +284,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - interpolateLine3D: { + interpolateLine3D: { value: function( pt0, pt1, t ) { var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2], @@ -444,7 +444,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - nearestPointOnLine2D: { + nearestPointOnLine2D: { value: function( linePt, lineDir, pt ) { var vec = this.vecSubtract( pt, linePt ); @@ -458,7 +458,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - parameterizePointOnLine2D: { + parameterizePointOnLine2D: { value: function( linePt, lineDir, ptOnLine ) { var t; @@ -483,7 +483,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - pointsEqual: { + pointsEqual: { value: function( dimen, a, b ) { if ((a.length < dimen) || (b.length < dimen)) @@ -582,107 +582,107 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - rectsOverlap: - { - value: function( pt, width, height, elt ) - { - // only consider rectangles with non-zero area - if ((width == 0) || (height == 0)) return false; - - // get the mins/maxs of the onput rectangle - var xMin, xMax, yMin, yMax; - if (width > 0) { xMin = pt[0]; xMax = pt[0] + width; } - else { xMax = pt[0]; xMin = pt[0] + width; } - if (height > 0) { yMin = pt[1]; yMax = pt[1] + height; } - else { yMax = pt[1]; yMin = pt[1] + height; } - - // get the bounds of the element in global screen space - var bounds = ViewUtils.getElementViewBounds3D( elt ); - var bounds3D = []; - for (var i=0; i<4; i++) - bounds3D[i] = ViewUtils.localToGlobal( bounds[i], elt ); - - // get the min/maxs for the element - var xMinElt = bounds3D[0][0], xMaxElt = bounds3D[0][0], - yMinElt = bounds3D[0][1], yMaxElt = bounds3D[0][1]; - for (var i=1; i<4; i++) - { - if (bounds3D[i][0] < xMinElt) xMinElt = bounds3D[i][0]; - else if (bounds3D[i][0] > xMaxElt) xMaxElt = bounds3D[i][0]; - if (bounds3D[i][1] < yMinElt) yMinElt = bounds3D[i][1]; - else if (bounds3D[i][1] > yMaxElt) yMaxElt = bounds3D[i][1]; - } - - // test 1. Overall bounding box test - if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax)) - return false; - - // test 2. See if any of the corners of the element are contained in the rectangle - var rect = Object.create(Rectangle, {}); - rect.set( pt[0], pt[1], width, height ); - for (var i=0; i<4; i++) - { - if (rect.contains( bounds3D[i][0], bounds3D[i][1] )) return true; - } - - // test 3. Bounding box tests on individual edges of the element - for (var i=0; i<4; i++) - { - var pt0 = bounds3D[i], - pt1 = bounds3D[(i+1)%4]; - - // get the extremes of the edge - if (pt0[0] < pt1[0]) { xMinElt = pt0[0]; xMaxElt = pt1[0]; } - else { xMaxElt = pt0[0]; xMinElt = pt1[0]; } - if (pt0[1] < pt1[1]) { yMinElt = pt0[1]; yMaxElt = pt1[1]; } - else { yMaxElt = pt0[1]; yMinElt = pt1[1]; } - - if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax)) - continue; - else - { - // intersect the element edge with the 4 sides of the rectangle - // vertical edges - var xRect = xMin; - for (var j=0; j<2; j++) - { - if ((xMinElt < xRect) && (xMaxElt > xRect)) - { - var t = (xRect - pt0[0])/(pt1[0] - pt0[0]); - var y = pt0[1] + t*(pt1[1] - pt0[1]); - if ((y >= yMin) && (y <= yMax)) return true; - } - xRect = xMax; - } - - // horizontal edges - var yRect = yMin; - for (var j=0; j<2; j++) - { - if ((yMinElt < yRect) && (yMaxElt > yRect)) - { - var t = (yRect - pt0[1])/(pt1[1] - pt0[1]); - var x = pt0[0] + t*(pt1[0] - pt0[0]); - if ((x >= xMin) && (x <= xMax)) return true; - } - yRect = yMax; - } - } - } - - // if we get here there is no overlap - return false; - } - }, + rectsOverlap: + { + value: function( pt, width, height, elt ) + { + // only consider rectangles with non-zero area + if ((width == 0) || (height == 0)) return false; + + // get the mins/maxs of the onput rectangle + var xMin, xMax, yMin, yMax; + if (width > 0) { xMin = pt[0]; xMax = pt[0] + width; } + else { xMax = pt[0]; xMin = pt[0] + width; } + if (height > 0) { yMin = pt[1]; yMax = pt[1] + height; } + else { yMax = pt[1]; yMin = pt[1] + height; } + + // get the bounds of the element in global screen space + var bounds = ViewUtils.getElementViewBounds3D( elt ); + var bounds3D = []; + for (var i=0; i<4; i++) + bounds3D[i] = ViewUtils.localToGlobal( bounds[i], elt ); + + // get the min/maxs for the element + var xMinElt = bounds3D[0][0], xMaxElt = bounds3D[0][0], + yMinElt = bounds3D[0][1], yMaxElt = bounds3D[0][1]; + for (var i=1; i<4; i++) + { + if (bounds3D[i][0] < xMinElt) xMinElt = bounds3D[i][0]; + else if (bounds3D[i][0] > xMaxElt) xMaxElt = bounds3D[i][0]; + if (bounds3D[i][1] < yMinElt) yMinElt = bounds3D[i][1]; + else if (bounds3D[i][1] > yMaxElt) yMaxElt = bounds3D[i][1]; + } + + // test 1. Overall bounding box test + if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax)) + return false; + + // test 2. See if any of the corners of the element are contained in the rectangle + var rect = Object.create(Rectangle, {}); + rect.set( pt[0], pt[1], width, height ); + for (var i=0; i<4; i++) + { + if (rect.contains( bounds3D[i][0], bounds3D[i][1] )) return true; + } + + // test 3. Bounding box tests on individual edges of the element + for (var i=0; i<4; i++) + { + var pt0 = bounds3D[i], + pt1 = bounds3D[(i+1)%4]; + + // get the extremes of the edge + if (pt0[0] < pt1[0]) { xMinElt = pt0[0]; xMaxElt = pt1[0]; } + else { xMaxElt = pt0[0]; xMinElt = pt1[0]; } + if (pt0[1] < pt1[1]) { yMinElt = pt0[1]; yMaxElt = pt1[1]; } + else { yMaxElt = pt0[1]; yMinElt = pt1[1]; } + + if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax)) + continue; + else + { + // intersect the element edge with the 4 sides of the rectangle + // vertical edges + var xRect = xMin; + for (var j=0; j<2; j++) + { + if ((xMinElt < xRect) && (xMaxElt > xRect)) + { + var t = (xRect - pt0[0])/(pt1[0] - pt0[0]); + var y = pt0[1] + t*(pt1[1] - pt0[1]); + if ((y >= yMin) && (y <= yMax)) return true; + } + xRect = xMax; + } + + // horizontal edges + var yRect = yMin; + for (var j=0; j<2; j++) + { + if ((yMinElt < yRect) && (yMaxElt > yRect)) + { + var t = (yRect - pt0[1])/(pt1[1] - pt0[1]); + var x = pt0[0] + t*(pt1[0] - pt0[0]); + if ((x >= xMin) && (x <= xMax)) return true; + } + yRect = yMax; + } + } + } + + // if we get here there is no overlap + return false; + } + }, /////////////////////////////////////////////////////////////////////// // Bezier Methods /////////////////////////////////////////////////////////////////////// - // this function returns the quadratic Bezier approximation to the specified - // circular arc. The input can be 2D or 3D, determined by the minimum dimension - // of the center and start point. - // includedAngle is in radians, can be positiveor negative - circularArcToBezier: { + // this function returns the quadratic Bezier approximation to the specified + // circular arc. The input can be 2D or 3D, determined by the minimum dimension + // of the center and start point. + // includedAngle is in radians, can be positiveor negative + circularArcToBezier: { value: function( ctr_, startPt_, includedAngle ) { var dimen = 3; @@ -753,16 +753,16 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // the area of the polygon is the length of the normal var area = VecUtils.vecMag(3, normal ); if (this.fpSign(area) != 0) - { + { //vec3.scale(normal, 1.0/area); - normal = VecUtils.vecNormalize(3, normal, 1.0); - } + normal = VecUtils.vecNormalize(3, normal, 1.0); + } return normal; } }, - getNormalFromBounds3D: { + getNormalFromBounds3D: { value: function( b ) { var xNrm = 0.0, yNrm = 0.0, zNrm = 0.0; @@ -785,7 +785,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - getCenterFromBounds: { + getCenterFromBounds: { value: function( dimen, bounds ) { var minVals = bounds[0].slice(0), @@ -987,7 +987,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, - colorToHex: { + colorToHex: { value: function( colorArray ) { if (colorArray.length < 3) return "#000000"; -- cgit v1.2.3 From 04343eda8c2f870b0da55cfdc8003c99fe1cc4de Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:53:10 -0700 Subject: Remove trailing spaces --- js/helper-classes/3D/math-utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/helper-classes/3D/math-utils.js') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 3c981d0d..191b02bd 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -41,7 +41,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // Instance variables /////////////////////////////////////////////////////////////////////// // VecUtils: { value: null, writable: true }, - + EPSILON: { value: 1.e-5, writable: true }, // these are used in containment tests @@ -616,7 +616,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // test 1. Overall bounding box test if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax)) return false; - + // test 2. See if any of the corners of the element are contained in the rectangle var rect = Object.create(Rectangle, {}); rect.set( pt[0], pt[1], width, height ); @@ -939,7 +939,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { }, /////////////////////////////////////////////////////////////////////// - // Utility method to calculate angle between two 3D vectors + // Utility method to calculate angle between two 3D vectors /////////////////////////////////////////////////////////////////////// getAxisAngleBetween3DVectors: { value: function (vec1, vec2, axis) { -- cgit v1.2.3