Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Created April 24, 2013 02:06
Show Gist options
  • Save AlphaGit/5449057 to your computer and use it in GitHub Desktop.
Save AlphaGit/5449057 to your computer and use it in GitHub Desktop.
// helper: grid calculator for coordinate system
function GridCalculator(realHeight, realWidth, numColumns, numRows) {
var self = this;
self.numColumns = numColumns;
self.numRows = numRows;
var getNumRows = function() {
return self.numRows;
}
var getNumColumns = function() {
return self.numColumns;
}
var getBlockWidth = function() {
return realWidth / numColumns;
};
var getBlockHeight = function() {
return realHeight / numRows;
};
var getBlockPosX = function(columnIndex) {
return columnIndex * getBlockWidth();
};
var getBlockPosY = function(rowIndex) {
return rowIndex * getBlockHeight();
};
var getBlockCenterPosX = function(columnIndex) {
return (columnIndex + 0.5) * getBlockWidth();
};
var getBlockCenterPosY = function(rowIndex) {
return (rowIndex + 0.5) * getBlockHeight();
};
return {
getBlockWidth: getBlockWidth,
getBlockHeight: getBlockHeight,
getBlockPosX: getBlockPosX,
getBlockPosY: getBlockPosY,
getBlockCenterPosX: getBlockCenterPosX,
getBlockCenterPosY: getBlockCenterPosY,
getNumRows: getNumRows,
getNumColumns: getNumColumns
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment