// Created on: 1995-06-08 // Created by: Robert COUBLANC // Copyright (c) 1995-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #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