/**
*	Constructor de l'objecte.
*	exemple: var punt = new NPoint(30000,930000);
*	@param {Number} cX Valor de la longitud
*	@param {Number} cY Valor de la latitud
*/
function NPoint(arg1,arg2) {
	if ( arguments.length == 1 )
		this.deserialize(arg1);
	else 
		this.init(arg1,arg2);
}

/**
*	Constructor de l'objecte.
*	exemple: var punt = new NPoint(30000,930000);
*	@param {Number} cX Valor de la longitud
*	@param {Number} cY Valor de la latitud
*/
NPoint.prototype.init = function(cX,cY) {
  this.cX = cX;
  this.cY = cY;
};

/**
*	Retorna la longitud
*	@return {Number}
*/
NPoint.prototype.getX = function() {
  return this.cX;
};

/**
*	Retorna la latitud
*	@return {Number}
*/
NPoint.prototype.getY = function() {
  return this.cY;
};

/**
*	NPoint setX
*	@param {Number} x Valor de la longitud
*/
NPoint.prototype.setX = function(x) {
  this.cX = x;
};

/**
*	NPoint setY
*	@param {Number} y Valor de la latitud
*/
NPoint.prototype.setY = function(y) {
  this.cY = y;
};

/**
*	NPoint toString
*	@private
*/
NPoint.prototype.toString = function() {
  return "(" + this.cX + "," + this.cY + ")";
};

/**
*	NPoint toString
*	@private
*/
NPoint.prototype.clone = function() {
  return new NPoint(this.cX,this.cY);
};

/**
*	Serialitza l'objecte
*/
NPoint.prototype.serialize = function() {
  return this.cX+","+this.cY;
};

/**
*	Serialitza l'objecte
*	@return {void}
*/
NPoint.prototype.deserialize = function(str) {
	var a=str.split(",");
	this.cX=parseFloat(a[0]);
	this.cY=parseFloat(a[1]);
};

/**
*	Recalcula el punt aplicant un angle de rotació.
*	@param {Float} angle de rotació en radiants.
*	@param {NPoint} punt sobre el que rotar.
*	@return {void}
*/
NPoint.prototype.rotate = function(angle,center) {
	try {
		angle=parseFloat(angle);

		var auxCx=(this.cX-center.cX)*Math.cos(angle)-(this.cY-center.cY)*Math.sin(angle)+center.cX;
		var auxCy=(this.cX-center.cX)*Math.sin(angle)+(this.cY-center.cY)*Math.cos(angle)+center.cY;
		
		this.cX=auxCx;
		this.cY=auxCy;
	}
	catch (e) {
		alert("Error a NPoint.rotate()\n"+e.message);
	}
};



