Skip to content

Instantly share code, notes, and snippets.

@jessefreeman
Created April 10, 2013 03:18
Show Gist options
  • Select an option

  • Save jessefreeman/5351492 to your computer and use it in GitHub Desktop.

Select an option

Save jessefreeman/5351492 to your computer and use it in GitHub Desktop.
TypeScript output of my Geom classes for PixelVisionJS
// Module
var pxv;
(function (pxv) {
var Point = (function () {
function Point(x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this.x = x;
this.y = y;
}
Point.prototype.add =
function (v) {
return new Point(this.x + v.x, this.y + v.y);
};
Point.prototype.clone =
function () {
return new Point(this.x, this.y);
};
Point.prototype.distance =
function (v) {
var x = this.x - v.x;
var y = this.y - v.y;
return Math.sqrt(x * x + y * y);
};
Point.prototype.toString =
function () {
return "(x=" + this.x + ", y=" + this.y + ")";
};
return Point;
})();
pxv.Point = Point;
var Rectangle = (function () {
function Rectangle(x, y, width, height) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
if (typeof width === "undefined") { width = 0; }
if (typeof height === "undefined") { height = 0; }
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.left = 0;
this.right = 0;
this.top = 0;
this.bottom = 0;
this.resize(x, y, width, height);
}
Rectangle.prototype.copyFrom = function (rect) {
this.x = rect.x;
this.y = rect.y;
this.width = rect.width;
this.height = rect.height;
return this;
};
Rectangle.prototype.copyTo = function (rect) {
rect.x = this.x;
rect.y = this.y;
rect.width = this.width;
rect.height = this.height;
return rect;
};
Rectangle.prototype.resize = function (x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.left = this.x;
this.right = this.x + this.width;
this.top = this.y;
this.bottom = this.y + this.height;
};
Rectangle.prototype.contains = function (targetRect) {
return (targetRect.x + targetRect.width > this.x) && (targetRect.x < this.x + this.width) && (targetRect.y + targetRect.height > this.y) && (targetRect.y < this.y + this.height);
};
return Rectangle;
})();
pxv.Rectangle = Rectangle;
})(pxv || (pxv = {}));
//@ sourceMappingURL=Geom.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment