Skip to content

Instantly share code, notes, and snippets.

@Mr00Anderson
Created October 14, 2020 20:38
Show Gist options
  • Save Mr00Anderson/8216b26a6fd5510a67846db49d580712 to your computer and use it in GitHub Desktop.
Save Mr00Anderson/8216b26a6fd5510a67846db49d580712 to your computer and use it in GitHub Desktop.
package com.virtual_hex.gdx.engine.maps;
public class TwoDIndexCalculation {
public static int rowMajorYTopLeft(int x, int y, int width){
return (width * x) + y;
}
public static int rowMajorYBottomLeft(int x, int y, int height, int indexHeight, int arrayLastIndex){
int indexY = indexHeight - y;
return arrayLastIndex - ((height * x) + indexY);
}
public static int rowMajorTopRight(int x, int y, int width, int indexHeight){
int indexY = indexHeight - y;
return (width * x) + indexY;
}
public static int colMajorYTopLeft(int x, int y, int width){
return (width * y) + x;
}
public static int colMajorYBottomLeft(int x, int y, int width, int indexHeight){
int indexY = indexHeight - y;
return (width * indexY) + x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment