//======   " "
class CDPoint
{
public:
	double x;
	double y;		//=====  

	//======   
	CDPoint() { x=0.; y=0.; }
	
	//======  
	CDPoint(const CDPoint& pt)
	{
		x = pt.x;
		y = pt.y; 
	}

	//======   
	CDPoint(double xx, double yy)
	{
		x = xx;
		y = yy;
	}
	
	//======   (  n )
	CDPoint operator*(UINT n)
 {
		return CDPoint (x*n,  y*n); 
	}

	//======  
	CDPoint& operator=(const CDPoint& pt) 
	{
		x = pt.x;	
		y = pt.y;
		return *this;		//   
	}
	
	//======    
	CDPoint operator+(CDPoint& pt) 
	{
		return CDPoint(x + pt.x, y + pt.y);
	}
	
	//======    
	CDPoint operator-(CDPoint& pt) 
	{
		return CDPoint(x - pt.x, y - pt.y);
	}
	
	//      CPoint ( )
	CPoint ToInt() 
	{
		return CPoint(int(x),int(y));
	}
	
	//======     
	void operator+=(CDPoint& pt) { x += pt.x;		y += pt.y; }
	
	//======     
	void operator-=(CDPoint& pt) { x -= pt.x;		y -= pt.y; }

	//======    ,  
	double operator! () { return fabs(x) + fabs(y); }
};


typedef vector<CDPoint, allocator<CDPoint> > VECPTS;


CMyDoc::CMyDoc()
{
	//======  
	double	pi = 4. * atan(1.),
				//====== 
				a1 = pi / 10.,	a2 = 3. * a1,
				//====== 2  
				x1 = cos(a1),		y1 = sin(a1),	
				x2 = cos(a2),		y2 = sin(a2);
	
	//====  (World)   
	m_Points.push_back(CDPoint( 0.,  1.));
	m_Points.push_back(CDPoint(-x2, -y2));
	m_Points.push_back(CDPoint( x1,  y1));
	m_Points.push_back(CDPoint(-x1,  y1));
	m_Points.push_back(CDPoint( x2, -y2));
}


void CMyView::OnSize(UINT nType, int cx, int cy)
{
	//==========   
	CView::OnSize(nType, cx, cy);

	if (cx==0 || cy==0)
		return;
	
	//=========    
	m_szView = CSize (cx, cy);
}

public:
		afx_msg void OnSize(UINT nType, int cx, int cy);


void CMyView::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	
	//===     World- 
	VECPTS& pts = GetDocument()->m_Points;
	UINT size = pts.size();
	
	//======     
	m_Points.resize(size);

	for (UINT i=0; i < size; i++)
		m_Points[i] = (pts[i] * m_nLogZoom).ToInt();
}


void CMyView::OnDraw(CDC* pDC)
{
	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	//======    
	UINT nPoints = m_Points.size();
	if (!nPoints)			// ,   
		return;
	
	//     ( GDI)
	pDC->SaveDC();

	//   Windows    
	CPen pen (PS_SOLID,2,RGB(0,96,0));

	//======     
	pDC->SelectObject (&pen);
	
	//===   Windows    
	CBrush brush (RGB(240,255,250));
	pDC->SelectObject (&brush);
	
	//======    
	pDC->SetMapMode(MM_ISOTROPIC);

	//======    
	pDC->SetWindowOrg(0,0);
	//======    
	pDC->SetViewportOrg (m_szView.cx/2, m_szView.cy/2);

	//======   
	pDC->SetWindowExt(3*m_nLogZoom,3*m_nLogZoom);	
	//======   
	pDC->SetViewportExt (m_szView.cx, -m_szView.cy);	
	
	//======  
	pDC->Polygon (&m_Points[0], nPoints);
	
	//   (  GDI)
	pDC->RestoreDC(-1);
}
