Skip to content
Snippets Groups Projects
Commit 68fa9569 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

closer

parent faf1109d
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ Lattice = Backbone.Model.extend({ ...@@ -10,7 +10,7 @@ Lattice = Backbone.Model.extend({
cellType: "octa", cellType: "octa",
connectionType: "face", connectionType: "face",
nodes: [], nodes: [],
cells: [[[]]],//3D matrix containing all cells and null, dynamic cells: [[[null]]],//3D matrix containing all cells and null, dynamic
cellsMin: {x:0, y:0, z:0},//min position of cells matrix cellsMin: {x:0, y:0, z:0},//min position of cells matrix
cellsMax: {x:0, y:0, z:0},//min position of cells matrix cellsMax: {x:0, y:0, z:0},//min position of cells matrix
numCells: 0, numCells: 0,
...@@ -38,18 +38,20 @@ Lattice = Backbone.Model.extend({ ...@@ -38,18 +38,20 @@ Lattice = Backbone.Model.extend({
position.x = Math.round(absPosition.x/scale); position.x = Math.round(absPosition.x/scale);
position.y = Math.round(absPosition.y/triHeight); position.y = Math.round(absPosition.y/triHeight);
position.z = Math.round(absPosition.z/octHeight); position.z = Math.round(absPosition.z/octHeight);
if (position.z%2 == 1) position.y += 1;
//check for matrix expansion //check for matrix expansion
var lastMax = this.get("cellsMax"); var lastMax = this.get("cellsMax");
var lastMin = this.get("cellsMin"); var lastMin = this.get("cellsMin");
var newMax = this._updateCellsMax(position, lastMax); var newMax = this._updateCellsMax(position, lastMax);
var newMin = this._updateCellsMin(position, lastMin); var newMin = this._updateCellsMin(position, lastMin);
console.log(position);
if (newMax) { if (newMax) {
this._expandCellsArray(cells, this._subtract(newMax, lastMin), false); this._expandCellsArray(cells, this._subtract(newMax, lastMax), false);
this.set("cellsMax", newMax); this.set("cellsMax", newMax);
} }
if (newMin) { if (newMin) {
this._expandCellsArray(cells, this._subtract(newMin, lastMin), true); this._expandCellsArray(cells, this._subtract(lastMin, newMin), true);
this.set("cellsMin", newMin); this.set("cellsMin", newMin);
} }
...@@ -63,12 +65,14 @@ Lattice = Backbone.Model.extend({ ...@@ -63,12 +65,14 @@ Lattice = Backbone.Model.extend({
_expandCellsArray: function(cells, expansion, fromFront){ _expandCellsArray: function(cells, expansion, fromFront){
console.log(expansion);
_.each(_.keys(expansion), function(key){ _.each(_.keys(expansion), function(key){
if (expansion[key] == 0) return;//no expansion on this axis if (expansion[key] == 0) return;//no expansion on this axis
var cellsX = cells.length; var cellsX = cells.length;
var cellsY = cellsX > 0 ? 0 : cells[0].length; var cellsY = cellsX > 0 ? 1 : cells[0].length;
var cellsZ = cellsY > 0 ? 0 : cells[0][0].length; var cellsZ = cellsY > 0 ? 1 : cells[0][0].length;
if (key=="x"){ if (key=="x"){
for (var x=0;x<expansion[key];x++){ for (var x=0;x<expansion[key];x++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment