From f879662486ea732626ac0cd433da56c059532e1c Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 26 May 2015 09:34:42 -0700
Subject: [PATCH] moving stuff around

---
 index.html                            |  14 ++--
 js/{fea => cell}/DMACellFreeform.js   |   0
 js/{fea => cell}/DMASuperCell.js      |   0
 js/{fea => cell}/DmaCell.js           |   0
 js/{fea => cell}/DmaCellOcta.js       |   0
 js/{fea => cell}/DmaCellOther.js      |   0
 js/{fea => cell}/DmaCellTetra.js      |   0
 js/lattice/CubeLattice.js             |  46 ++++++++++++
 js/lattice/GIKLattice.js              | 102 ++++++++++++++++++++++++++
 js/lattice/KelvinLattice.js           |  46 ++++++++++++
 js/{models => lattice}/Lattice.js     |   0
 js/lattice/OctaEdgeLattice.js         |  64 ++++++++++++++++
 js/lattice/OctaFaceLattice.js         |  54 ++++++++++++++
 js/lattice/OctaFreeFormFaceLattice.js |  74 +++++++++++++++++++
 js/lattice/OctaRotEdgeLattice.js      |  58 +++++++++++++++
 js/lattice/OctaVertexLattice.js       |  54 ++++++++++++++
 js/lattice/TruncatedCubeLattice.js    |  46 ++++++++++++
 js/main.js                            |   2 +
 18 files changed, 553 insertions(+), 7 deletions(-)
 rename js/{fea => cell}/DMACellFreeform.js (100%)
 rename js/{fea => cell}/DMASuperCell.js (100%)
 rename js/{fea => cell}/DmaCell.js (100%)
 rename js/{fea => cell}/DmaCellOcta.js (100%)
 rename js/{fea => cell}/DmaCellOther.js (100%)
 rename js/{fea => cell}/DmaCellTetra.js (100%)
 create mode 100644 js/lattice/CubeLattice.js
 create mode 100644 js/lattice/GIKLattice.js
 create mode 100644 js/lattice/KelvinLattice.js
 rename js/{models => lattice}/Lattice.js (100%)
 create mode 100644 js/lattice/OctaEdgeLattice.js
 create mode 100644 js/lattice/OctaFaceLattice.js
 create mode 100644 js/lattice/OctaFreeFormFaceLattice.js
 create mode 100644 js/lattice/OctaRotEdgeLattice.js
 create mode 100644 js/lattice/OctaVertexLattice.js
 create mode 100644 js/lattice/TruncatedCubeLattice.js

diff --git a/index.html b/index.html
index 77598d4a..906f0c29 100644
--- a/index.html
+++ b/index.html
@@ -43,19 +43,19 @@
     <!--fea stuff-->
     <script src="js/fea/DmaNode.js"></script>
     <script src="js/fea/DmaBeam.js"></script>
-    <script src="js/fea/DmaCell.js"></script>
-    <script src="js/fea/DMASuperCell.js"></script>
-    <script src="js/fea/DMACellFreeform.js"></script>
-    <script src="js/fea/DmaCellOcta.js"></script>
-    <script src="js/fea/DmaCellTetra.js"></script>
-    <script src="js/fea/DmaCellOther.js"></script>
+    <script src="js/cell/DmaCell.js"></script>
+    <script src="js/cell/DMASuperCell.js"></script>
+    <script src="js/cell/DMACellFreeform.js"></script>
+    <script src="js/cell/DmaCellOcta.js"></script>
+    <script src="js/cell/DmaCellTetra.js"></script>
+    <script src="js/cell/DmaCellOther.js"></script>
     <script src="js/fea/DmaPart.js"></script>
 
     <!--models-->
     <script src="js/models/ThreeModel.js"></script>
     <script src="js/models/LatticeOcta.js"></script>
     <script src="js/models/LatticeOther.js"></script>
-    <script src="js/models/Lattice.js"></script>
+    <script src="js/lattice/Lattice.js"></script>
     <script src="js/models/FillGeometry.js"></script>
     <script src="js/models/BasePlane.js"></script>
     <script src="js/models/extrudeVisualizer.js"></script>
diff --git a/js/fea/DMACellFreeform.js b/js/cell/DMACellFreeform.js
similarity index 100%
rename from js/fea/DMACellFreeform.js
rename to js/cell/DMACellFreeform.js
diff --git a/js/fea/DMASuperCell.js b/js/cell/DMASuperCell.js
similarity index 100%
rename from js/fea/DMASuperCell.js
rename to js/cell/DMASuperCell.js
diff --git a/js/fea/DmaCell.js b/js/cell/DmaCell.js
similarity index 100%
rename from js/fea/DmaCell.js
rename to js/cell/DmaCell.js
diff --git a/js/fea/DmaCellOcta.js b/js/cell/DmaCellOcta.js
similarity index 100%
rename from js/fea/DmaCellOcta.js
rename to js/cell/DmaCellOcta.js
diff --git a/js/fea/DmaCellOther.js b/js/cell/DmaCellOther.js
similarity index 100%
rename from js/fea/DmaCellOther.js
rename to js/cell/DmaCellOther.js
diff --git a/js/fea/DmaCellTetra.js b/js/cell/DmaCellTetra.js
similarity index 100%
rename from js/fea/DmaCellTetra.js
rename to js/cell/DmaCellTetra.js
diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js
new file mode 100644
index 00000000..e9db2e0a
--- /dev/null
+++ b/js/lattice/CubeLattice.js
@@ -0,0 +1,46 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    CubeLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new CubeHighlighter();
+        },
+
+        getIndexForPosition: function(absPosition){
+            return this._indexForPosition(absPosition);
+        },
+
+        getPositionForIndex: function(index){
+            return this._positionForIndex(index);
+        },
+
+        xScale: function(){
+            return 1+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return 1+2*this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMACubeCell(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;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js
new file mode 100644
index 00000000..d2182bbd
--- /dev/null
+++ b/js/lattice/GIKLattice.js
@@ -0,0 +1,102 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    GIKLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new GIKHighlighter();
+        },
+
+        getIndexForPosition: function(absPosition){
+            return this._indexForPosition(absPosition);
+        },
+
+        getPositionForIndex: function(index){
+            return this._positionForIndex(index);
+        },
+
+        xScale: function(){
+            return 1+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return 1.28*(1+2*this.get("cellSeparation").z);
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMAGIKCell(indices);
+        },
+
+        makeSuperCell: function(range){
+            var length = this.get("gikLength");
+            var cells;
+            if (range) cells = this.addCellsInRange(range);
+            else {
+                cells = [];
+                for (var i=0;i<length;i++){
+                    cells.push(this.makeCellForLatticeType(null));
+                }
+            }
+            if (cells.length < 1) return null;
+            var superCell = new DMASuperCell(length, range, cells);
+            _.each(cells, function(cell, index){
+                cell.setSuperCell(superCell, index);
+            });
+            return superCell;
+        },
+
+        _rasterGikCells: function(order, callback, var1, var2, var3, cells){
+            for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){
+                for (var j=this._getRasterLoopInit(var2);this._getRasterLoopCondition(j,var2);j+=this._getRasterLoopIterator(var2)){
+                    for (var k=this._getRasterLoopInit(var3);this._getRasterLoopCondition(k,var3);k+=this._getRasterLoopIterator(var3)){
+                        var numToSkip = {x:0,y:0};
+                        if (var1.order == 0){
+                            if (var2.order == 1) numToSkip = this._doSuperCellCallback(cells, i, j, k, callback);
+                            else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, i, k, j, callback);
+                        } else if (var1.order == 1){
+                            if (var2.order == 0) numToSkip = this._doSuperCellCallback(cells, j, i, k, callback);
+                            else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, k, i, j, callback);
+                        } else {
+                            if (var2.order == 0) {
+                                numToSkip = this._doSuperCellCallback(cells, j, k, i, callback);
+                            }
+                            else if (var2.order == 1) {
+                                numToSkip = this._doSuperCellCallback(cells, k, j, i, callback);
+                            }
+                        }
+
+                    }
+                }
+            }
+        },
+
+        _doSuperCellCallback: function(cells, x, y, z, callback){
+            var cell = cells[x][y][z];
+            if (z%2 != 0) cell = cells[y][x][z];
+            if (!cell) {
+                callback(null, x, y, z);
+                return {x:0,y:0};
+            }
+            var superCell = cell.superCell;
+            callback(superCell, x, y, z);
+            if (z%2 != 0) return {x:0, y:superCell.getLength()};
+            return {x:superCell.getLength(), y:0};
+        },
+
+        _undo: function(){//remove all the mixins, this will help with debugging later
+            var self = this;
+            _.each(_.keys(this.GIKLattice), function(key){
+                self[key] = null;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js
new file mode 100644
index 00000000..b98be46d
--- /dev/null
+++ b/js/lattice/KelvinLattice.js
@@ -0,0 +1,46 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    KelvinLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new TruncatedCubeHighlighter();
+        },
+
+        getIndexForPosition: function(absPosition){
+            return this._indexForPosition(absPosition);
+        },
+
+        getPositionForIndex: function(index){
+            return this._positionForIndex(index);
+        },
+
+        xScale: function(){
+            return 2*Math.sqrt(2)+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return 2*Math.sqrt(2)+2*this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMATruncOctaCell(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;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/models/Lattice.js b/js/lattice/Lattice.js
similarity index 100%
rename from js/models/Lattice.js
rename to js/lattice/Lattice.js
diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js
new file mode 100644
index 00000000..0d1b73e2
--- /dev/null
+++ b/js/lattice/OctaEdgeLattice.js
@@ -0,0 +1,64 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    OctaEdgeLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaEdgeHighlighter();
+
+        },
+
+        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){
+
+            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;
+        },
+
+        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;
+            });
+            _.each(_.keys(this.OctaFaceLattice), function(key){
+                self[key] = null;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js
new file mode 100644
index 00000000..a10acb09
--- /dev/null
+++ b/js/lattice/OctaFaceLattice.js
@@ -0,0 +1,54 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+_.extend(Lattice, {
+
+    OctaFaceLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaFaceHighlighter();
+        },
+
+        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(){
+            return 1+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale()/2*Math.sqrt(3);
+        },
+
+        zScale: function(){
+            return 2/Math.sqrt(6)+2*this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMAFaceOctaCell(indices);
+        },
+
+        _undo: function(){//remove all the mixins
+            var self = this;
+            _.each(_.keys(this.OctaFaceLattice), function(key){
+                self[key] = null;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js
new file mode 100644
index 00000000..acc7ab9e
--- /dev/null
+++ b/js/lattice/OctaFreeFormFaceLattice.js
@@ -0,0 +1,74 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    OctaFreeFormFaceLattice: {
+
+         _initLatticeType: function(){
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaFreeFormHighlighter();
+
+            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();
+        },
+
+        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;
+        },
+
+        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(){
+            return 1+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale()/2*Math.sqrt(3);
+        },
+
+        zScale: function(){
+            if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*this.get("cellSeparation").xy;
+            return 2/Math.sqrt(24)+2*this.get("cellSeparation").xy;
+        },
+
+        _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;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js
new file mode 100644
index 00000000..ad0d4759
--- /dev/null
+++ b/js/lattice/OctaRotEdgeLattice.js
@@ -0,0 +1,58 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    OctaRotEdgeLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new RotEdgeOctaBasePlane();
+            globals.highlighter = new OctaVertexHighlighter();
+        },
+
+        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;
+        },
+
+        xScale: function(){
+            return 1 + 2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return Math.sqrt(2)/2 + 2*this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMARotatedEdgeCell(indices);
+        },
+
+        _undo: function(){//remove all the mixins
+            var self = this;
+            _.each(_.keys(this.OctaRotEdgeLattice), function(key){
+                self[key] = null;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js
new file mode 100644
index 00000000..a0a2ac39
--- /dev/null
+++ b/js/lattice/OctaVertexLattice.js
@@ -0,0 +1,54 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    OctaVertexLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new OctaVertexHighlighter();
+        },
+
+        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(){
+            return Math.sqrt(2)+this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return Math.sqrt(2)+this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMAVertexOctaCell(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;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js
new file mode 100644
index 00000000..e81739bc
--- /dev/null
+++ b/js/lattice/TruncatedCubeLattice.js
@@ -0,0 +1,46 @@
+/**
+ * Created by aghassaei on 5/26/15.
+ */
+
+
+_.extend(Lattice, {
+
+    TruncatedCubeLattice: {
+
+        _initLatticeType: function(){
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new TruncatedCubeHighlighter();
+        },
+
+        getIndexForPosition: function(absPosition){
+            return this._indexForPosition(absPosition);
+        },
+
+        getPositionForIndex: function(index){
+            return this._positionForIndex(index);
+        },
+
+        xScale: function(){
+            return Math.sqrt(2)+2*this.get("cellSeparation").xy;
+        },
+
+        yScale: function(){
+            return this.xScale();
+        },
+
+        zScale: function(){
+            return Math.sqrt(2)+2*this.get("cellSeparation").z;
+        },
+
+        makeCellForLatticeType: function(indices){
+            return new DMATruncCubeCell(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;
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/js/main.js b/js/main.js
index 1f2a48e7..c6507724 100644
--- a/js/main.js
+++ b/js/main.js
@@ -29,4 +29,6 @@ $(function(){
     new ThreeView({model:globals.three});
 
     if (globals.lattice.get("connectionType") != "gik") globals.lattice.addCellAtIndex({x:0,y:0,z:0});//add a cell
+
+//    return {globals:globals};
 });
-- 
GitLab