From 8d6fc42a68d1d3b3e3870fbe38fed1797dcc8baa Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 4 Feb 2015 00:28:35 -0500
Subject: [PATCH] lattice subclassing

---
 js/main.js           | 10 +++---
 js/models/Lattice.js | 75 +++++++++++++++++++++++++++++++-------------
 2 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/js/main.js b/js/main.js
index 2e38b74e..c88cfa2a 100644
--- a/js/main.js
+++ b/js/main.js
@@ -10,15 +10,15 @@ $(function(){
 
     //init threeJS and geometry models
     window.three = new ThreeModel();
-    var lattice = new Lattice();
+    window.lattice = new OctaFaceLattice();
 
     //setup ui
-    var appState = new AppState({lattice:lattice});
-    new MenuWrapper({lattice:lattice, model:appState});
+    var appState = new AppState({lattice:window.lattice});
+    new MenuWrapper({lattice:window.lattice, model:appState});
     new NavBar({model:appState});
 
     //threeJS View
-    new ThreeView({model:window.three, lattice:lattice, appState:appState});
+    new ThreeView({model:window.three, lattice:window.lattice, appState:appState});
 
-    lattice.addCellAtIndex({x:0,y:0,z:0});
+    window.lattice.addCellAtIndex({x:0,y:0,z:0});
 });
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 72d5616f..b3d9e3b1 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -53,27 +53,21 @@ Lattice = Backbone.Model.extend({
     ///////////////////////////////ADD/REMOVE CELLS/////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////
 
-    addCellAtPosition: function(absPosition){
+    addCellAtIndex: function(indices){
 
-        //calc indices in cell matrix
         var scale = this.get("scale");
-        var octHeight = 2*scale/Math.sqrt(6);
-        var triHeight = scale/2*Math.sqrt(3);
-        var position = {};
-        position.x = Math.round(absPosition.x/scale);
-        position.y = Math.round(absPosition.y/triHeight);
-        position.z = Math.round(absPosition.z/octHeight);
-        if (position.z%2 == 1) position.y += 1;
+        var cells = this.get("cells");
+        this._checkForMatrixExpansion(cells, indices);
 
-        this.addCellAtIndex(position);
+        var index = this._subtract(indices, this.get("cellsMin"));
+        if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = this._makeCellForLatticeType(indices, scale);
+        else console.warn("already a cell there");
+        this.set("numCells", this.get("numCells")+1);
+        window.three.render();
     },
 
-    addCellAtIndex: function(indices){
-
-        var cells = this.get("cells");
-        var scale = this.get("scale");
+    _checkForMatrixExpansion: function(cells, indices){
 
-        //check for matrix expansion
         var lastMax = this.get("cellsMax");
         var lastMin = this.get("cellsMin");
         var newMax = this._updateCellsMax(indices, lastMax);
@@ -86,12 +80,6 @@ Lattice = Backbone.Model.extend({
             this._expandCellsArray(cells, this._subtract(lastMin, newMin), true);
             this.set("cellsMin", newMin);
         }
-
-        var index = this._subtract(indices, this.get("cellsMin"));
-        if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = new DMASideOctaCell(this.get("cellMode"), indices, scale, this);
-        else console.warn("already a cell there");
-        this.set("numCells", this.get("numCells")+1);
-        window.three.render();
     },
 
     removeCell: function(cell){
@@ -253,4 +241,47 @@ Lattice = Backbone.Model.extend({
         });
     }
 
-});
\ No newline at end of file
+});
+
+
+////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////FACE CONN OCTA LATTICE////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+
+
+OctaFaceLattice = Lattice.extend({
+
+    addCellAtPosition: function(absPosition){
+
+        //calc indices in cell matrix
+        var scale = this.get("scale");
+        var octHeight = 2*scale/Math.sqrt(6);
+        var triHeight = scale/2*Math.sqrt(3);
+        var position = {};
+        position.x = Math.round(absPosition.x/scale);
+        position.y = Math.round(absPosition.y/triHeight);
+        position.z = Math.round(absPosition.z/octHeight);
+        if (position.z%2 == 1) position.y += 1;
+
+        this.addCellAtIndex(position);
+    },
+
+    _makeCellForLatticeType: function(indices, scale){
+        return new DMASideOctaCell(this.get("cellMode"), indices, scale, this);
+    }
+
+});
+
+////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////EDGE CONN OCTA LATTICE////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////VERTEX CONN OCTA LATTICE//////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////CUBE LATTICE//////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
-- 
GitLab