Skip to content
Snippets Groups Projects
Select Git revision
  • master default
  • dev
2 results

TetraVertexLattice.js

Blame
  • TetraVertexLattice.js 2.27 KiB
    /**
     * Created by aghassaei on 6/4/15.
     */
    
    define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'],
        function(_, Backbone, appState, lattice, globals, plist, THREE, three){
    
        var TetraVertexLattice = {
    
            _initLatticeType: function(){
                require(['octaBaseplane'], function(OctaBasePlane){
                    globals.basePlane = new OctaBasePlane();
                });
                require(['defaultHighlighter'], function(DefaultHighlighter){
                    globals.highlighter = new DefaultHighlighter();
                });
            },
    
            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 = 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){
                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
                return 1+2*cellSeparation;
            },
    
            yScale: function(cellSeparation){
                return this.xScale(cellSeparation)/2*Math.sqrt(3);
            },
    
            zScale: function(cellSeparation){
                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
                return 2/Math.sqrt(6)+2*cellSeparation;
            },
    
            makeCellForLatticeType: function(indices, callback){
                require(['tetraVertexCell'], function(TetraVertexCell){
                    var cell = new TetraVertexCell(indices);
                    if (callback) callback(cell);
                });
            },
    
            _undo: function(){//remove all the mixins, this will help with debugging later
                var self = this;
                _.each(_.keys(TetraVertexLattice), function(key){
                    self[key] = null;
                });
            }
        };
    
        return TetraVertexLattice;
    });