Skip to content

Instantly share code, notes, and snippets.

@rhyolight
Created March 25, 2010 14:58
Show Gist options
  • Save rhyolight/343637 to your computer and use it in GitHub Desktop.
Save rhyolight/343637 to your computer and use it in GitHub Desktop.
PositionedRectangle = function(w,h,xIn,yIn) {
var x = xIn,
y = yIn,
rect = new ORectangle(w,h),
me = {
getX: function() { return x; },
setX: function(xIn) { this.x = xIn; },
getY: function() { return y; },
setY: function(yIn) { this.y = yIn; },
distanceFrom: function(otherRect) {
return Math.sqrt(
Math.pow(this.getX() - otherRect.getX(), 2)
+ Math.pow(this.getY() - otherRect.getY(), 2)
);
},
toString: function() {
return rect.toString() + ' at ' + this.getX() + ',' + this.getY();
}
};
return mixin(rect, me);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment