From 01156a5819aac634abded163b7047adc907bc6ef Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 10 Jun 2015 14:53:24 -0700 Subject: [PATCH] octa base plane refactor --- js/baseplane/OctaBasePlane.js | 8 +++-- js/lattice/OctaEdgeLattice.js | 59 +++++++++++++++++++------------ js/lattice/OctaFaceLattice.js | 12 +++---- js/lattice/TetraStackedLattice.js | 12 +++---- 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/js/baseplane/OctaBasePlane.js b/js/baseplane/OctaBasePlane.js index 0e58993e..93740571 100644 --- a/js/baseplane/OctaBasePlane.js +++ b/js/baseplane/OctaBasePlane.js @@ -65,6 +65,8 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', var pointVertOffset = 2*baseVertOffset; var horizontalOffset = xySep; + var yOffset = 1/Math.sqrt(3)/2; + for (var j=-dimX;j<=dimX;j++){ for (var i=-dimY;i<=dimY;i++){ @@ -73,9 +75,9 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', xOffset = 1/2*xScale; } - vertices.push(new THREE.Vector3(i*xScale + xOffset - horizontalOffset, j*yScale + baseVertOffset, 0)); - vertices.push(new THREE.Vector3(i*xScale + xOffset + horizontalOffset, j*yScale + baseVertOffset, 0)); - vertices.push(new THREE.Vector3(i*xScale + xOffset, j*yScale - pointVertOffset, 0)); + vertices.push(new THREE.Vector3(i*xScale + xOffset - horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0)); + vertices.push(new THREE.Vector3(i*xScale + xOffset + horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0)); + vertices.push(new THREE.Vector3(i*xScale + xOffset - xScale/2, j*yScale - pointVertOffset - yOffset, 0)); } diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js index 517ff6aa..1c80e60e 100644 --- a/js/lattice/OctaEdgeLattice.js +++ b/js/lattice/OctaEdgeLattice.js @@ -17,36 +17,51 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, getIndexForPosition: function(absPosition){ - 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; + if (index.y%2 != 0) { + absPosition.x += this.xScale()/2; + index = this._indexForPosition(absPosition); } - return this._indexForPosition(absPosition); + return index; }, getPositionForIndex: function(index){ - var position = index.clone(); - 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; - } + var position = this._positionForIndex(index); + if ((index.y%2) != 0) position.x -= this.xScale()/2; return position; }, +// getIndexForPosition: function(absPosition){ +// 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; +// } +// return this._indexForPosition(absPosition); +// }, +// +// getPositionForIndex: function(index){ +// var position = index.clone(); +// 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; diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js index 2aa1d1fe..5cc6b5d5 100644 --- a/js/lattice/OctaFaceLattice.js +++ b/js/lattice/OctaFaceLattice.js @@ -17,18 +17,16 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, 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; + if (index.y%2 != 0) { + absPosition.x += this.xScale()/2; + index = this._indexForPosition(absPosition); + } return index; }, getPositionForIndex: function(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(); + var position = this._positionForIndex(index); if ((index.y%2) != 0) position.x -= this.xScale()/2; return position; }, diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/TetraStackedLattice.js index 4bea1a01..9cdbc6d0 100644 --- a/js/lattice/TetraStackedLattice.js +++ b/js/lattice/TetraStackedLattice.js @@ -17,18 +17,16 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, 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; + if (index.y%2 != 0) { + absPosition.x += this.xScale()/2; + index = this._indexForPosition(absPosition); + } return index; }, getPositionForIndex: function(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(); + var position = this._positionForIndex(index); if ((index.y%2) != 0) position.x -= this.xScale()/2; return position; }, -- GitLab