Polygon.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:20k
源码类别:
绘图程序
开发平台:
Visual C++
- // Polygon.cpp: implementation of the CPolygon class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "Polygon.h"
- #include "math.h"
- #include "GlobalFunction.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- ///////////////////////////////////
- IMPLEMENT_SERIAL( CPolygon, CShape, 0 )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- CPolygon::CPolygon():CShape()
- {
- }
- CPolygon::CPolygon(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
- {
- }
- CPolygon::CPolygon(CPolygon * const pPolygon):CShape(pPolygon)
- {
- int i=pPolygon->m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- fx=pPolygon->m_flArrayxTemp.GetAt(j-1);
- fy=pPolygon->m_flArrayyTemp.GetAt(j-1);
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- i=pPolygon->m_flArrayx.GetSize();
- j=0;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- while(j++<i){
- fx=pPolygon->m_flArrayx.GetAt(j-1);
- fy=pPolygon->m_flArrayy.GetAt(j-1);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- }
- }
- CPolygon::~CPolygon()
- {
- }
- //////////////////////////////////////////////////////////////////////////
- void CPolygon::Serialize( CArchive& ar)
- {
- CShape::Serialize( ar ) ;
- int i=0,j;
- if ( ar.IsLoading() ){
- float fx,fy;
- ar>>i;
- j=0;
- while(j++ < i){
- ar>>fx;
- ar>>fy;
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- //temp
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- } else {
- RefreshData(m_bModified);
- i=m_flArrayx.GetSize();
- j=0;
- ar<<i;
- while(j++ < i){
- ar<<((float)m_flArrayx.GetAt(j-1));
- ar<<((float)m_flArrayy.GetAt(j-1));
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////
- void CPolygon::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
- {
- if(m_flArrayxTemp.GetSize()!=m_flArrayyTemp.GetSize())
- return;
- CPen pen,*poldPen;
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- pen.CreatePen(PS_SOLID,1, fillColor);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- CPoint *ptArray=new CPoint[i];
- for(j=0;j<i;j++){
- ptArray[j].x=m_flArrayxTemp.GetAt(j);
- ptArray[j].y=m_flArrayyTemp.GetAt(j);
- }
- AreaFill(pDC,i,ptArray,fillColor);
- delete[] ptArray;
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth, color);
- pDC->SelectObject(&pen);
- j=0;
- pDC->MoveTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j));
- while(++j<i){
- pDC->LineTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j));
- }
- pDC->LineTo(m_flArrayxTemp.GetAt(0),m_flArrayyTemp.GetAt(0));
- if(GetDrawPointsFlag()==1){
- DrawPoints(pDC,color);
- }
- pDC->SelectObject(poldPen);
- }
- ///////////////////////////////////////////
- void CPolygon::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- CArray<float,float> flArrayx;
- CArray<float,float> flArrayy;;
- //移动
- int i=m_flArrayxTemp.GetSize(),j;
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- for(j=0;j<i;j++){
- flArrayx.Add(m_flArrayxTemp.GetAt(j)+stepx);
- flArrayy.Add(m_flArrayyTemp.GetAt(j)+stepy);
- }
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- i=flArrayx.GetSize();
- for(j=0;j<i;j++){
- flArrayx.SetAt(j,(flArrayx.GetAt(j)-cx)*flScale+cx);
- flArrayy.SetAt(j,(flArrayy.GetAt(j)-cy)*flScale+cy);
- }
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- i=flArrayx.GetSize();
- for(j=0;j<i;j++){
- pDC->MoveTo(flArrayx.GetAt(j),flArrayy.GetAt(j)-1-GetPenWidth());
- pDC->LineTo(flArrayx.GetAt(j),flArrayy.GetAt(j)+2+GetPenWidth());
- pDC->MoveTo(flArrayx.GetAt(j)-1-GetPenWidth(),flArrayy.GetAt(j));
- pDC->LineTo(flArrayx.GetAt(j)+2+GetPenWidth(),flArrayy.GetAt(j));
- }
- pDC->SelectObject(poldPen);
- return;
- }
- void CPolygon::DrawPoints(CDC *pDC,COLORREF color)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- int i=m_flArrayxTemp.GetSize();
- for(int j=0;j<i;j++){
- pDC->MoveTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j)-1-GetPenWidth());
- pDC->LineTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j)+2+GetPenWidth());
- pDC->MoveTo(m_flArrayxTemp.GetAt(j)-1-GetPenWidth(),m_flArrayyTemp.GetAt(j));
- pDC->LineTo(m_flArrayxTemp.GetAt(j)+2+GetPenWidth(),m_flArrayyTemp.GetAt(j));
- }
- pDC->SelectObject(poldPen);
- return;
- }
- /////////////////
- void CPolygon::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- CArray<float,float> flArrayx;
- CArray<float,float> flArrayy;;
- //移动
- int i=m_flArrayxTemp.GetSize(),j;
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- for(j=0;j<i;j++){
- flArrayx.Add(m_flArrayxTemp.GetAt(j)+stepx);
- flArrayy.Add(m_flArrayyTemp.GetAt(j)+stepy);
- }
- //扩缩
- float cx,cy,flScale;
- cx=m_rectTo.left;
- cy=m_rectTo.top;
- if(m_rectFrom.Width()<0.01){
- m_rectFrom.right=m_rectFrom.left +1;
- }
- if(m_rectFrom.Height()<0.01){
- m_rectFrom.bottom=m_rectFrom.top +1;
- }
- flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
- //flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
- i=flArrayx.GetSize();
- for(j=0;j<i;j++){
- flArrayx.SetAt(j,(flArrayx.GetAt(j)-cx)*flScale+cx);
- flArrayy.SetAt(j,(flArrayy.GetAt(j)-cy)*flScale+cy);
- }
- CPen pen,*poldPen;
- i=flArrayx.GetSize();
- j=0;
- pen.CreatePen(PS_SOLID,1, fillColor);
- poldPen=pDC->SelectObject(&pen);
- if(m_nFillStyle==_shape_solid_fill){
- CPoint *ptArray=new CPoint[i];
- for(j=0;j<i;j++){
- ptArray[j].x=flArrayx.GetAt(j);
- ptArray[j].y=flArrayy.GetAt(j);
- }
- AreaFill(pDC,i,ptArray,fillColor);
- delete[] ptArray;
- }
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID,penWidth, color);
- pDC->SelectObject(&pen);
- j=0;
- pDC->MoveTo(flArrayx.GetAt(j),flArrayy.GetAt(j));
- while(++j<i){
- pDC->LineTo(flArrayx.GetAt(j),flArrayy.GetAt(j));
- }
- pDC->LineTo(flArrayx.GetAt(0),flArrayy.GetAt(0));
- if(GetDrawPointsFlag()==1){
- DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
- }
- pDC->SelectObject(poldPen);
- // flArrayx.RemoveAll();
- // flArrayy.RemoveAll();
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CPolygon::RefreshData(bool bRefresh)
- {
- if(bRefresh){
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- while(j++<i){
- fx=m_flArrayxTemp.GetAt(j-1);
- fy=m_flArrayyTemp.GetAt(j-1);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- }
- m_bModified=FALSE;
- m_ptMagnifyCenterTemp=CPoint(0,0);
- m_flScaleTemp=1;
- m_ptRotateCenterTemp=CPoint(0,0);
- m_flAngleTemp=0;
- }
- }
- void CPolygon::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- //if(ptArray.GetSize()<2){
- // return;
- //}
- CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
- int i=flArrayX.GetSize();
- int j=0;
- float flx,fly;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- flx=flArrayX.GetAt(j-1);
- fly=flArrayY.GetAt(j-1);
- m_flArrayx.Add(flx);
- m_flArrayy.Add(fly);
- //temp
- m_flArrayxTemp.Add(flx);
- m_flArrayyTemp.Add(fly);
- }
- }
- void CPolygon::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- //if(ptArray.GetSize()<2){
- // return;
- //}
- CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
- int i=ptArray.GetSize();
- int j=0;
- CPoint pt;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- pt=ptArray.GetAt(j-1);
- m_flArrayx.Add(pt.x);
- m_flArrayy.Add(pt.y);
- //temp
- m_flArrayxTemp.Add(pt.x);
- m_flArrayyTemp.Add(pt.y);
- //TRACE("%d---(%d,%d)n",j,pt.x,pt.y);
- }
- }
- void CPolygon::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- m_flArrayx.Copy(flArrayX);
- m_flArrayxTemp.Copy(flArrayX);
- m_flArrayy.Copy(flArrayY);
- m_flArrayyTemp.Copy(flArrayY);
- }
- void CPolygon::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- flArrayX.Copy(m_flArrayxTemp);
- flArrayY.Copy(m_flArrayyTemp);
- }
- CShape* CPolygon::GetCopy()
- {
- CShape* pGraph=new CPolygon(this);
- return pGraph;
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CPolygon::Move(CDC *pDC,float stepx,float stepy)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=m_flArrayxTemp.GetAt(j-1);
- fy=m_flArrayyTemp.GetAt(j-1);
- m_flArrayx.SetAt(j-1,fx+stepx);
- m_flArrayy.SetAt(j-1,fy+stepy);
- m_flArrayxTemp.SetAt(j-1,fx+stepx);
- m_flArrayyTemp.SetAt(j-1,fy+stepy);
- }
- }
- void CPolygon::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
- {
- RefreshData(m_bModified);
- if(m_nSelectPtNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_flArrayxTemp.SetAt(m_nSelectPtNum,CurX);
- m_flArrayyTemp.SetAt(m_nSelectPtNum,CurY);
- m_flArrayx.SetAt(m_nSelectPtNum,CurX);
- m_flArrayy.SetAt(m_nSelectPtNum,CurY);
- // CShape::Draw(pDC);
- }else if(m_nSelectLineNum>-1){
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- float flCut1x,flCut1y,flCut2x,flCut2y;
- float flX1[4],flY1[4],flX2[4],flY2[4];
- int nptNum=m_flArrayyTemp.GetSize();
- flX1[0]=m_flArrayx.GetAt((nptNum+m_nSelectLineNum-1)%nptNum);
- flY1[0]=m_flArrayy.GetAt((nptNum+m_nSelectLineNum-1)%nptNum);
- flX1[1]=CurX;
- flY1[1]=CurY;
- flX1[2] = m_flArrayx.GetAt((nptNum+m_nSelectLineNum)%nptNum);
- flY1[2] = m_flArrayy.GetAt((nptNum+m_nSelectLineNum)%nptNum);
- flX1[3] = m_flArrayx.GetAt((nptNum+m_nSelectLineNum+1)%nptNum);
- flY1[3] = m_flArrayy.GetAt((nptNum+m_nSelectLineNum+1)%nptNum);
- flX2[0]=m_flArrayx.GetAt((nptNum+m_nSelectLineNum+2)%nptNum);
- flY2[0]=m_flArrayy.GetAt((nptNum+m_nSelectLineNum+2)%nptNum);
- flX2[1]=CurX;
- flY2[1]=CurY;
- flX2[2] = flX1[2];
- flY2[2] = flY1[2];
- flX2[3] = flX1[3];
- flY2[3] = flY1[3];
- if(GetCutPtFrom2Line(flX1,flY1,&flCut1x,&flCut1y) && GetCutPtFrom2Line(flX2,flY2,&flCut2x,&flCut2y)){
- if(fabs(flCut1x-flX1[0])>0.01){
- m_flArrayxTemp.SetAt((nptNum+m_nSelectLineNum)%nptNum,(flX1[2]-flX1[0])*((float)CurX-flCut1x)/(flCut1x-flX1[0])+flX1[2]);
- }
- if(fabs(flCut1y-flY1[0])>0.01){
- m_flArrayyTemp.SetAt((nptNum+m_nSelectLineNum)%nptNum,(flY1[2]-flY1[0])*((float)CurY-flCut1y)/(flCut1y-flY1[0])+flY1[2]);
- }
- if(fabs(flCut2x-flX2[0])>0.01){
- m_flArrayxTemp.SetAt((nptNum+m_nSelectLineNum+1)%nptNum,(flX2[3]-flX2[0])*((float)CurX-flCut2x)/(flCut2x-flX2[0])+flX2[3]);
- }
- if(fabs(flCut2y-flY2[0])>0.01){
- m_flArrayyTemp.SetAt((nptNum+m_nSelectLineNum+1)%nptNum,(flY2[3]-flY2[0])*((float)CurY-flCut2y)/(flCut2y-flY2[0])+flY2[3]);
- }
- }
- // CShape::Draw(pDC);
- }
- }
- void CPolygon::Rotate(CDC *pDC,float CX,float CY,float flAngle)
- {
- if(m_flScaleTemp!=1){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptRotateCenterTemp=CPoint(CX,CY);
- m_flAngleTemp=flAngle;
- m_bModified=TRUE;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx,fy,fxTemp,fyTemp;
- while(j++<i){
- fx=m_flArrayx.GetAt(j-1);
- fy=m_flArrayy.GetAt(j-1);
- fxTemp=((fx-CX)*cos(flAngle)-(fy-CY)*sin(flAngle))+CX;
- fyTemp=((fy-CY)*cos(flAngle)+(fx-CX)*sin(flAngle))+CY;
- m_flArrayxTemp.SetAt(j-1,fxTemp);
- m_flArrayyTemp.SetAt(j-1,fyTemp);
- }
- }
- void CPolygon::Magnify(CDC *pDC,float CX,float CY,float flScale)
- {
- if(m_flAngleTemp!=0){
- RefreshData(TRUE);
- }
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- m_ptMagnifyCenterTemp=CPoint(CX,CY);
- m_flScaleTemp=flScale;
- m_bModified=TRUE;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=m_flArrayx.GetAt(j-1);
- fy=m_flArrayy.GetAt(j-1);
- fx=(fx-CX)*flScale+CX;
- fy=(fy-CY)*flScale+CY;
- m_flArrayxTemp.SetAt(j-1,fx);
- m_flArrayyTemp.SetAt(j-1,fy);
- }
- }
- void CPolygon::LeftToRight(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayx.GetSize();
- for(int j=0;j<i;j++){
- m_flArrayx.SetAt(j,rect.left/1000.0+rect.right/1000.0-m_flArrayx.GetAt(j));
- m_flArrayxTemp.SetAt(j,rect.left/1000.0+rect.right/1000.0-m_flArrayxTemp.GetAt(j));
- }
- //CShape::Draw(pDC);
- }
- void CPolygon::TopToBottom(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayx.GetSize();
- for(int j=0;j<i;j++){
- m_flArrayy.SetAt(j,rect.top/1000.0+rect.bottom/1000.0-m_flArrayy.GetAt(j));
- m_flArrayyTemp.SetAt(j,rect.top/1000.0+rect.bottom/1000.0-m_flArrayyTemp.GetAt(j));
- }
- //CShape::Draw(pDC);
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- int CPolygon::IsInRect(CRect rect)
- {
- int nRltVal=0,nTemp;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx1,fy1,fx2,fy2;
- while(++j < i){
- fx1=m_flArrayxTemp.GetAt(j-1);
- fy1=m_flArrayyTemp.GetAt(j-1);
- fx2=m_flArrayxTemp.GetAt(j);
- fy2=m_flArrayyTemp.GetAt(j);
- nTemp=GetLineStateToRect(fx1,fy1,fx2,fy2,rect);
- nRltVal=nRltVal | nTemp;
- }
- fx1=m_flArrayxTemp.GetAt(i-1);
- fy1=m_flArrayyTemp.GetAt(i-1);
- fx2=m_flArrayxTemp.GetAt(0);
- fy2=m_flArrayyTemp.GetAt(0);
- nTemp=GetLineStateToRect(fx1,fy1,fx2,fy2,rect);
- nRltVal=nRltVal | nTemp;
- if(nRltVal==3){
- nRltVal=1;
- }else if(nRltVal==0){
- CPoint pt[4];
- pt[0].x=rect.left;
- pt[0].y=rect.top;
- pt[1].x=rect.right;
- pt[1].y=rect.top;
- pt[2].x=rect.right;
- pt[2].y=rect.bottom;
- pt[3].x=rect.left;
- pt[3].y=rect.bottom;
- if(IsPointinRegion(pt[0])&&IsPointinRegion(pt[1])&&
- IsPointinRegion(pt[2])&&IsPointinRegion(pt[3])&&
- m_nFillStyle==_shape_solid_fill){
- nRltVal=1;
- }
- }
- return nRltVal;
- }
- CRect CPolygon::GetBoundaryRect()
- {
- if(m_flArrayxTemp.GetSize()==0){
- return CRect(0,0,0,0);
- }
- CRect rect(1000*m_flArrayxTemp.GetAt(0),1000*m_flArrayyTemp.GetAt(0),1000*m_flArrayxTemp.GetAt(0),1000*m_flArrayyTemp.GetAt(0));
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=1000*m_flArrayxTemp.GetAt(j-1);
- fy=1000*m_flArrayyTemp.GetAt(j-1);
- if(fx<rect.left){
- rect.left=fx;
- }else if(fx>rect.right){
- rect.right=fx;
- }
- if(fy<rect.top){
- rect.top=fy;
- }else if(fy>rect.bottom){
- rect.bottom=fy;
- }
- }
- return rect;
- }
- CPoint CPolygon::GetCenterPoint()
- {
- CRect rect=GetBoundaryRect();
- return rect.CenterPoint();
- }
- int CPolygon::IsPointinRegion(POINT point)
- {
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- while(++j < i){
- if(point.y>min(m_flArrayyTemp.GetAt(j-1),m_flArrayyTemp.GetAt(j))&&point.y<max(m_flArrayyTemp.GetAt(j-1),m_flArrayyTemp.GetAt(j)))
- {
- if((m_flArrayxTemp.GetAt(j)-(m_flArrayyTemp.GetAt(j)-m_flArrayyTemp.GetAt(j-1))*
- ((m_flArrayyTemp.GetAt(j)-point.y)/
- (m_flArrayxTemp.GetAt(j)-m_flArrayxTemp.GetAt(j-1)))) >=point.x){
- nRltVal+=1;
- }
- }
- }
- if(point.y>min(m_flArrayyTemp.GetAt(i-1),m_flArrayyTemp.GetAt(0))&&point.y<max(m_flArrayyTemp.GetAt(i-1),m_flArrayyTemp.GetAt(0)))
- {
- if((m_flArrayxTemp.GetAt(0)-(m_flArrayyTemp.GetAt(0)-m_flArrayyTemp.GetAt(i-1))*
- ((m_flArrayyTemp.GetAt(0)-point.y)/
- (m_flArrayxTemp.GetAt(0)-m_flArrayxTemp.GetAt(i-1)))) >=point.x){
- nRltVal+=1;
- } }
- if((nRltVal%2)==1){
- return 1;
- }
- return 0;
- }
- //////
- int CPolygon::GetPtState(float flx,float fly,float flRate){
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- float x,y;
- float tmpx,tmpy;
- while(j++<i){
- tmpx=m_flArrayxTemp.GetAt(j-1);
- tmpy=m_flArrayyTemp.GetAt(j-1);
- if(IsPtInRect(tmpx-3*flRate,tmpy-3*flRate,tmpx+3*flRate,tmpy+3*flRate,flx,fly)){
- m_nSelectPtNum=j-1;
- m_nSelectLineNum=-1;
- return 1;
- }
- }
- //on out line
- j=0;
- while(++j<i){
- if(GetPtStateToBigLine(m_flArrayxTemp.GetAt(j-1),m_flArrayyTemp.GetAt(j-1),
- m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j),5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=j-1;
- return 2;
- }
- }
- if(GetPtStateToBigLine(m_flArrayxTemp.GetAt(i-1),m_flArrayyTemp.GetAt(i-1),
- m_flArrayxTemp.GetAt(0),m_flArrayyTemp.GetAt(0),5*flRate,flx,fly)){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=i-1;
- return 2;
- }
- //out
- m_nSelectPtNum=-1;
- m_nSelectLineNum=-1;
- return 0;
- }
- float CPolygon::GetSelectLineRate()
- {
- if(m_nSelectLineNum==-1)
- return 0;
- int nptNum= m_flArrayxTemp.GetSize();
- float flx1 = m_flArrayx.GetAt((nptNum+m_nSelectLineNum)%nptNum);
- float fly1 = m_flArrayy.GetAt((nptNum+m_nSelectLineNum)%nptNum);
- float flx2 = m_flArrayx.GetAt((nptNum+m_nSelectLineNum+1)%nptNum);
- float fly2 = m_flArrayy.GetAt((nptNum+m_nSelectLineNum+1)%nptNum);
- return -GetLineRate(flx1,fly1,flx2,fly2);
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ExPort
- // ABSTRACT :Export to a txt file
- // FUNCTION :File->Export...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // O FILE* outStream Out put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CPolygon::ExPort(FILE* outStream)//增加导出txt功能时用
- {
- fprintf(outStream, " CPolygon n");
- CShape::ExPort(outStream);
- int n=m_flArrayxTemp.GetSize();
- int i=0;
- fprintf(outStream, " %d ",n);
- while(i++ < n){
- fprintf( outStream, " %f %f",(float)m_flArrayxTemp.GetAt(i-1),(float)m_flArrayyTemp.GetAt(i-1));
- }
- fprintf( outStream, "n");
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ImPort
- // ABSTRACT :ImPort from a txt file
- // FUNCTION :File->ImPort...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // I FILE* inStream in put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CPolygon::ImPort(FILE* inStream)
- {
- CShape::ImPort(inStream);
- float fx,fy;
- int n;
- fscanf(inStream, "%d",&n);
- int i=0;
- while(i++ < n){
- fscanf(inStream, "%f%f",&fx,&fy);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- //temp
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- }
- CString CPolygon::GetNameString()
- {
- CString str;
- str.LoadString(IDS_POLYGON);
- return str;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File////////////////
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////