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/LinePlaneIntersectRec.js | 16 +- js/helper-classes/3D/Rectangle.js | 8 +- js/helper-classes/3D/StageLine.js | 372 +-- js/helper-classes/3D/draw-utils.js | 2092 ++++++------- js/helper-classes/3D/hit-record.js | 322 +- js/helper-classes/3D/math-utils.js | 252 +- js/helper-classes/3D/snap-2d-record.js | 84 +- js/helper-classes/3D/snap-manager.js | 4042 ++++++++++++------------- js/helper-classes/3D/vec-utils.js | 146 +- js/helper-classes/3D/view-utils.js | 318 +- 10 files changed, 3826 insertions(+), 3826 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/LinePlaneIntersectRec.js b/js/helper-classes/3D/LinePlaneIntersectRec.js index 71ee81f4..ec2d6d57 100755 --- a/js/helper-classes/3D/LinePlaneIntersectRec.js +++ b/js/helper-classes/3D/LinePlaneIntersectRec.js @@ -60,17 +60,17 @@ var LinePlaneIntersectRec = exports.LinePlaneIntersectRec = Object.create(Object getElementPlanes: { value: function() { return this._elementPlanes; } }, setElementPlanes: { value: function(p) { this._elementPlanes = p; } }, - getT: { value: function() { return this._t; } }, - setT: { value: function(t) { this._t = t; } }, + getT: { value: function() { return this._t; } }, + setT: { value: function(t) { this._t = t; } }, - setDeltaVis: { value: function(d) { this._deltaVis = d; } }, - getDeltaVis: { value: function() { return this._deltaVis; } }, + setDeltaVis: { value: function(d) { this._deltaVis = d; } }, + getDeltaVis: { value: function() { return this._deltaVis; } }, - setNext: { value: function(n) { this._next = n; } }, - getNext: { value: function() { return this._next; } }, + setNext: { value: function(n) { this._next = n; } }, + getNext: { value: function() { return this._next; } }, - getPrev: { value: function() { return this._prev; } }, - setPrev: { value: function(p) { this._prev = p; } } + getPrev: { value: function() { return this._prev; } }, + setPrev: { value: function(p) { this._prev = p; } } /////////////////////////////////////////////////////////////////////// // Methods diff --git a/js/helper-classes/3D/Rectangle.js b/js/helper-classes/3D/Rectangle.js index 1922bd91..fb6127ed 100755 --- a/js/helper-classes/3D/Rectangle.js +++ b/js/helper-classes/3D/Rectangle.js @@ -67,7 +67,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { getHeight: { value: function() { return this.m_height; } }, setHeight: { value: function(h) { this.m_height = h; } }, - geomType: { value: function() { return this.GEOM_TYPE_RECTANGLE; } }, + geomType: { value: function() { return this.GEOM_TYPE_RECTANGLE; } }, /////////////////////////////////////////////////////////////////////// // Methods @@ -84,7 +84,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - dup: { + dup: { value: function() { var rtnRec = Object.create(Rectangle, {}); @@ -122,7 +122,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - setToBounds: { + setToBounds: { value: function( bounds ) { var pt = bounds[0]; @@ -166,7 +166,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - getQuadrant: { + getQuadrant: { value: function( iQuad ) { // quadrant ordering starts at upper left and continues around counter-clockwise diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index 787a4568..d6eea478 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -120,7 +120,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { // add the intersection var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; var deltaVis = (dot > 0) ? 1 : -1; -// if (plane.isBackFacing()) +// if (plane.isBackFacing()) // deltaVis = (dot < 0) ? 1 : -1; this.addIntersection( plane, t, deltaVis ); @@ -175,14 +175,14 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { MathUtils.negate( vec ); planeEq = [-vec[1], vec[0], 0]; var normal = [planeEq[0], planeEq[1], planeEq[2]]; -// var d = -planeEq.dot(bPt0); +// var d = -planeEq.dot(bPt0); var d = -vecUtils.vecDot(3, planeEq, bPt0); planeEq[3] = d; t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); if (t) { - if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! + if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! { // get the intersection point var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); @@ -207,184 +207,184 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } }, - doCoplanarIntersection: { - value: function( plane ) - { - // get the boundary points for the plane - var boundaryPts = plane.getBoundaryPoints(); - var planeEq = plane.getPlaneEq(); - - if (plane.isBackFacing()) - { - var tmp; - tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; - tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; - } - - var pt0 = this.getPoint0(), - pt1 = this.getPoint1(); - - // keep a couple flags to prevent counting crossings twice in edge cases - var gotEnter = false, - gotExit = false; - - var bp1 = boundaryPts[3]; - for (var i=0; i<4; i++) - { - var bp0 = bp1; - bp1 = boundaryPts[i]; - var vec = vecUtils.vecSubtract(3, bp1, bp0); - var nrm = vecUtils.vecCross(3, vec, planeEq); - nrm[3] = -vecUtils.vecDot(3, bp0, nrm); - - var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], - d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; - - var s0 = MathUtils.fpSign(d0), - s1 = MathUtils.fpSign(d1); - - if (s0 != s1) - { - var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); - if (t == 0) - { - if (s1 > 0) // entering the material from the beginning of the line that is to be drawn - { - // see if the start point of the line is at a corner of the bounded plane - var lineDir = vecUtils.vecSubtract(3, pt1, pt0); - vecUtils.vecNormalize(3, lineDir); - var dist = vecUtils.vecDist( 3, pt0, bp1 ); - var bp2, bv0, bv1, cross1, cross2, cross3; - if ( MathUtils.fpSign(dist) == 0) - { - bp2 = boundaryPts[(i+1) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp1); - bv1 = vecUtils.vecSubtract(3, bp0, bp1); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) - { - bp2 = boundaryPts[(i+2) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp0); - bv1 = vecUtils.vecSubtract(3, bp1, bp0); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else - { - // check if the line is on the edge of the boundary or goes to the interior - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - } - else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) - { - // get the point where the line crosses the edge of the element plane - var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); - - // we know that the line crosses the infinite extension of the edge. Determine - // if that crossing is within the bounds of the edge - var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), - dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); - if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) - { - // determine if the line is entering or exiting - if (s0 <= 0) // entering - { - if (!gotEnter) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) // exiting - { - if (!gotExit) - { - gotExit = true; - this.addIntersection( plane, t, -1 ); - } - } - else // s0 == 0 - { - // TODO - } - } - else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) - { - var j = i - 2; - if (j < 0) j += 4; - var bp = boundaryPts[j]; - - var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), - v1 = vec; - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) - { - var j = (i + 1) % 4; - var bp = boundaryPts[j]; - - var v1 = vec.slice(0), - v0 = vecUtils.vecSubtract( 3, bp, bp1 ), - v1 = vecUtils.vecNegate(3, v1); - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - } - } - } - } - }, + doCoplanarIntersection: { + value: function( plane ) + { + // get the boundary points for the plane + var boundaryPts = plane.getBoundaryPoints(); + var planeEq = plane.getPlaneEq(); + + if (plane.isBackFacing()) + { + var tmp; + tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; + tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; + } + + var pt0 = this.getPoint0(), + pt1 = this.getPoint1(); + + // keep a couple flags to prevent counting crossings twice in edge cases + var gotEnter = false, + gotExit = false; + + var bp1 = boundaryPts[3]; + for (var i=0; i<4; i++) + { + var bp0 = bp1; + bp1 = boundaryPts[i]; + var vec = vecUtils.vecSubtract(3, bp1, bp0); + var nrm = vecUtils.vecCross(3, vec, planeEq); + nrm[3] = -vecUtils.vecDot(3, bp0, nrm); + + var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], + d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; + + var s0 = MathUtils.fpSign(d0), + s1 = MathUtils.fpSign(d1); + + if (s0 != s1) + { + var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); + if (t == 0) + { + if (s1 > 0) // entering the material from the beginning of the line that is to be drawn + { + // see if the start point of the line is at a corner of the bounded plane + var lineDir = vecUtils.vecSubtract(3, pt1, pt0); + vecUtils.vecNormalize(3, lineDir); + var dist = vecUtils.vecDist( 3, pt0, bp1 ); + var bp2, bv0, bv1, cross1, cross2, cross3; + if ( MathUtils.fpSign(dist) == 0) + { + bp2 = boundaryPts[(i+1) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp1); + bv1 = vecUtils.vecSubtract(3, bp0, bp1); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) + { + bp2 = boundaryPts[(i+2) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp0); + bv1 = vecUtils.vecSubtract(3, bp1, bp0); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else + { + // check if the line is on the edge of the boundary or goes to the interior + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + } + else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) + { + // get the point where the line crosses the edge of the element plane + var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); + + // we know that the line crosses the infinite extension of the edge. Determine + // if that crossing is within the bounds of the edge + var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), + dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); + if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) + { + // determine if the line is entering or exiting + if (s0 <= 0) // entering + { + if (!gotEnter) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) // exiting + { + if (!gotExit) + { + gotExit = true; + this.addIntersection( plane, t, -1 ); + } + } + else // s0 == 0 + { + // TODO + } + } + else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) + { + var j = i - 2; + if (j < 0) j += 4; + var bp = boundaryPts[j]; + + var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), + v1 = vec; + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) + { + var j = (i + 1) % 4; + var bp = boundaryPts[j]; + + var v1 = vec.slice(0), + v0 = vecUtils.vecSubtract( 3, bp, bp1 ), + v1 = vecUtils.vecNegate(3, v1); + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + } + } + } + } + }, removeIntersections: { value: function() @@ -440,7 +440,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } }, - boundaryContainsPoint: { + boundaryContainsPoint: { value: function( boundaryPts, backFacing, pt ) { // the computation is done in 2D. @@ -451,12 +451,12 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { { var pt0 = pt1; var pt1 = boundaryPts[i]; - //var vec0 = pt1.subtract( pt0 ), - // vec1 = pt.subtract( pt0 ); + //var vec0 = pt1.subtract( pt0 ), + // vec1 = pt.subtract( pt0 ); var vec0 = vecUtils.vecSubtract(3, pt1, pt0), vec1 = vecUtils.vecSubtract(pt, pt0); - // var cross = vec0.cross( vec1 ); + // var cross = vec0.cross( vec1 ); var cross = vecUtils.vecCross(3, vec0, vec1); var inside; if (backFacing) @@ -468,7 +468,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } return true; - } + } }, setPoints: { diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 235b381e..6f4c287d 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -42,104 +42,104 @@ var StageLine = require("js/helper-classes/3D/StageLine").StageLine; var DrawUtils = exports.DrawUtils = Montage.create(Component, { - /////////////////////////////////////////////////////////////////////// - // Instance variables - /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// viewUtils: { value: null, writable: true }, snapManager: { value: null }, ElementPlanes : { value: null, writable: true }, - // the drawing surface (a canvas) - _drawingSurfaceElt : { value: null, writable: true }, - _drawingContext : { value: null, writable: true }, + // the drawing surface (a canvas) + _drawingSurfaceElt : { value: null, writable: true }, + _drawingContext : { value: null, writable: true }, - // color to draw the lines - _lineColor : { value: "black", writable: true}, + // color to draw the lines + _lineColor : { value: "black", writable: true}, - // define a stack for quickly setting graphics states and restoring them - _stateArray : { value: [], writable: true }, + // define a stack for quickly setting graphics states and restoring them + _stateArray : { value: [], writable: true }, - // save references to the grid lines for quick redraw - _gridLineArray : {value: [], writable: true }, + // save references to the grid lines for quick redraw + _gridLineArray : {value: [], writable: true }, - // state for moveTo, lineTo - _curPt : { value: null, writable: true }, - _curVis : { value: null, writable: true }, + // state for moveTo, lineTo + _curPt : { value: null, writable: true }, + _curVis : { value: null, writable: true }, - // the element that defines the coordinate system for the displayed lines - _sourceSpaceElt : { value: null, writable: true }, + // the element that defines the coordinate system for the displayed lines + _sourceSpaceElt : { value: null, writable: true }, - // maintain a list of objects to hide against - _eltArray : {value: [], writable: true }, + // maintain a list of objects to hide against + _eltArray : {value: [], writable: true }, - // maintain a list of the planes to test against - _planesArray : {value: [], writable: true }, + // maintain a list of the planes to test against + _planesArray : {value: [], writable: true }, - // the working plane. - // a grid may be drawn aligned with this working plane - _workingPlane : { value: null, writable: true }, + // the working plane. + // a grid may be drawn aligned with this working plane + _workingPlane : { value: null, writable: true }, - // save some parameters about the grid. - // these parameters are set when the grid is drawn - _gridHorizontalSpacing : {value: 50, writable: true }, - _gridVerticalSpacing : {value: 50, writable: true }, - _gridHorizontalLineCount : {value:10, writable: true }, - _gridVerticalLineCount : {value:0, writable: true }, - _gridOrigin : {value: null, writable: true }, + // save some parameters about the grid. + // these parameters are set when the grid is drawn + _gridHorizontalSpacing : {value: 50, writable: true }, + _gridVerticalSpacing : {value: 50, writable: true }, + _gridHorizontalLineCount : {value:10, writable: true }, + _gridVerticalLineCount : {value:0, writable: true }, + _gridOrigin : {value: null, writable: true }, - drawXY : {value: false, writable: true }, - drawXZ : {value: false, writable: true }, - drawYZ : {value: false, writable: true }, + drawXY : {value: false, writable: true }, + drawXZ : {value: false, writable: true }, + drawYZ : {value: false, writable: true }, - drawElementN : {value: false, writable: true }, + drawElementN : {value: false, writable: true }, - _selectionCtr : {value: null, writable: true }, + _selectionCtr : {value: null, writable: true }, // Properties that require element planes to be updated - _updatePlaneProps : {value: ["matrix", "left", "top", "width", "height"], writable: false }, - _recalculateScrollOffsets : { value: false }, + _updatePlaneProps : {value: ["matrix", "left", "top", "width", "height"], writable: false }, + _recalculateScrollOffsets : { value: false }, - /////////////////////////////////////////////////////////////////////// - // Property accessors - /////////////////////////////////////////////////////////////////////// - setDrawingSurfaceElement : { value: function( s ) { this._drawingSurfaceElt = s; if (s) this._drawingContext = s.getContext("2d"); }}, - getDrawingSurfaceElement : { value: function() { return this._drawingSurfaceElt; }}, + /////////////////////////////////////////////////////////////////////// + // Property accessors + /////////////////////////////////////////////////////////////////////// + setDrawingSurfaceElement : { value: function( s ) { this._drawingSurfaceElt = s; if (s) this._drawingContext = s.getContext("2d"); }}, + getDrawingSurfaceElement : { value: function() { return this._drawingSurfaceElt; }}, - getDrawingContext : { value: function() { return this._drawingContext; }}, + getDrawingContext : { value: function() { return this._drawingContext; }}, - setSourceSpaceElement : { value: function(ss) { this._sourceSpaceElt = ss; }}, - getSourceSpaceElement : { value: function() { return this._sourceSpaceElt; }}, + setSourceSpaceElement : { value: function(ss) { this._sourceSpaceElt = ss; }}, + getSourceSpaceElement : { value: function() { return this._sourceSpaceElt; }}, - getWorkingPlane : { value: function() { return this._workingPlane; }}, - setWorkingPlane : { value: function (wp) { this._workingPlane = wp; }}, + getWorkingPlane : { value: function() { return this._workingPlane; }}, + setWorkingPlane : { value: function (wp) { this._workingPlane = wp; }}, - getGridHorizontalSpacing : { value: function() { return this._gridHorizontalSpacing; }}, - getGridVerticalSpacing : { value: function() { return this._gridVerticalSpacing; }}, - getGridHorizontalLineCount : { value: function() { return this._gridHorizontalLineCount; }}, - getGridVerticalLineCount : { value: function() { return this._gridVerticalLineCount; }}, - getGridOrigin : { value: function() { return this._gridOrigin.slice(0); }}, + getGridHorizontalSpacing : { value: function() { return this._gridHorizontalSpacing; }}, + getGridVerticalSpacing : { value: function() { return this._gridVerticalSpacing; }}, + getGridHorizontalLineCount : { value: function() { return this._gridHorizontalLineCount; }}, + getGridVerticalLineCount : { value: function() { return this._gridVerticalLineCount; }}, + getGridOrigin : { value: function() { return this._gridOrigin.slice(0); }}, - isDrawingGrid : { value: function() { return this.drawXY || this.drawYZ || this.drawXZ; }}, - isDrawingElementNormal : { value: function() { return this.drawElementN }}, + isDrawingGrid : { value: function() { return this.drawXY || this.drawYZ || this.drawXZ; }}, + isDrawingElementNormal : { value: function() { return this.drawElementN }}, - getLineColor : { value: function() { return this._lineColor; }}, - setLineColor : { value: function( color ) { this._lineColor = color; }}, + getLineColor : { value: function() { return this._lineColor; }}, + setLineColor : { value: function( color ) { this._lineColor = color; }}, - getLineWidth : { value: function() { return this._drawingContext.lineWidth; }}, - setLineWidth : { value: function( w ) { this._drawingContext.lineWidth = w; }}, + getLineWidth : { value: function() { return this._drawingContext.lineWidth; }}, + setLineWidth : { value: function( w ) { this._drawingContext.lineWidth = w; }}, - initialize: { - value: function() { - this._gridOrigin = [0,0]; // 2D plane space point + initialize: { + value: function() { + this._gridOrigin = [0,0]; // 2D plane space point this.eventManager.addEventListener("elementAdded", this, false); this.eventManager.addEventListener("elementsRemoved", this, false); this.eventManager.addEventListener("elementChange", this, false); this.eventManager.addEventListener("elementChanging", this, false); this.eventManager.addEventListener("elementReplaced", this, false); - } - }, + } + }, initializeFromDocument:{ value:function(adjustScrollOffsets, useStageValues){ @@ -364,502 +364,502 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } }, - /////////////////////////////////////////////////////////////////////// - // Methods - /////////////////////////////////////////////////////////////////////// - - addElement: { - value: function( elt ) { - // check if we already know about this object - var n = this._eltArray.length; - for (var i=0; i 3) pt.pop(); - - var z = pt[2]; - var n = this._planesArray.length; - var vis = 0; - for (var i=0; i plane.getZMax()) continue; - - // test for containment in the polygon bounds - var contain = MathUtils.boundaryContainsPoint( plane.getBoundaryPoints(), pt, plane.isBackFacing() ); - if (contain == MathUtils.OUTSIDE) continue; - if (contain == MathUtils.ON) continue; - - // shoot a ray from the point in the +Z direction to get the z value of the plane - var vec = [0,0,1]; - var planeEq = plane.getPlaneEq(); - var ptOnPlane = MathUtils.vecIntersectPlane( pt, vec, planeEq ); - if (ptOnPlane) - { - // in keeping with the convention that a point "on" a face is outside the element, - // check that case. - //if (MathUtils.fpCmp(pt[2], ptOnPlane[2]) == 0) continue; - - // if the point is behind the plane, increase the visibility - if (MathUtils.fpCmp(pt[2],ptOnPlane[2]) <= 0) vis++; - } - } - - return vis; - } - }, - - moveTo : { - value: function( pt ) { - if (this._sourceSpaceElt) - pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); - - this._curPt = pt.slice(0); - this._curVis = this.getVisibilityAtPoint( pt ); - } - }, - - lineTo : - { - value: function( pt ) - { - if (this._sourceSpaceElt) - pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); - - var line = Object.create(StageLine, {}); - line.setPoints( this._curPt, pt ); - line.setVisibility( this._curVis ); - - // find all the plane intersections - this.getLineIntersections( line ); - - // draw the line - this._curVis = this.drawIntersectedLine( line, this._drawingContext ); - this._curPt = pt.slice(0); - } - }, - - - drawLine : - { - value: function( pt0, pt1 ) - { - if (this._drawingContext) - { - // transform the points from local object space to world space - if (this._sourceSpaceElt) - { - pt0 = this.viewUtils.localToGlobal( pt0, this._sourceSpaceElt ); - pt1 = this.viewUtils.localToGlobal( pt1, this._sourceSpaceElt ); - } - - // create the line structure - var line = Object.create(StageLine, {}); - line.setPoints( pt0, pt1 ); - - // find all the plane intersections - this.getLineIntersections( line ); - - // get the starting visibility - var vis = this.getVisibilityAtPoint( pt0 ); - line.setVisibility( vis ); - - // draw the line - this._curVis = this.drawIntersectedLine( line, this._drawingContext ); - } - } - }, - - drawIntersectedLine : - { - value: function( line ) - { - this._drawingContext.strokeStyle = this._lineColor; - this._drawingContext.beginPath(); - - // get the 2 enpoints of the line - var pt0 = line.getPoint0(), - pt1 = line.getPoint1(); - - // find the visibility at the start point - var vis = line.getVisibility(); - if (vis == 0) - { - this._drawingContext.strokeStyle = this._lineColor; - this._drawingContext.beginPath(); - this._drawingContext.moveTo( pt0[0], pt0[1] ); - } - - // go through each intersection - var n = line.getIntersectionCount(); - var t = 0.0; - var iRec = line.getIntersectionList(); - for (var i=0; i 3) pt.pop(); + + var z = pt[2]; + var n = this._planesArray.length; + var vis = 0; + for (var i=0; i plane.getZMax()) continue; + + // test for containment in the polygon bounds + var contain = MathUtils.boundaryContainsPoint( plane.getBoundaryPoints(), pt, plane.isBackFacing() ); + if (contain == MathUtils.OUTSIDE) continue; + if (contain == MathUtils.ON) continue; + + // shoot a ray from the point in the +Z direction to get the z value of the plane + var vec = [0,0,1]; + var planeEq = plane.getPlaneEq(); + var ptOnPlane = MathUtils.vecIntersectPlane( pt, vec, planeEq ); + if (ptOnPlane) + { + // in keeping with the convention that a point "on" a face is outside the element, + // check that case. + //if (MathUtils.fpCmp(pt[2], ptOnPlane[2]) == 0) continue; + + // if the point is behind the plane, increase the visibility + if (MathUtils.fpCmp(pt[2],ptOnPlane[2]) <= 0) vis++; + } + } + + return vis; + } + }, + + moveTo : { + value: function( pt ) { + if (this._sourceSpaceElt) + pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); + + this._curPt = pt.slice(0); + this._curVis = this.getVisibilityAtPoint( pt ); + } + }, + + lineTo : + { + value: function( pt ) + { + if (this._sourceSpaceElt) + pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); + + var line = Object.create(StageLine, {}); + line.setPoints( this._curPt, pt ); + line.setVisibility( this._curVis ); + + // find all the plane intersections + this.getLineIntersections( line ); + + // draw the line + this._curVis = this.drawIntersectedLine( line, this._drawingContext ); + this._curPt = pt.slice(0); + } + }, + + + drawLine : + { + value: function( pt0, pt1 ) + { + if (this._drawingContext) + { + // transform the points from local object space to world space + if (this._sourceSpaceElt) + { + pt0 = this.viewUtils.localToGlobal( pt0, this._sourceSpaceElt ); + pt1 = this.viewUtils.localToGlobal( pt1, this._sourceSpaceElt ); + } + + // create the line structure + var line = Object.create(StageLine, {}); + line.setPoints( pt0, pt1 ); + + // find all the plane intersections + this.getLineIntersections( line ); + + // get the starting visibility + var vis = this.getVisibilityAtPoint( pt0 ); + line.setVisibility( vis ); + + // draw the line + this._curVis = this.drawIntersectedLine( line, this._drawingContext ); + } + } + }, + + drawIntersectedLine : + { + value: function( line ) + { + this._drawingContext.strokeStyle = this._lineColor; + this._drawingContext.beginPath(); + + // get the 2 enpoints of the line + var pt0 = line.getPoint0(), + pt1 = line.getPoint1(); + + // find the visibility at the start point + var vis = line.getVisibility(); + if (vis == 0) + { + this._drawingContext.strokeStyle = this._lineColor; + this._drawingContext.beginPath(); + this._drawingContext.moveTo( pt0[0], pt0[1] ); + } + + // go through each intersection + var n = line.getIntersectionCount(); + var t = 0.0; + var iRec = line.getIntersectionList(); + for (var i=0; i