79eab851949fa8b9e10600cab253a841d3e414ba
[occt.git] / src / Select3D / Select3D_Box2d.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Select3D_Box2d_HeaderFile
15 #define _Select3D_Box2d_HeaderFile
16
17 #include<Bnd_Box2d.hxx>
18 #include<Standard_ShortReal.hxx>
19 #include<Select3D_Macro.hxx>
20
21 struct Select3D_Box2d
22 {
23  Standard_ShortReal xmin, ymin, xmax, ymax;
24
25  Select3D_Box2d()
26  : xmin( ShortRealLast()  ),
27    ymin( ShortRealLast()  ),
28    xmax( ShortRealFirst() ),
29    ymax( ShortRealFirst() )
30  {
31  }
32
33  Select3D_Box2d(const Bnd_Box2d& theBox)
34  { 
35    SetField(theBox);
36  }
37
38  inline operator Bnd_Box2d() const
39  {
40    Bnd_Box2d aBox;
41    aBox.SetVoid();
42    if( !IsVoid() )
43      aBox.Update(xmin, ymin, xmax, ymax);
44    return aBox;
45  }
46
47  inline Select3D_Box2d operator = ( const Bnd_Box2d& theBox)
48  { 
49    SetField(theBox); 
50    return *this;
51  }
52
53  inline void Update(const gp_Pnt2d& thePnt)
54  {
55   Bnd_Box2d aBox;
56   aBox.Set(thePnt);
57   if( !IsVoid() )
58     aBox.Update(xmin, ymin, xmax, ymax);
59   SetField(aBox);
60  }
61
62  inline void SetVoid()
63  {
64    xmin = ymin = ShortRealLast();
65    xmax = ymax = ShortRealFirst();
66  }
67
68  inline Standard_Boolean IsVoid() const
69  {
70    return ( xmin == ShortRealLast() && ymin == ShortRealLast() && xmax == ShortRealFirst() && ymax == ShortRealFirst() );
71  }
72
73 private: 
74  inline void SetField(const Bnd_Box2d& theBox)
75  {
76   if( theBox.IsVoid() )
77     SetVoid();
78   else {
79     Standard_Real x, y, x1, y1;
80     theBox.Get(x, y, x1, y1);   
81
82     xmin = DToF(x);
83     ymin = DToF(y);
84     xmax = DToF(x1);
85     ymax = DToF(y1);
86   }
87  }
88
89 };
90
91 #endif
92
93
94
95