Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icholy/d73c9e8ea349492e8f26 to your computer and use it in GitHub Desktop.
Save icholy/d73c9e8ea349492e8f26 to your computer and use it in GitHub Desktop.
var FlatCoordinates = function () {
var FlatCoordinates = function FlatCoordinates (coordinates) {
this._coordinates = coordinates;
};
FlatCoordinates.prototype.shift = function () {
var c = this._coordinates;
c.shift();
c.shift();
};
FlatCoordinates.prototype.pop = function () {
var c = this._coordinates;
c.pop();
c.pop();
};
FlatCoordinates.prototype.push = function (coordinate) {
var c = this._coordinates;
c.push(coordinate[0]);
c.push(coordinate[1]);
};
FlatCoordinates.prototype.get = function (index) {
return this._coordinates.slice(index*2, (index*2)+2);
};
FlatCoordinates.prototype.set = function (index, coordinate) {
this._coordinates.splice(index, index+2, coordinate[0], coordinate[1]);
};
FlatCoordinates.prototype.unshift = function (coordinate) {
var c = this._coordinates;
c.unshift(coordinate[0]);
c.unshift(coordinate[1]);
};
FlatCoordinates.prototype.length = function () {
return this._coordinates.length / 2;
};
return FlatCoordinates;
}.call(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment