www.pudn.com > roll.rar > COMNFUN.CPP


#include "stdafx.h" 
#include  
 
double _Global_Ratio; 
 
int FLTtoINT(float x) 
{ 
	if(fabs(x)<1.0e-10) return 0; 
	return (x>0.0 ? int(x+0.5) : int(x-0.5)); 
} 
 
int DBLtoINT(double x) 
{ 
	if(fabs(x)<1.0e-10) return 0; 
	return (x>0.0 ? int(x+0.5) : int(x-0.5)); 
} 
 
void Arc_f(CDC* dc,double xc,double yc,double a,double b,double xs,double ys,double xe,double ye) 
{ 
	CRect rect=CRect(DBLtoINT(_Global_Ratio*(xc-a)),DBLtoINT(_Global_Ratio*(yc-b)), 
		DBLtoINT(_Global_Ratio*(xc+a)),DBLtoINT(_Global_Ratio*(yc+b))); 
	CPoint start=CPoint(DBLtoINT(_Global_Ratio*xs),DBLtoINT(_Global_Ratio*ys)); 
	CPoint end=CPoint(DBLtoINT(_Global_Ratio*xe),DBLtoINT(_Global_Ratio*ye)); 
	dc->Arc(&rect,start,end); 
} 
 
void Arc_f(CDC* dc,double xc,double yc,double r,double xs,double ys,double xe,double ye) 
{ 
	Arc_f(dc,xc,yc,r,r,xs,ys,xe,ye); 
} 
 
void Circle_f(CDC* dc,double xc,double yc,double r) 
{ 
	Arc_f(dc,xc,yc,r,r,r+xc,0.0,r+xc,0.0); 
} 
 
void Line_f(CDC* dc,double xs,double ys,double xe,double ye) 
{ 
	dc->MoveTo(DBLtoINT(_Global_Ratio*xs),DBLtoINT(_Global_Ratio*ys)); 
	dc->LineTo(DBLtoINT(_Global_Ratio*xe),DBLtoINT(_Global_Ratio*ye)); 
} 
 
void MoveTo_f(CDC* dc,double x,double y) 
{ 
	dc->MoveTo(DBLtoINT(_Global_Ratio*x),DBLtoINT(_Global_Ratio*y)); 
} 
 
void LineTo_f(CDC* dc,double x,double y) 
{ 
	dc->LineTo(DBLtoINT(_Global_Ratio*x),DBLtoINT(_Global_Ratio*y)); 
} 
 
void DrawHArrow(CDC *dc,double x,double y) 
{ 
	POINT pt[4]; 
	pt[3].x=pt[0].x=DBLtoINT(x); 
	pt[3].y=pt[0].y=DBLtoINT(y); 
	pt[2].x=pt[1].x=DBLtoINT(x-6); 
	pt[1].y=DBLtoINT(y+2); 
	pt[2].y=DBLtoINT(y-2); 
	dc->Polyline(pt,4); 
} 
 
void DrawVArrow(CDC *dc,double x,double y) 
{ 
	POINT pt[4]; 
	pt[3].x=pt[0].x=DBLtoINT(x); 
	pt[3].y=pt[0].y=DBLtoINT(y); 
	pt[2].y=pt[1].y=DBLtoINT(y-6); 
	pt[1].x=DBLtoINT(x+2); 
	pt[2].x=DBLtoINT(x-2); 
	dc->Polyline(pt,4); 
} 
 
void DrawRectangle(CDC* dc,double xmin,double xmax,double ymin,double ymax) 
{ 
	dc->Rectangle(DBLtoINT(xmin),DBLtoINT(ymin),DBLtoINT(xmax),DBLtoINT(ymax)); 
}