From c22573b1e12747d27ff62ce68e9a017381cf3cb4 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 2 Jun 2015 19:22:08 -0700 Subject: [PATCH] lattice --- js/lattice/CubeLattice.js | 91 ++++++++++--------- js/lattice/GIKLattice.js | 93 ++++++++++--------- js/lattice/KelvinLattice.js | 92 +++++++++---------- js/lattice/Lattice.js | 49 +++++----- js/lattice/OctaEdgeLattice.js | 125 +++++++++++++------------- js/lattice/OctaFaceLattice.js | 109 +++++++++++----------- js/lattice/OctaFreeFormFaceLattice.js | 123 +++++++++++++------------ js/lattice/OctaRotEdgeLattice.js | 99 ++++++++++---------- js/lattice/OctaVertexLattice.js | 107 +++++++++++----------- js/lattice/TruncatedCubeLattice.js | 91 ++++++++++--------- js/main.js | 9 ++ 11 files changed, 499 insertions(+), 489 deletions(-) diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index 91e5decf..59bcf25f 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 a8bf98df..352333cb 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 7a872cbe..56cc2d04 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 1c6802d5..641ed806 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 62b6a02e..49957abc 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 1f256c4c..e47d010a 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 e2d6ab89..6beeea84 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 03fb6340..5abcec78 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 628aa0e5..fe6b85ff 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 798a82ca..c628651a 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 4516b059..f6230a6c 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', -- GitLab