Скачиваний:
16
Добавлен:
01.05.2014
Размер:
2.57 Кб
Скачать
#include "l1c1point.h"

int cPoint::quantity = 0;

cPoint::cPoint(const double x1,const double y1)
 {
  SetXY(x1,y1);
  quantity++;
 };

cPoint::cPoint()
{};

cPoint::~cPoint()
{
 quantity--;
};

int cPoint::Getquantity()
{
 return quantity;
};

void cPoint::inv() const
{
 if ( (x > MAXFLOAT) || (x < -MAXFLOAT) || (y > MAXFLOAT) || (y < -MAXFLOAT))

 {
 clrscr();
 cout<<"incorrect conditions";
 getch();
 exit(1);
 }
}


void cPoint::GetXY(double &x1, double &y1) const
{
 x1=x;
 y1=y;
}//GetXY


void cPoint::Set(const cPoint &F)
{
 SetXY(F.GetX(),F.GetY());
};


void cPoint::SetXY(const double x1,const double y1)
{
 if ((x1 > MAXFLOAT)||(x1 < -MAXFLOAT)||(y1 > MAXFLOAT)||(y1 < -MAXFLOAT))
 {
	clrscr();
	cout<<"incorrect conditions";
	getch();
	exit(1);
 };
 x=x1;
 y=y1;

}//SetXY


void cPoint::Move(const double dx,const double dy)
{
 if ((dx > MAXFLOAT)||(dx < -MAXFLOAT)||(dy > MAXFLOAT)||(dy < -MAXFLOAT))
 {
	clrscr();
			cout<<"incorrect conditions";
			getch();
	exit(1);
 };
 inv();
 double x1,y1;
 GetXY(x1,y1);
 x1+=dx;
 y1+=dy;
 SetXY(x1,y1);
 inv();
}//Move


void cPoint::Rotate(const double x0,const double y0,const double alpha)
{
 if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
 {
 clrscr();
			cout<<"incorrect conditions";
			getch();
 exit(1);
 };
 inv();
 double x1,y1,c,s,x11,x12,y11,y12;
 GetXY(x1,y1);
 c=cos(alpha);
 s=sin(alpha);
 x11=(x1-x0)*c;
 x12=(y1-y0)*s;
 y11=(y1-y0)*c;
 y12=(x1-x0)*s;
 x1=x11-x12+x0;
 y1=y11+y12+y0;
 SetXY(x1,y1);
 inv();
}//Rotate



void cPoint::Mirror(const double x0,const double y0)
{
 inv();
 if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
 {
 clrscr();
			cout<<"incorrect conditions";
			getch();
 exit(1);
 };
 double x1,y1;
 GetXY(x1,y1);
 x1=2*x0-x1;
 y1=2*y0-y1;
 SetXY(x1,y1);
 inv();
}

double cPoint::GetX() const
{
 return x;
}//GetX

double cPoint::GetY() const
{
 return y;
}//GetY


double cPoint::Distance(const double x0,const double y0) const
{
 if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
 {
 clrscr();
			cout<<"incorrect conditions";
			getch();
 exit(1);
 };
 inv();
 double x1,y1,ans;
 GetXY(x1,y1);
 ans=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
 if (ans>MAXFLOAT)
 {
	clrscr();
			cout<<"incorrect result";
			getch();
	exit(1);
 }
 inv();
 return ans;
}//Distance


void cPoint::Out() const
{
 cout<<"("<<GetX()<<";"<<GetY()<<") ";
};
Соседние файлы в папке Лабораторная работа 2