Created
July 7, 2017 15:21
-
-
Save timotree3/1f45558ed13fb70957ef27226ad4cd40 to your computer and use it in GitHub Desktop.
Coordinate Transformation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************** | |
* 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