0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / Select2D / Select2D_SensitiveArc.cxx
1 // Copyright:   Matra-Datavision 1995
2 // File:        Select2D_SensitiveArc.cxx
3 // Created:     Tue May 23 13:22:33 1995
4 // Author:      Robert COUBLANC
5 //              <rob>
6
7
8
9 #include <Select2D_SensitiveArc.ixx>
10 #include <Bnd_Box2d.hxx>
11 #include <gp_Pnt2d.hxx>
12 #include <gp_Vec2d.hxx>
13 #include <Precision.hxx>
14 //#include <.hxx>
15 //#include <.hxx>
16 //#include <.hxx>
17
18
19 //==================================================
20 // Function: Constructor 
21 // Purpose :
22 //==================================================
23
24 Select2D_SensitiveArc::
25 Select2D_SensitiveArc(const Handle(SelectBasics_EntityOwner)& OwnerId,
26                       const gp_Ax2d& OriginAxis,
27                       const Standard_Real Angle,
28                       const Standard_Real Radius,
29                       const Standard_Integer NbPoints):
30 Select2D_SensitiveEntity(OwnerId),
31 myradius(Radius),
32 myax2d( OriginAxis),
33 myangle(Angle),
34 mynbpt(NbPoints)
35
36 {
37   if(myangle<=Precision::Confusion()) myangle=2*M_PI;
38 }
39
40
41 //=====================================================
42 // Function : Areas
43 // Purpose  :
44 //=====================================================
45
46 void Select2D_SensitiveArc::
47 Areas (SelectBasics_ListOfBox2d& boxes) 
48 {
49   Bnd_Box2d abox;
50   Standard_Real deteta =myangle/mynbpt;
51
52
53   gp_Pnt2d P1 = myax2d.Location().Translated(gp_Vec2d(myax2d.Direction())*myradius);
54   
55   abox.Set(P1);
56   for(Standard_Integer i=1;i<=mynbpt;i++){
57     abox.Add(P1.Rotated(myax2d.Location(),deteta*i));}
58   boxes.Append(abox);
59 }
60
61
62 //=====================================================
63 // Function : Matches
64 // Purpose  :
65 //=====================================================
66 Standard_Boolean Select2D_SensitiveArc::
67 Matches (const Standard_Real X,
68          const Standard_Real Y,
69          const Standard_Real aTol,
70          Standard_Real& DMin)
71 {
72   Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;
73
74   gp_Pnt2d Pick(X,Y);
75   Standard_Real Angle = (gp_Dir2d(gp_Vec2d(myax2d.Location(),Pick))).Angle(myax2d.Direction());
76   if(Angle<0 && Angle>myangle) return Standard_False;
77   else
78     {
79       DMin =myax2d.Location().Distance(Pick);
80       if (DMin>myradius-TheTol&&DMin<=myradius+TheTol) return Standard_True;
81     }
82   return Standard_False;
83 }
84
85 Standard_Boolean Select2D_SensitiveArc::
86 Matches (const Standard_Real XMin,
87          const Standard_Real YMin,
88          const Standard_Real XMax,
89          const Standard_Real YMax,
90          const Standard_Real aTol)
91 {
92   Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;
93   if(mynbpt<1) return Standard_True; //to avoid problems...
94
95   Standard_Real deteta = myangle/mynbpt;
96   Bnd_Box2d BoundBox;
97   BoundBox.Update(XMin-TheTol,YMin-TheTol,XMax+TheTol,YMax+TheTol);
98   gp_Pnt2d ExtPt = myax2d.Location().Translated(gp_Vec2d(myax2d.Direction())*myradius);
99
100   if(BoundBox.IsOut(ExtPt)) return Standard_False;
101
102   for (Standard_Integer I=1;I<=mynbpt;I++)
103     {
104       if(BoundBox.IsOut(ExtPt.Rotated(myax2d.Location(),deteta*I))) return Standard_False;
105     }
106   return Standard_True;
107 }
108
109
110
111