/********************************************************************/
/* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno          */
/* All rights reserved.                                             */
/********************************************************************/
#include "MGCLStdAfx.h"
#include "mg/Tolerance.h"
#include "mg/LBRep.h"

#if defined(_DEBUG)
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// MGLBRep.cpp
//
// Implement MGLBRep class.

///This is a polar coordinate system data.
///Given polar coordinate LBRep, update this to ordinary coordinates system MGLBRep.
///This curve's (x,y) coordinates are polar coordinates system(r,theta), 
///where r is the distance from origin and theta is the angel with x coordinate.
///When return from the function (x,y) are ordinary coordinate system.
///The space dimension of this curve must be >=2;
///If this space dimension is lager than 2, the remaining coordinates are unchanged.
void MGLBRep::updatePolarCoordinates2Ordinary(){
	int n=bdim();
	assert(bdim()>=2);
	MGBPointSeq& bp=line_bcoef();
	for(int i=0; i<n; i++){
		double r=bp(i,0);
		double theta=bp(i,1);
		double x,y;
		if(r<=MGTolerance::wc_zero()){
			x=y=0.;
		}else{
			x=r*cos(theta);
			y=r*sin(theta);
		}
		bp(i,0)=x;
		bp(i,1)=y;
	}
	update_mark();
}
