summaryrefslogtreecommitdiff
path: root/src/Select2D/Select2D_SensitiveCircle.cxx
blob: 2d02251566df73a2decd7c18e6fb5dce0017e466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright: 	Matra-Datavision 1995
// File:	Select2D_SensitiveCircle.cxx
// Created:	Mon Jan 30 16:58:02 1995
// Author:	Mister rmi
//		<rmi>


#include <Select2D_SensitiveCircle.ixx>
#include <BndLib.hxx>
#include <Bnd_Box2d.hxx>

//=====================================================
// Function : Create
// Purpose  :Constructor
//=====================================================


Select2D_SensitiveCircle::
Select2D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
			 const gp_Circ2d& aCirc,
			 const Select2D_TypeOfSelection atype):
Select2D_SensitiveEntity(OwnerId),
myCirc(aCirc),
mytype(atype){}


//=====================================================
// Function : Areas
// Purpose  :
//=====================================================

void Select2D_SensitiveCircle::
Areas (SelectBasics_ListOfBox2d& boxes) 
{
  Bnd_Box2d abox;
  BndLib::Add(myCirc,myCirc.Radius()/100.,abox);
  boxes.Append(abox);
}


//=====================================================
// Function : Matches
// Purpose  :
//=====================================================
Standard_Boolean Select2D_SensitiveCircle::
Matches (const Standard_Real X,
	 const Standard_Real Y,
	 const Standard_Real aTol,
	 Standard_Real& DMin)
{
  Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;

  switch(mytype){
  case Select2D_TOS_INTERIOR:
    {
      if(myCirc.Contains(gp_Pnt2d(X,Y),TheTol) )
	{DMin=0.;
	 return Standard_True;}
      else 
	{DMin=myCirc.Distance(gp_Pnt2d(X,Y));}
    }
  case Select2D_TOS_BOUNDARY:
    {
      DMin = myCirc.Distance(gp_Pnt2d(X,Y));
      if(DMin<= TheTol) return Standard_True;
      
    }
  }  
  return Standard_False;
}

Standard_Boolean Select2D_SensitiveCircle::
Matches (const Standard_Real XMin,
	 const Standard_Real YMin,
	 const Standard_Real XMax,
	 const Standard_Real YMax,
	 const Standard_Real aTol)
{
  Standard_Real TheTol = HasOwnTolerance()? myOwnTolerance : aTol;

  Bnd_Box2d abox, BoundBox;
  BoundBox.Update(XMin-TheTol,YMin-TheTol,XMax+TheTol,YMax+TheTol);
  BndLib::Add(myCirc,myCirc.Radius()/100.,abox);

  if(BoundBox.IsOut(abox)) return Standard_False;
 return Standard_True;
}