/**
 * Some additions on Canvas.
 */

CanvasRenderingContext2D.prototype.setWorld = function(xmin, ymin, xmax, ymax) {
	this.xmin = xmin;
	this.ymin = ymin;
	this.xmax = xmax;
	this.ymax = ymax;
}

CanvasRenderingContext2D.prototype.convertWorldX = function(x) {
	return (x - this.xmin) / (this.xmax - this.xmin) * (this.canvas.width-1);
}

CanvasRenderingContext2D.prototype.convertWorldY = function(y) {
	return (this.ymax - y) / (this.ymax - this.ymin) * (this.canvas.height-1);
}

CanvasRenderingContext2D.prototype.convertWorldLength = function(d) {
	return d / (this.xmax - this.xmin) * this.canvas.width;
}

CanvasRenderingContext2D.prototype.moveToWorld = function(x, y) {
	this.moveTo(this.convertWorldX(x), this.convertWorldY(y));
}

CanvasRenderingContext2D.prototype.lineToWorld = function(x, y) {
	this.lineTo(this.convertWorldX(x), this.convertWorldY(y));
}

CanvasRenderingContext2D.prototype.arcWorld = function(x, y, radius, startAngle, endAngle, anticlockwise) {
	this.arc(this.convertWorldX(x), this.convertWorldY(y), this.convertWorldLength(radius), startAngle, endAngle,
			anticlockwise);
}

