// Copyright: Matra-Datavision 1995 // File: SelectBasics_BasicTool.cxx // Created: Thu Jun 8 11:08:55 1995 // Author: Robert COUBLANC // #include #include #include //================================================== // Function: // Purpose : //================================================== Standard_Boolean SelectBasics_BasicTool:: MatchSegments(const gp_Pnt2d & A, const gp_Pnt2d & B, const gp_Pnt2d & C, const gp_Pnt2d & D) { Standard_Real d[6],det,deta,detb; if(Max(A.X(),B.X())Max(C.X(),D.X())) return Standard_False; if(Max(A.Y(),B.Y())Max(C.Y(),D.Y())) return Standard_False; d[0] = B.X()-A.X();d[1]=C.X()-D.X();d[2]=C.X()-A.X(); d[3] = B.Y()-A.Y();d[4]=C.Y()-D.Y();d[5]=C.Y()-A.Y(); det = d[0]*d[4]-d[3]*d[1]; deta = d[4]*d[2]-d[5]*d[1]; detb = d[0]*d[5]-d[3]*d[2]; if(Abs(det)<=Precision::Confusion()) return Standard_False; if(deta/det1+Precision::Confusion()) return Standard_False; if(detb/det1+Precision::Confusion()) return Standard_False; return Standard_True; } //================================================== // Function: MatchSegment // Purpose : Return True if Segment(pBegin, pEnd) is Selected //================================================== Standard_Boolean SelectBasics_BasicTool::MatchSegment(const gp_Pnt2d& pBegin,const gp_Pnt2d& pEnd, const Standard_Real X, const Standard_Real Y, const Standard_Real aTol, Standard_Real& DMin) { const Standard_Real SqTol = aTol * aTol; gp_Vec2d AB, AC, BC; const gp_Pnt2d apoint(X,Y); AB.SetCoord(pEnd.X()-pBegin.X(),pEnd.Y()-pBegin.Y()); AC.SetCoord(X-pBegin.X(),Y-pBegin.Y()); BC.SetCoord(pEnd.X()-X,pEnd.Y()-Y); //1. Check the ends, do not estimate distance to the segment itself here if((apoint.SquareDistance(pBegin)=0. && AB.Dot(BC)>=0.){ //3. Estimate distance from the mouse point to the segment // if length of segment exceeds tolerance const Standard_Real aSegLen = AB.Magnitude(); if (aSegLen>aTol){ DMin=Abs(AB.Crossed(gp_Vec2d(pBegin,apoint))/aSegLen); if (DMin