line drawing algorithm
-
hi I want to find whether the mouse is positioned on the line which I draw ,or not.for this I am using Bresenhalm algorithm.this is the code. /* [helpstring] */ STDMETHODIMP CConnector::intersects(/* [in] */ SPoint pt,/* [retval][out] */ BOOL __RPC_FAR *checkflag) { SRect boundingRect; ptrConState->get_Position(&boundingRect); SPoint start,end; start.x=boundingRect.topLeft.x; start.y=boundingRect.topLeft.y; end.x=boundingRect.bottomRight.x; end.y=boundingRect.bottomRight.y; double m=findSlope(start,end); int dx,dy,xend,yend,p,x1,y1; dx=abs(start.x-end.x); dy=abs(start.y-end.y); //if(m<1||m>-1) if(m<=1&&m>=0) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=0) y1=y1+1; //else // y1=y1-1; p=p+2*(dy-dx); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } else if(m<0&&m>-1) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=1) { p=2*dx-dy; if(start.y>end.y) { x1=end.x; y1=end.y; yend=start.y; } else { x1=start.x; y1=start.y; yend=end.y; } while(y11) x1=x1+1; else x1=x1-1; p=p+2*(dx-dy); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } *checkflag=0; return S_OK; } here the problem is i am not getting exact intersections for the lines slope of which is less than 0 and greater than -1.why this problem? please find any mistakes and hellp me.I also want that the user of my application can easily select the lines provided some offset for the line to get selected. Thanks regards Pathi bhikshapathi_g@semanticspace.com
-
hi I want to find whether the mouse is positioned on the line which I draw ,or not.for this I am using Bresenhalm algorithm.this is the code. /* [helpstring] */ STDMETHODIMP CConnector::intersects(/* [in] */ SPoint pt,/* [retval][out] */ BOOL __RPC_FAR *checkflag) { SRect boundingRect; ptrConState->get_Position(&boundingRect); SPoint start,end; start.x=boundingRect.topLeft.x; start.y=boundingRect.topLeft.y; end.x=boundingRect.bottomRight.x; end.y=boundingRect.bottomRight.y; double m=findSlope(start,end); int dx,dy,xend,yend,p,x1,y1; dx=abs(start.x-end.x); dy=abs(start.y-end.y); //if(m<1||m>-1) if(m<=1&&m>=0) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=0) y1=y1+1; //else // y1=y1-1; p=p+2*(dy-dx); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } else if(m<0&&m>-1) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=1) { p=2*dx-dy; if(start.y>end.y) { x1=end.x; y1=end.y; yend=start.y; } else { x1=start.x; y1=start.y; yend=end.y; } while(y11) x1=x1+1; else x1=x1-1; p=p+2*(dx-dy); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } *checkflag=0; return S_OK; } here the problem is i am not getting exact intersections for the lines slope of which is less than 0 and greater than -1.why this problem? please find any mistakes and hellp me.I also want that the user of my application can easily select the lines provided some offset for the line to get selected. Thanks regards Pathi bhikshapathi_g@semanticspace.com