Skip to content

Instantly share code, notes, and snippets.

@timotree3
Created July 7, 2017 15:21
Show Gist options
  • Save timotree3/1f45558ed13fb70957ef27226ad4cd40 to your computer and use it in GitHub Desktop.
Save timotree3/1f45558ed13fb70957ef27226ad4cd40 to your computer and use it in GitHub Desktop.
Coordinate Transformation
/*****************************************
* credit to *
* http://www.solitaryroad.com/c308.html *
*****************************************/
function Location(x, y) {
this.x = x;
this.y = y;
this.flip_h = function(max) {
return new Location(max - this.x, this.y);
};
this.flip_v = function(max) {
return new Location(this.x, max - this.y);
};
this.flip_24 = function() {
return new Location(this.y, this.x);
};
this.flip_13 = function(max) {
return this.flip_v(max).turn_90(max);
};
this.turn_90 = function(max) {
return this.flip_v(max).flip_24();
};
this.turn_180 = function(max) {
return this.turn_90(max).turn_90(max);
};
this.turn_270 = function(max) {
return this.turn_90(max).turn_90(max).turn_90(max);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment