BezierCurve.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:19k
源码类别:
绘图程序
开发平台:
Visual C++
- // BezierCurve.cpp: implementation of the CBezierCurve class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "BezierCurve.h"
- #include "math.h"
- #include "GlobalFunction.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- ///////////////////////////////////
- IMPLEMENT_SERIAL( CBezierCurve, CShape, 0 )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- CBezierCurve::CBezierCurve():CShape()
- {
- }
- CBezierCurve::CBezierCurve(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
- {
- }
- CBezierCurve::CBezierCurve(CBezierCurve * const pBezierCurve):CShape(pBezierCurve)
- {
- int i=pBezierCurve->m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- fx=pBezierCurve->m_flArrayxTemp.GetAt(j-1);
- fy=pBezierCurve->m_flArrayyTemp.GetAt(j-1);
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- i=pBezierCurve->m_flArrayx.GetSize();
- j=0;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- while(j++<i){
- fx=pBezierCurve->m_flArrayx.GetAt(j-1);
- fy=pBezierCurve->m_flArrayy.GetAt(j-1);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- }
- }
- CBezierCurve::~CBezierCurve()
- {
- }
- //////////////////////////////////////////////////////////////////////////
- void CBezierCurve::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 CBezierCurve::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,penWidth, color);
- poldPen=pDC->SelectObject(&pen);
- deCasteljau(pDC,m_flArrayxTemp,m_flArrayyTemp);
- if(GetDrawPointsFlag()==1){
- DrawPoints(pDC,color);
- }
- pDC->SelectObject(poldPen);
- }
- ///////////////////////////////////////////
- void CBezierCurve::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();
- int nSX,nSY;
- nSX=flArrayx.GetAt(0);
- nSY=flArrayy.GetAt(0);
- 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));
- //画线
- pen.DeleteObject();
- CShape::DotLine(pDC,nSX,nSY,flArrayx.GetAt(j),flArrayy.GetAt(j),color);
- nSX=flArrayx.GetAt(j);
- nSY=flArrayy.GetAt(j);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- void CBezierCurve::DrawPoints(CDC *pDC,COLORREF color)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- int i=m_flArrayxTemp.GetSize();
- int nSX,nSY;
- nSX=m_flArrayxTemp.GetAt(0);
- nSY=m_flArrayyTemp.GetAt(0);
- 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));
- //画线
- pen.DeleteObject();
- // pen.CreatePen(PS_DOT,1,color);
- // pDC->SelectObject(&pen);
- //pDC->MoveTo(nSX,nSY);
- //pDC->LineTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j));
- CShape::DotLine(pDC,nSX,nSY,m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j),color);
- nSX=m_flArrayxTemp.GetAt(j);
- nSY=m_flArrayyTemp.GetAt(j);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- ////////////////////////////
- void CBezierCurve::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;
- pen.CreatePen(PS_SOLID,penWidth, color);
- poldPen=pDC->SelectObject(&pen);
- deCasteljau(pDC,flArrayx,flArrayy);
- if(GetDrawPointsFlag()==1){
- DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
- }
- pDC->SelectObject(poldPen);
- }
- /*int CBezierCurve::deCasteljau(CDC *pDC,CArray<float,float>& flArrayx,CArray<float,float>& flArrayy)
- {
- if(flArrayx.GetSize()!=flArrayy.GetSize())
- return 0;
- CArray<float,float> flLx,flLy,flRx,flRy;//(flLx,flLy)-----0〈=u〈=1/2内的控制点
- //(flRx,flRy)-----1/2〈=u〈=1内的控制点
- float flTemp1x,flTemp1y,flTemp2x,flTemp2y,flU=0.5;//flu-------u参数
- int i,n,j;
- n=flArrayx.GetSize();
- if(n<2) return 0;
- for(i=0;i<n;i++){//方便后来的程序,加满无效点
- flLx.Add(0);
- flLy.Add(0);
- flRx.Add(0);
- flRy.Add(0);
- }
- //关键迭代
- flLx.SetAt(0,flArrayx.GetAt(0));
- flLy.SetAt(0,flArrayy.GetAt(0));
- flRx.SetAt(0,flArrayx.GetAt(0));
- flRy.SetAt(0,flArrayy.GetAt(0));
- for(i=1;i<n;i++){
- flTemp1x=flRx.GetAt(0);
- flTemp1y=flRy.GetAt(0);
- flRx.SetAt(0,flArrayx.GetAt(i));
- flRy.SetAt(0,flArrayy.GetAt(i));
- for(j=1;j<=i;j++){
- flTemp2x=flRx.GetAt(j);
- flTemp2y=flRy.GetAt(j);
- flRx.SetAt(j,(flRx.GetAt(j-1)+flTemp1x)/2);
- flRy.SetAt(j,(flRy.GetAt(j-1)+flTemp1y)/2);
- flTemp1x=flTemp2x;
- flTemp1y=flTemp2y;
- }
- flLx.SetAt(i,flRx.GetAt(i));
- flLy.SetAt(i,flRy.GetAt(i));
- }
- for(i=0,j=n-1;i<=j;i++,j--){//反序得到1/2〈=u〈=1内的控制点
- flTemp2x=flRx.GetAt(i);
- flTemp2y=flRy.GetAt(i);
- flRx.SetAt(i,flRx.GetAt(j));
- flRy.SetAt(i,flRy.GetAt(j));
- flRx.SetAt(j,flTemp2x);
- flRy.SetAt(j,flTemp2y);
- }
- //关键递归
- float distanceLC,distanceRC;
- distanceLC=GetDistance(m_flArrayx.GetAt(0),m_flArrayy.GetAt(0),flLx.GetAt(n-1),flLy.GetAt(n-1));
- distanceRC=GetDistance(m_flArrayx.GetAt(n-1),m_flArrayy.GetAt(n-1),flLx.GetAt(n-1),flLy.GetAt(n-1));
- TRACE("d1=%f,d2=%f,(%f,%f),(%f,%f),(%f,%f)n",distanceLC,distanceRC,m_flArrayx.GetAt(0),m_flArrayy.GetAt(0),flLx.GetAt(n-1),flLy.GetAt(n-1),m_flArrayx.GetAt(n-1),m_flArrayy.GetAt(n-1));
- if(max(distanceLC,distanceRC)<=3){//分割结束条件,'中点'和两端点重合
- pDC->MoveTo(m_flArrayx.GetAt(0),m_flArrayy.GetAt(0));
- pDC->LineTo(m_flArrayx.GetAt(n-1),m_flArrayy.GetAt(n-1));
- }else{
- deCasteljau(pDC,flLx,flLy);
- deCasteljau(pDC,flRx,flRy);
- }
- return 1;
- }
- */
- int CBezierCurve::deCasteljau(CDC *pDC,CArray<float,float>& flArrayx,CArray<float,float>& flArrayy)
- {
- if(flArrayx.GetSize()!=flArrayy.GetSize())
- return 0;
- float *pflX,*pflY;
- float flTempx,flTempy,flU;//flu-------u参数
- int i,n,j;
- n=flArrayx.GetSize();
- if(n<2) return 0;
- pflX=new float[n];
- pflY=new float[n];
- flTempx=flArrayx.GetAt(0);
- flTempy=flArrayy.GetAt(0);
- for(i=0;i<n;i++){
- pflX[i]=flArrayx.GetAt(i);
- pflY[i]=flArrayy.GetAt(i);
- }
- for(flU=0;flU<=1;flU+=0.05/n){
- for(i=1;i<n;i++){
- for(j=0;j<n-i;j++){
- pflX[j]=(1-flU)*pflX[j]+flU*pflX[j+1];
- pflY[j]=(1-flU)*pflY[j]+flU*pflY[j+1];
- }
- }
- pDC->MoveTo(flTempx,flTempy);
- pDC->LineTo(pflX[0],pflY[0]);
- flTempx=pflX[0];
- flTempy=pflY[0];
- }
- delete[] pflX;
- delete[] pflY;
- return 1;
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CBezierCurve::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 CBezierCurve::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 CBezierCurve::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 CBezierCurve::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- flArrayX.Copy(m_flArrayxTemp);
- flArrayY.Copy(m_flArrayyTemp);
- }
- void CBezierCurve::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);
- }
- }
- CShape* CBezierCurve::GetCopy()
- {
- CShape* pGraph=new CBezierCurve(this);
- return pGraph;
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CBezierCurve::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 CBezierCurve::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);
- }
- }
- void CBezierCurve::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 CBezierCurve::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 CBezierCurve::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 CBezierCurve::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 CBezierCurve::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;
- }
- if(nRltVal==3){
- nRltVal=1;
- }
- return nRltVal;
- }
- CRect CBezierCurve::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=m_flArrayxTemp.GetAt(j-1);
- fy=m_flArrayyTemp.GetAt(j-1);
- if(1000*fx<rect.left){
- rect.left=1000*fx;
- }else if(1000*fx>rect.right){
- rect.right=1000*fx;
- }
- if(1000*fy<rect.top){
- rect.top=1000*fy;
- }else if(1000*fy>rect.bottom){
- rect.bottom=1000*fy;
- }
- }
- return rect;
- }
- CPoint CBezierCurve::GetCenterPoint()
- {
- CRect rect=GetBoundaryRect();
- return rect.CenterPoint();
- }
- int CBezierCurve::IsPointinRegion(POINT point)
- {
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- CPoint pt1,pt2;
- CRect rect;
- while(++j < i){
- pt1.x=m_flArrayxTemp.GetAt(j-1);
- pt1.y=m_flArrayyTemp.GetAt(j-1);
- pt2.x=m_flArrayxTemp.GetAt(j);
- pt2.y=m_flArrayyTemp.GetAt(j);
- rect=GetRectFromPoint(pt1,pt2);
- if(rect.PtInRect(point)){
- nRltVal|=1;
- break;
- }
- }
- return nRltVal;
- }
- //////
- int CBezierCurve::GetPtState(float flx,float fly,float flRate)
- {
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- CRect rect;
- 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)){
- nRltVal|=1;
- m_nSelectPtNum=j-1;
- m_nSelectLineNum=-1;
- break;
- }
- }
- if(nRltVal==0){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=-1;
- }
- return nRltVal;
- }
- //////////////////////////////////////////////////////////////////////
- // 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 CBezierCurve::ExPort(FILE* outStream)//增加导出txt功能时用
- {
- fprintf(outStream, " CBezierCurve 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 CBezierCurve::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 CBezierCurve::GetNameString()
- {
- CString str;
- str.LoadString(IDS_BEZIERCURVE);
- return str;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File////////////////
- ////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////