diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index 91e5decf0ca1a3aa51281875de59b4bb5c9a34ef..59bcf25f397fd3693a68d0ae8097907935b70b8c 100644 --- a/js/lattice/CubeLattice.js +++ b/js/lattice/CubeLattice.js @@ -4,52 +4,51 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - CubeLattice: { - - _initLatticeType: function(){ - require(['squareBaseplane'], function(SquareBasePlane){ - globals.basePlane = new SquareBasePlane(); - }); - require(['cubeHighlighter'], function(CubeHighlighter){ - globals.highlighter = new CubeHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return 1+2*cellSeparation; - }, - - makeCellForLatticeType: function(indices){ - return new CubeCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.CubeLattice), function(key){ - self[key] = null; - }); - } + var CubeLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require(['cubeHighlighter'], function(CubeHighlighter){ + globals.highlighter = new CubeHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 1+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices){ + return new CubeCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(CubeLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return CubeLattice; }); diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index a8bf98df3d0c5bdab67f8c5505963932df60a58a..352333cbba2d0f9df949934d30a9df926473f4f9 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -4,52 +4,51 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - GIKLattice: { - - _initLatticeType: function(){ - require(['squareBaseplane'], function(SquareBasePlane){ - globals.basePlane = new SquareBasePlane(); - }); - require(['gikHighlighter'], function(GIKHighlighter){ - globals.highlighter = new GIKHighlighter(); - globals.highlighter.updateGikLength(); - }); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return 1.28*(1+2*cellSeparation); - }, - - makeCellForLatticeType: function(indices){ - return new GIKSuperCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.GIKLattice), function(key){ - self[key] = null; - }); - } + var GIKLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require(['gikHighlighter'], function(GIKHighlighter){ + globals.highlighter = new GIKHighlighter(); + globals.highlighter.updateGikLength(); + }); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 1.28*(1+2*cellSeparation); + }, + + makeCellForLatticeType: function(indices){ + return new GIKSuperCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(GIKLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return GIKLattice; }); diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js index 7a872cbe940f9c6b6cfc796d108c5b9c5c41fe87..56cc2d04f2435c66f02646c6908609774ec35064 100644 --- a/js/lattice/KelvinLattice.js +++ b/js/lattice/KelvinLattice.js @@ -5,51 +5,51 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - KelvinLattice: { - - _initLatticeType: function(){ - require(['squareBaseplane'], function(SquareBasePlane){ - globals.basePlane = new SquareBasePlane(); - }); - require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){ - globals.highlighter = new TruncatedCubeHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 2*Math.sqrt(2)+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return 2*Math.sqrt(2)+2*cellSeparation; - }, - - makeCellForLatticeType: function(indices){ - return new KelvinCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.KelvinLattice), function(key){ - self[key] = null; - }); - } + var KelvinLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){ + globals.highlighter = new TruncatedCubeHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 2*Math.sqrt(2)+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2*Math.sqrt(2)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices){ + return new KelvinCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(KelvinLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return KelvinLattice; + }); diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 1c6802d594a9a00ece6d25e89cd71e3298e06a98..641ed80675b4ddab40c216fa1a383f34b95111ee 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -378,18 +378,24 @@ define(['appState', 'plist', 'three', 'threeModel', 'globals'], function(appStat if (this._undo) this._undo(); if (globals.basePlane) globals.basePlane.destroy(); if (globals.highlighter) globals.highlighter.destroy(); - _.extend(this, this._getSubclassForLatticeType(loadingFromFile)); - this._initLatticeType(); - //copy over cells to new lattice type - var cells = this.get("cells"); - this._loopCells(cells, function(cell, x, y, z, self){ - if (!cell) return; - var index = _.clone(cell.index); - if (cell.destroy) cell.destroy(); - cells[x][y][z] = self.makeCellForLatticeType(index);// parentPos, parentOrientation, direction, parentType, type) + var subclass = this._getSubclassForLatticeType(loadingFromFile); + var self = this; + require([subclass], function(subclassObject){ + + _.extend(self, subclassObject); + self._initLatticeType(); + + //copy over cells to new lattice type + var cells = self.get("cells"); + self._loopCells(cells, function(cell, x, y, z){ + if (!cell) return; + var index = _.clone(cell.index); + if (cell.destroy) cell.destroy(); + cells[x][y][z] = self.makeCellForLatticeType(index);// parentPos, parentOrientation, direction, parentType, type) + }); + three.render(); }); - three.render(); }, _getSubclassForLatticeType: function(loadingFromFile){ @@ -397,31 +403,34 @@ define(['appState', 'plist', 'three', 'threeModel', 'globals'], function(appStat var connectionType = this.get("connectionType"); if (cellType == "octa"){ if (connectionType == "face"){ - return this.OctaFaceLattice; + return "octaFaceLattice"; } else if (connectionType == "freeformFace"){ if (!loadingFromFile) this.clearCells(); - return this.OctaFreeFormFaceLattice; + return "octaFreeFormFaceLattice"; } else if (connectionType == "edge"){ - return this.OctaEdgeLattice; + return "octaEdgeLattice"; } else if (connectionType == "edgeRot"){ - return this.OctaRotEdgeLattice; + return "octaRotEdgeLattice"; } else if (connectionType == "vertex"){ - return this.OctaVertexLattice; + return "octaVertexLattice"; } } else if (cellType == "tetra"){ - return this.CubeLattice; + return "cubeLattice"; } else if (cellType == "cube"){ if (connectionType == "face"){ - return this.CubeLattice; + return "cubeLattice"; } else if (connectionType == "gik"){ if (!loadingFromFile) this.clearCells(); - return this.GIKLattice; + return "gikLattice"; } } else if (cellType == "truncatedCube"){ - return this.TruncatedCubeLattice; + return "truncatedCubeLattice"; } else if (cellType == "kelvin"){ - return this.KelvinLattice; + return "kelvinLattice"; + } else { + console.warn("unrecognized cell type " + cellType); } + return null; }, _setToDefaultsSilently: function(){ diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js index 62b6a02e85b7ace9226a9c953221072d6510097e..49957abc18159dfd0e3e67f3b762fab71ab30f1e 100644 --- a/js/lattice/OctaEdgeLattice.js +++ b/js/lattice/OctaEdgeLattice.js @@ -4,77 +4,76 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { + var OctaEdgeLattice = { - OctaEdgeLattice: { + _initLatticeType: function(){ + require(['octaBaseplane'], function(OctaBasePlane){ + globals.basePlane = new OctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, - _initLatticeType: function(){ - require(['octaBaseplane'], function(OctaBasePlane){ - globals.basePlane = new OctaBasePlane(); - }); - require(['defaultHighlighter'], function(DefaultHighlighter){ - globals.highlighter = new DefaultHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - //todo finish this - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var yScale = 1/Math.sqrt(3); - var index = this._indexForPosition(absPosition); - if (index.z%3 == 1) { - absPosition.x -= this.xScale()/2; - absPosition.y += yScale/2; - } else if (index.z%3 == 2){ - absPosition.y += yScale; - } - var index = this._indexForPosition(absPosition); - return index; - }, + getIndexForPosition: function(absPosition){ + //todo finish this + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var yScale = 1/Math.sqrt(3); + var index = this._indexForPosition(absPosition); + if (index.z%3 == 1) { + absPosition.x -= this.xScale()/2; + absPosition.y += yScale/2; + } else if (index.z%3 == 2){ + absPosition.y += yScale; + } + var index = this._indexForPosition(absPosition); + return index; + }, - getPositionForIndex: function(index){ + getPositionForIndex: function(index){ - var position = _.clone(index); - var xScale = this.xScale(); - var yScale = 1/Math.sqrt(3); - position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale()+yScale/2; - position.z = (position.z+0.5)*this.zScale(); - if (index.y%2 != 0) position.x -= this.xScale()/2; - if (index.z%3 == 1) { - position.x += this.xScale()/2; - position.y -= yScale/2; - } else if (index.z%3 == 2){ - position.y -= yScale; - } - return position; - }, + var position = _.clone(index); + var xScale = this.xScale(); + var yScale = 1/Math.sqrt(3); + position.x = (position.x+1/2)*xScale; + position.y = position.y*this.yScale()+yScale/2; + position.z = (position.z+0.5)*this.zScale(); + if (index.y%2 != 0) position.x -= this.xScale()/2; + if (index.z%3 == 1) { + position.x += this.xScale()/2; + position.y -= yScale/2; + } else if (index.z%3 == 2){ + position.y -= yScale; + } + return position; + }, - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1+2*cellSeparation; - }, + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, - yScale: function(cellSeparation){ - return this.xScale(cellSeparation)/2*Math.sqrt(3); - }, + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); + }, - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return 2/Math.sqrt(6)+2*cellSeparation; - }, + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2/Math.sqrt(6)+2*cellSeparation; + }, - makeCellForLatticeType: function(indices){ - return new DMAEdgeOctaCell(indices); - }, + makeCellForLatticeType: function(indices){ + return new DMAEdgeOctaCell(indices); + }, - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaEdgeLattice), function(key){ - self[key] = null; - }); - } + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(OctaEdgeLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return OctaEdgeLattice; }); diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js index 1f256c4c5d2aac815c7cf827ee173e68f297835e..e47d010a058b2a7b9231caf1f0b371a35b99b25e 100644 --- a/js/lattice/OctaFaceLattice.js +++ b/js/lattice/OctaFaceLattice.js @@ -4,60 +4,59 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - OctaFaceLattice: { - - _initLatticeType: function(){ - require(['octaBaseplane'], function(OctaBasePlane){ - globals.basePlane = new OctaBasePlane(); - }); - require(['defaultHighlighter'], function(DefaultHighlighter){ - globals.highlighter = new DefaultHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var index = this._indexForPosition(absPosition); - if (index.z%2 == 1) index.y += 1; - return index; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - position.x = (position.x+1/2); - position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(); - if ((index.y%2) != 0) position.x -= this.xScale()/2; - return position; - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation)/2*Math.sqrt(3); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return 2/Math.sqrt(6)+2*cellSeparation; - }, - - makeCellForLatticeType: function(indices){ - return new OctaFaceCell(indices); - }, - - _undo: function(){//remove all the mixins - var self = this; - _.each(_.keys(this.OctaFaceLattice), function(key){ - self[key] = null; - }); - } + var OctaFaceLattice = { + + _initLatticeType: function(){ + require(['octaBaseplane'], function(OctaBasePlane){ + globals.basePlane = new OctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, + + getPositionForIndex: function(index){ + var position = _.clone(index); + position.x = (position.x+1/2); + position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; + position.z = (position.z+0.5)*this.zScale(); + if ((index.y%2) != 0) position.x -= this.xScale()/2; + return position; + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2/Math.sqrt(6)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices){ + return new OctaFaceCell(indices); + }, + + _undo: function(){//remove all the mixins + var self = this; + _.each(_.keys(OctaFaceLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return OctaFaceLattice; }); diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js index e2d6ab89cc5e68b98d6bb8535b19dd58054267a3..6beeea843cacaa3e17be72f05c0482cc0b3a2918 100644 --- a/js/lattice/OctaFreeFormFaceLattice.js +++ b/js/lattice/OctaFreeFormFaceLattice.js @@ -4,77 +4,76 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { + var OctaFreeFormFaceLattice = { - OctaFreeFormFaceLattice: { + _initLatticeType: function(){ + require(['octaBaseplane'], function(OctaBasePlane){ + globals.basePlane = new OctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + this.set("freeformCellType", "octa"); + }, - _initLatticeType: function(){ - require(['octaBaseplane'], function(OctaBasePlane){ - globals.basePlane = new OctaBasePlane(); - }); - require(['defaultHighlighter'], function(DefaultHighlighter){ - globals.highlighter = new DefaultHighlighter(); - }); - this.set("freeformCellType", "octa"); - }, + addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ + var cells = this.get("cells"); + cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, parentCellPos, parentCellOrient, direction, parentType, type)); + this.set("numCells", this.get("numCells")+1); + globals.three.render(); + }, - addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ - var cells = this.get("cells"); - cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, parentCellPos, parentCellOrient, direction, parentType, type)); - this.set("numCells", this.get("numCells")+1); - globals.three.render(); - }, - - makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){ - if (type){ - if (type == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); - return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); - } - if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); + makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){ + if (type){ + if (type == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); - }, + } + if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); + return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); + }, - getIndexForPosition: function(absPosition){//only used by baseplane - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var index = this._indexForPosition(absPosition); - if (index.z%2 == 1) index.y += 1; - return index; - }, + getIndexForPosition: function(absPosition){//only used by baseplane + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, - getPositionForIndex: function(index){//only used by baseplane - var position = _.clone(index); - var xScale = this.xScale(); - position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(); - if ((index.y%2) != 0) position.x -= xScale/2; - return position; - }, + getPositionForIndex: function(index){//only used by baseplane + var position = _.clone(index); + var xScale = this.xScale(); + position.x = (position.x+1/2)*xScale; + position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; + position.z = (position.z+0.5)*this.zScale(); + if ((index.y%2) != 0) position.x -= xScale/2; + return position; + }, - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1+2*cellSeparation; - }, + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, - yScale: function(cellSeparation){ - return this.xScale(cellSeparation)/2*Math.sqrt(3); - }, + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); + }, - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;//todo xy? - if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*cellSeparation; - return 2/Math.sqrt(24)+2*cellSeparation; - }, + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;//todo xy? + if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*cellSeparation; + return 2/Math.sqrt(24)+2*cellSeparation; + }, - _undo: function(){//remove all the mixins - var self = this; - this.set("freeformCellType", null);//todo get rid of this property - this.clearCells(); - _.each(_.keys(this.OctaFreeFormFaceLattice), function(key){ - self[key] = null; - }); - } + _undo: function(){//remove all the mixins + var self = this; + this.set("freeformCellType", null);//todo get rid of this property + this.clearCells(); + _.each(_.keys(OctaFreeFormFaceLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return OctaFreeFormFaceLattice; }); \ No newline at end of file diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js index 03fb634037a64e90fa3e2655e0a7a38b4b2c56ab..5abcec7830fcbb808c9fac0a5c91e6e83cf2cf78 100644 --- a/js/lattice/OctaRotEdgeLattice.js +++ b/js/lattice/OctaRotEdgeLattice.js @@ -4,63 +4,62 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { + var OctaRotEdgeLattice = { - OctaRotEdgeLattice: { + _initLatticeType: function(){ + require(['rotEdgeOctaBasePlane'], function(RotEdgeOctaBasePlane){ + globals.basePlane = new RotEdgeOctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, - _initLatticeType: function(){ - require(['rotEdgeOctaBasePlane'], function(RotEdgeOctaBasePlane){ - globals.basePlane = new RotEdgeOctaBasePlane(); - }); - require(['defaultHighlighter'], function(DefaultHighlighter){ - globals.highlighter = new DefaultHighlighter(); - }); - }, + getIndexForPosition: function(absPosition){ + var position = {}; + position.x = Math.floor(absPosition.x/this.xScale()+0.5); + position.y = Math.floor(absPosition.y/this.yScale()+0.5); + position.z = Math.floor(absPosition.z/this.zScale()+0.5); + return position; + }, - getIndexForPosition: function(absPosition){ - var position = {}; - position.x = Math.floor(absPosition.x/this.xScale()+0.5); - position.y = Math.floor(absPosition.y/this.yScale()+0.5); - position.z = Math.floor(absPosition.z/this.zScale()+0.5); - return position; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - if (index.z %2 != 0){ - position.x += 0.5; - position.y += 0.5; - } - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+1)*this.zScale(); - return position; - }, + getPositionForIndex: function(index){ + var position = _.clone(index); + if (index.z %2 != 0){ + position.x += 0.5; + position.y += 0.5; + } + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+1)*this.zScale(); + return position; + }, - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return 1 + 2*cellSeparation; - }, + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1 + 2*cellSeparation; + }, - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return Math.sqrt(2)/2 + 2*cellSeparation; - }, + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)/2 + 2*cellSeparation; + }, - makeCellForLatticeType: function(indices){ - return new OctaRotEdgeCell(indices); - }, + makeCellForLatticeType: function(indices){ + return new OctaRotEdgeCell(indices); + }, - _undo: function(){//remove all the mixins - var self = this; - _.each(_.keys(this.OctaRotEdgeLattice), function(key){ - self[key] = null; - }); - } + _undo: function(){//remove all the mixins + var self = this; + _.each(_.keys(OctaRotEdgeLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return OctaRotEdgeLattice; }); diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js index 628aa0e58a301fc31d249440417c160577032f90..fe6b85ff54404e2e831019a484918aeea2bfb7b7 100644 --- a/js/lattice/OctaVertexLattice.js +++ b/js/lattice/OctaVertexLattice.js @@ -4,59 +4,58 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - OctaVertexLattice: { - - _initLatticeType: function(){ - require(['squareBaseplane'], function(SquareBasePlane){ - globals.basePlane = new SquareBasePlane(); - }); - require(['defaultHighlighter'], function(DefaultHighlighter){ - globals.highlighter = new DefaultHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - var position = {}; - position.x = Math.floor(absPosition.x/this.xScale()+0.5); - position.y = Math.floor(absPosition.y/this.yScale()+0.5); - position.z = Math.floor(absPosition.z/this.zScale()+0.5); - return position; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+0.5)*this.zScale(); - return position; - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return Math.sqrt(2)+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return Math.sqrt(2)+2*cellSeparation; - }, - - makeCellForLatticeType: function(indices){ - return new OctaVertexCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaVertexLattice), function(key){ - self[key] = null; - }); - } + var OctaVertexLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + var position = {}; + position.x = Math.floor(absPosition.x/this.xScale()+0.5); + position.y = Math.floor(absPosition.y/this.yScale()+0.5); + position.z = Math.floor(absPosition.z/this.zScale()+0.5); + return position; + }, + + getPositionForIndex: function(index){ + var position = _.clone(index); + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+0.5)*this.zScale(); + return position; + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return Math.sqrt(2)+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices){ + return new OctaVertexCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(OctaVertexLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return OctaVertexLattice; }); diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js index 798a82ca055b41d1002f47ff16a4d51630b087fe..c628651a9d654da570c5a86ba219b9f706cef575 100644 --- a/js/lattice/TruncatedCubeLattice.js +++ b/js/lattice/TruncatedCubeLattice.js @@ -5,51 +5,50 @@ define(['lattice', 'globals'], function(lattice, globals){ - _.extend(lattice, { - - TruncatedCubeLattice: { - - _initLatticeType: function(){ - require(['squareBaseplane'], function(SquareBasePlane){ - globals.basePlane = new SquareBasePlane(); - }); - require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){ - globals.highlighter = new TruncatedCubeHighlighter(); - }); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; - return Math.sqrt(2)+2*cellSeparation; - }, - - yScale: function(cellSeparation){ - return this.xScale(cellSeparation); - }, - - zScale: function(cellSeparation){ - if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; - return Math.sqrt(2)+2*cellSeparation; - }, - - makeCellForLatticeType: function(indices){ - return new TruncatedCubeCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.TruncatedCubeLattice), function(key){ - self[key] = null; - }); - } + var TruncatedCubeLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){ + globals.highlighter = new TruncatedCubeHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return Math.sqrt(2)+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices){ + return new TruncatedCubeCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(TruncatedCubeLattice), function(key){ + self[key] = null; + }); } - }); + }; + + return TruncatedCubeLattice; }); diff --git a/js/main.js b/js/main.js index 4516b059d1bbb092cfe24bd5764e12cda575e83a..f6230a6ca8956e65547ac41e70d4ab24b007e0da 100644 --- a/js/main.js +++ b/js/main.js @@ -25,6 +25,15 @@ require.config({ //lattice lattice: 'lattice/Lattice', + cubeLattice: 'lattice/CubeLattice', + gikLattice: 'lattice/GIKLattice', + kelvinLattice: 'lattice/KelvinLattice', + octaEdgeLattice: 'lattice/OctaEdgeLattice', + octaFaceLattice: 'lattice/OctaFaceLattice', + octaFreeFormFaceLattice: 'lattice/OctaFreeFormFaceLattice', + octaRotEdgeLattice: 'lattice/OctaRotEdgeLattice', + octavertexLattice: 'lattice/OctaVertexLattice', + truncatedCubeLattice: 'lattice/TruncatedCubeLattice', //baseplane baseplane: 'baseplane/BasePlane',