1 // Copyright: Matra-Datavision 1995
2 // File: Select2D_SensitiveSegment.cxx
3 // Created: Thu Jan 26 11:50:08 1995
7 #include <Select2D_SensitiveSegment.ixx>
8 #include <Bnd_Box2d.hxx>
9 #include <gp_Lin2d.hxx>
10 #include <gp_Dir2d.hxx>
11 #include <gp_Vec2d.hxx>
12 #include <TColgp_Array1OfPnt2d.hxx>
13 #include <SelectBasics_BasicTool.hxx>
15 //=====================================================
17 // Purpose :Constructor
18 //=====================================================
21 Select2D_SensitiveSegment::
22 Select2D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
23 const gp_Pnt2d& FirstP,
24 const gp_Pnt2d& LastP,
25 const Standard_Integer MaxRect):
26 Select2D_SensitiveEntity(OwnerId),
33 //=====================================================
36 //=====================================================
37 void Select2D_SensitiveSegment::
38 Areas(SelectBasics_ListOfBox2d& boxes)
40 // look for the angle with X axis if x % pi/4 <pi/12 -> one box
41 //gp_Dir2d dy (0.,1.);
43 gp_Vec2d MyVec(mystart,myend),VAxx(gp_Dir2d(0.,1.));
46 Standard_Real theangle = (VAxx.Angle(MyVec));
47 theangle = Abs(theangle);
48 if(theangle>=M_PI/2.) theangle-=M_PI/2;
51 if(theangle>=M_PI/12. && theangle <=5*M_PI/12.)
53 TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
54 BoxPoint (1) = mystart;BoxPoint(mymaxrect+1)=myend;
55 gp_Vec2d Vtr = MyVec/mymaxrect;
56 // for (Standard_Integer i=2;i<=mymaxrect;i++)
58 for ( i=2;i<=mymaxrect;i++)
59 {BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);}
60 for (i=2;i<=mymaxrect+1;i++)
62 curbox.Set(BoxPoint(i-1));
63 curbox.Add(BoxPoint(i));
77 //=====================================================
80 //=====================================================
81 Standard_Boolean Select2D_SensitiveSegment::
82 Matches(const Standard_Real X,
83 const Standard_Real Y,
84 const Standard_Real aTol,
87 // gp_Pnt2d pickpoint(X,Y);
88 // gp_Vec2d V(mystart,myend);
89 // gp_Lin2d Lin(mystart,V);
90 Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;
92 if(mystart.Distance(myend)<=TheTol) DMin = Min(mystart.Distance(gp_Pnt2d(X,Y)),
93 myend.Distance(gp_Pnt2d(X,Y)));
95 DMin =Abs (gp_Lin2d(mystart,gp_Vec2d(mystart,myend)).Distance(gp_Pnt2d(X,Y)));
97 if(DMin<=TheTol) return Standard_True;
99 return Standard_False;
103 Standard_Boolean Select2D_SensitiveSegment::
104 Matches (const Standard_Real XMin,
105 const Standard_Real YMin,
106 const Standard_Real XMax,
107 const Standard_Real YMax,
108 const Standard_Real aTol)
110 Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;
113 BoundBox.Update(XMin-TheTol,YMin-TheTol,XMax+TheTol,YMax+TheTol);
115 if (BoundBox.IsOut(mystart)||BoundBox.IsOut(myend)) return Standard_False;
116 return Standard_True;