From e8bb0f0597837a17698438ff0eaf903944ac77da Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 5 Jun 2015 22:05:55 -0700
Subject: [PATCH] eod

---
 js/cells/TetraEdgeCell.js        | 17 ----------------
 js/cells/TetraVertexCell.js      | 35 ++++++++++++++++++++++++++++++++
 js/lattice/TetraVertexLattice.js | 20 ++++++++++++------
 js/main.js                       |  2 +-
 4 files changed, 50 insertions(+), 24 deletions(-)
 delete mode 100644 js/cells/TetraEdgeCell.js
 create mode 100644 js/cells/TetraVertexCell.js

diff --git a/js/cells/TetraEdgeCell.js b/js/cells/TetraEdgeCell.js
deleted file mode 100644
index c40fb191..00000000
--- a/js/cells/TetraEdgeCell.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Created by aghassaei on 5/26/15.
- */
-
-
-define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'TetraStackedCell'],
-    function(_, THREE, three, lattice, appState, TetraFaceCell){
-    
-    function TetraEdgeCell(index, superCell){
-        TetraFaceCell.call(this, index, superCell);
-    }
-    TetraEdgeCell.prototype = Object.create(TetraFaceCell.prototype);
-    
-    TetraEdgeCell.prototype._rotateCell = function(){};
-    
-    return TetraEdgeCell;
-});
\ No newline at end of file
diff --git a/js/cells/TetraVertexCell.js b/js/cells/TetraVertexCell.js
new file mode 100644
index 00000000..8a9c392c
--- /dev/null
+++ b/js/cells/TetraVertexCell.js
@@ -0,0 +1,35 @@
+/**
+ * Created by aghassaei on 6/5/15.
+ */
+
+
+define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
+    function(_, THREE, three, lattice, appState, DMACell){
+
+    var unitGeo = new THREE.TetrahedronGeometry(Math.sqrt(3/8));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-2/Math.sqrt(6)));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
+
+    function TetraStackedCell(index, superCell){
+        DMACell.call(this, index, superCell);
+    }
+    TetraStackedCell.prototype = Object.create(DMACell.prototype);
+
+    TetraStackedCell.prototype._getGeometry = function(){//abstract mesh representation of cell
+        return unitGeo;
+    };
+
+    TetraStackedCell.prototype.calcHighlighterParams = function(face){
+        var direction = face.normal;
+        if (direction.z<-0.95) direction = new THREE.Vector3(0,0,-1);
+        else direction = new THREE.Vector3(0,0,1);
+        direction.applyQuaternion(this.getAbsoluteOrientation());
+        var position = this.getAbsolutePosition();
+        position.z += direction.z*this.zScale()/2;
+        return {position:position, direction: direction};
+    };
+
+    return TetraStackedCell;
+});
\ No newline at end of file
diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/TetraVertexLattice.js
index d142e840..e04a7a83 100644
--- a/js/lattice/TetraVertexLattice.js
+++ b/js/lattice/TetraVertexLattice.js
@@ -1,8 +1,7 @@
 /**
- * Created by aghassaei on 6/5/15.
+ * Created by aghassaei on 6/4/15.
  */
 
-
 define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'],
     function(_, Backbone, appState, lattice, globals, plist, THREE, three){
 
@@ -18,11 +17,20 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
         },
 
         getIndexForPosition: function(absPosition){
-            return this._indexForPosition(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){
-            return this._positionForIndex(index);
+            var position = index.clone();
+            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){
@@ -40,7 +48,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
         },
 
         makeCellForLatticeType: function(indices, callback){
-            require(['tetraStackedCell'], function(TetraVertexCell){
+            require(['tetraVertexCell'], function(TetraVertexCell){
                 var cell = new TetraVertexCell(indices);
                 if (callback) callback(cell);
                 return cell;
@@ -56,4 +64,4 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
     };
 
     return TetraVertexLattice;
-});
\ No newline at end of file
+});
diff --git a/js/main.js b/js/main.js
index 88ac5176..f64da74f 100644
--- a/js/main.js
+++ b/js/main.js
@@ -59,7 +59,7 @@ require.config({
         octaVertexCell: 'cells/OctaVertexCell',
         octaRotEdgeCell: 'cells/OctaRotEdgeCell',
         tetraStackedCell: 'cells/TetraStackedCell',
-        tetraFaceCell: 'cells/TetraFaceCell',
+        tetraVertexCell: 'cells/TetraVertexCell',
         truncatedCubeCell: 'cells/TruncatedCubeCell',
         kelvinCell: 'cells/KelvinCell',
         cubeCell: 'cells/CubeCell',
-- 
GitLab